Fixed bugs caused by method createWordSalad()

This commit is contained in:
Tobias Grampp 2025-11-03 12:02:28 +01:00
parent e702373347
commit e5a049842c

View File

@ -7,7 +7,7 @@
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
#define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+cd minimum) //Macro to generate a Number between minimum and maximum (both are possibly rolled)
#define RANDOMNUMBER(minimum, maximum) ((rand() % ((maximum)-(minimum)+1))+ minimum) //Macro to generate a Number between minimum and maximum (both are possibly rolled)
//TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren - erledigt
@ -31,9 +31,9 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for(int i = 0; i < wordCount; i++)
{
int wordPlaced = 0, amountFailed = 0;
int wordlength = 0;
do
{
int wordlength = 0;
while(words[i][wordlength] != '0')//gets the length of the current word
wordlength++;
int startPosition1 = RANDOMNUMBER(0, MAX_SEARCH_FIELD_LEN - wordlength);//gets a random starting position for the word
@ -50,7 +50,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{
for(int j = 0; j < wordlength; j++)
{
salad[startPosition1 + j][startPosition2] = words[i][j]
salad[startPosition1 + j][startPosition2] = words[i][j];
}
wordPlaced++;
wordamount++;
@ -72,7 +72,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{
for(int j = 0; j < wordlength; j++)
{
salad[startPosition2][startPosition1 + j] = words[i][j]
salad[startPosition2][startPosition1 + j] = words[i][j];
}
wordPlaced++;
wordamount++;
@ -82,7 +82,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
amountFailed++;
}
}
}
}while((wordPlaced == 0)&&(amountFailed < MAX_RAND_TRIES_PER_WORD));
int index = 0;
while((wordPlaced == 0)&&(index < searchFieldLen))//Places Words that couln't be put in normally in the highest up horizontal place.
{
@ -96,7 +96,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
{
for(int j = 0; j < wordlength; j++)
{
salad[index + j][0] = words[i][j]
salad[index + j][0] = words[i][j];
}
wordPlaced++;
wordamount++;