From ef958955012fa89e2bf8681c66c82f7ea4e3ed72 Mon Sep 17 00:00:00 2001 From: zidanmo99094 Date: Tue, 27 Oct 2026 12:48:19 +0100 Subject: [PATCH] txt --- Startcode/game.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Startcode/game.c b/Startcode/game.c index 54a4fe6..f1601c6 100644 --- a/Startcode/game.c +++ b/Startcode/game.c @@ -3,7 +3,7 @@ #include #include -#define MAX_RAND_TRIES_PER_WORD 1000 +#define MAX_RAND_TRIES_PER_WORD 100 #define EMPTY_CHAR 0 // TODO: Spiellogik implementieren: @@ -11,9 +11,16 @@ * 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) +int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int wordCount, char **words) { - // 1. Spielfeld vollständig mit EMPTY_CHAR initialisieren + // 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 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; @@ -29,7 +36,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 Mal, eine freie Position zu finden + // Versuche bis zu MAX_RAND_TRIES_PER_WORD (10) 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; @@ -79,4 +86,4 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi } return placedWordsCount; -} +} \ No newline at end of file