This commit is contained in:
zidanmo99094 committed 2026-10-30 00:52:24 +01:00
1 parent 0d0ab8ab7e
commit ad2984a808
1 file changed
+3 -10
+3 -10
View File
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#define MAX_RAND_TRIES_PER_WORD 100
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
// TODO: Spiellogik implementieren:
@@ -13,14 +13,7 @@
// 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 wordCount, char **words)
{
// Zufallsgenerator einmalig initialisieren
static int seeded = 0;
if (!seeded) {
srand((unsigned int)time(NULL));
seeded = 1;
}
// 1. Spielfeld vollständig mit EMPTY_CHAR (0) initialisieren
// 1. Spielfeld vollständig mit EMPTY_CHAR initialisieren
for (int r = 0; r < MAX_SEARCH_FIELD_LEN; r++) {
for (int c = 0; c < MAX_SEARCH_FIELD_LEN; c++) {
salad[r][c] = EMPTY_CHAR;
@@ -36,7 +29,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
int len = (int)strlen(words[i]);
if (len == 0 || len > MAX_SEARCH_FIELD_LEN) continue;
// Versuche bis zu MAX_RAND_TRIES_PER_WORD (10) Mal, eine freie Position zu finden
// Versuche bis zu MAX_RAND_TRIES_PER_WORD Mal, eine freie Position zu finden
for (int attempt = 0; attempt < MAX_RAND_TRIES_PER_WORD; attempt++) {
// 0 = Horizontal, 1 = Vertikal
int dir = rand() % 2;