Zufalläig Horiz/Verti & Plazieren im Filler Array

This commit is contained in:
Niklas Wolf 2025-10-23 10:05:35 +02:00
parent a980b80623
commit 3e77de5152

View File

@ -5,11 +5,41 @@
#define MAX_RAND_TRIES_PER_WORD 10
#define EMPTY_CHAR 0
#define FILLER '.'
#define SIZE 20
//TODO: Spiellogik implementieren:
/* * Wörter aus der Wortliste zufällig horizontal oder vertikal platzieren
* restliche Felder mit zufälligen Buchstaben füllen */
int can_Place(char grid[SIZE][SIZE], const char *word, int row, int col, int orient)
{
srand(time(NULL)); //Zufallsgenerator
orient = rand() % 2;
int len = strlen(word); //Wortlänge best.
if (orient == 0) //Horizontal
{
if (col + len > SIZE) //Rand
return 0;
for (int i = 0; i < len; i++)
if (grid[row][col + i] != FILLER && grid[row][col + i] != word[i])
return 0;
}
else //Vertikal
{
if (row + len > SIZE) //Rand
return 0;
for (int i = 0; i < len; i++)
if (grid[row + i][col] != FILLER && grid[row + i][col] != word[i])
return 0;
}
return 1;
}
// 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)
{