diff --git a/.idea/editor.xml b/.idea/editor.xml
index 963c96f..ead1d8a 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -244,101 +244,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Start_Mac/game.c b/Start_Mac/game.c
index 4116305..1952fc3 100644
--- a/Start_Mac/game.c
+++ b/Start_Mac/game.c
@@ -2,21 +2,21 @@
#include
#include
#include
+#include
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
-//TODO: Spiellogik implementieren: (erledigt von Sara)
+//TODO: Spiellogik implementieren: | VERSION: Erfolgreicher Test 4 & 5 I
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */
// Creates the word salad by placing words randomly and filling empty spaces
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{
-// Zufall initialisieren
+ //Random Zeit initialisieren
srand(time(NULL));
- // 1. Spielfeld leeren
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
@@ -25,7 +25,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
}
- // 2. Wörter platzieren
+ int placed = 0; //Anzahl der Erfolgreich platzierten Worte
+
+ //Platzieren
for (unsigned int w = 0; w < wordCount; w++)
{
const char *word = words[w];
@@ -33,29 +35,25 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++)
{
- // zufällige Startposition
int row = rand() % searchFieldLen;
int col = rand() % searchFieldLen;
-
- // zufällige Richtung: 0 = horizontal, 1 = vertikal
int direction = rand() % 2;
-
int canPlace = 1;
- // Nur prüfen, ob Buchstaben passen (gleiche erlaubt, leer erlaubt)
+ //Ob EIN Wort platziert werden kann (wird noch nicht platziert!)
for (unsigned int k = 0; k < wordLen; k++)
{
int r = row + (direction == 1 ? k : 0);
int c = col + (direction == 0 ? k : 0);
- // Wenn außerhalb des Feldes -> abbrechen
+ //Ränder des Spielfeldes beachten
if (r >= (int)searchFieldLen || c >= (int)searchFieldLen)
{
canPlace = 0;
break;
}
- // Wenn belegt mit anderem Buchstaben -> abbrechen
+ //Ist die Stelle nicht leer und passt Die stelle nicht zum passenden Buchstaben des Wortes
if (salad[r][c] != EMPTY_CHAR && salad[r][c] != word[k])
{
canPlace = 0;
@@ -63,8 +61,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
}
- // Wenn möglich, das Wort setzen
- if (canPlace)
+ if (canPlace) //Wenn geprüft wurde ob ein Wort erfolgreich platziert werden kann.
{
for (unsigned int k = 0; k < wordLen; k++)
{
@@ -73,12 +70,13 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
if (r < (int)searchFieldLen && c < (int)searchFieldLen)
salad[r][c] = word[k];
}
- break; // Wort erfolgreich platziert
+ placed++;
+ break; //Beim Nächsten Wort weiter machen
}
}
}
- // 3. Leere Felder mit Zufallsbuchstaben füllen
+ //Mit Zufälligen Buchstaben füllen
for (unsigned int i = 0; i < searchFieldLen; i++)
{
for (unsigned int j = 0; j < searchFieldLen; j++)
@@ -90,11 +88,20 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
}
}
- return 0;
+ return placed;
}
+
// Prints the word salad to console
void showWordSalad(const char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{
-
+ for (unsigned int i = 0; i < searchFieldLen; i++)
+ {
+ for (unsigned int j = 0; j < searchFieldLen; j++)
+ {
+ printf("%c ", salad[i][j]);
+ }
+ printf("\n");
+ }
}
+
diff --git a/Start_Mac/game.o b/Start_Mac/game.o
index d1784ab..c491c2e 100644
Binary files a/Start_Mac/game.o and b/Start_Mac/game.o differ
diff --git a/Start_Mac/input.c b/Start_Mac/input.c
index ed77805..934f9cf 100644
--- a/Start_Mac/input.c
+++ b/Start_Mac/input.c
@@ -1,12 +1,25 @@
#include "input.h"
#include
#include
+#include
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
-// Read words from file and store in 'words' array
+
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
+ unsigned int count = 0;
+ // Solange noch Platz ist und Wörter vorhanden sind
+ while (count < maxWordCount && fscanf(file, "%s", words[count]) == 1) {
+ // Optional: alle Buchstaben in Kleinbuchstaben umwandeln
+ for (int i = 0; words[count][i]; i++) {
+ words[count][i] = tolower((unsigned char)words[count][i]);
+ }
+
+ count++;
+ }
+
+ return count; // gibt zurück, wie viele Wörter tatsächlich eingelesen wurden
}
\ No newline at end of file
diff --git a/Start_Mac/input.o b/Start_Mac/input.o
index 904362a..dd50b61 100644
Binary files a/Start_Mac/input.o and b/Start_Mac/input.o differ
diff --git a/Start_Mac/main.o b/Start_Mac/main.o
index aff659d..1b68e6c 100644
Binary files a/Start_Mac/main.o and b/Start_Mac/main.o differ
diff --git a/Start_Mac/runTests b/Start_Mac/runTests
index 64cec2d..cc7d24f 100755
Binary files a/Start_Mac/runTests and b/Start_Mac/runTests differ
diff --git a/Start_Windows/input.c b/Start_Windows/input.c
index ed77805..934f9cf 100644
--- a/Start_Windows/input.c
+++ b/Start_Windows/input.c
@@ -1,12 +1,25 @@
#include "input.h"
#include
#include
+#include
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
-// Read words from file and store in 'words' array
+
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
+ unsigned int count = 0;
+ // Solange noch Platz ist und Wörter vorhanden sind
+ while (count < maxWordCount && fscanf(file, "%s", words[count]) == 1) {
+ // Optional: alle Buchstaben in Kleinbuchstaben umwandeln
+ for (int i = 0; words[count][i]; i++) {
+ words[count][i] = tolower((unsigned char)words[count][i]);
+ }
+
+ count++;
+ }
+
+ return count; // gibt zurück, wie viele Wörter tatsächlich eingelesen wurden
}
\ No newline at end of file