findpossiblePositions kreiert

This commit is contained in:
LukVal54 2025-11-01 18:42:17 +01:00
parent 4ea6b50cf5
commit cf577e2a37

View File

@ -15,7 +15,7 @@
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 searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
{ {
Position position[1520]; //Positionsarray, 1520, weil 2 Richtungen, minimalwort größe Position position[1520]; //Positionsarray, 1520, weil 2 Richtungen, minimalwort größe
@ -38,6 +38,7 @@ void clearWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
} }
} }
} }
//Funktion für den Schluss: Übrige leere stellen werden random befüllt.
void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen) void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen)
{ {
srand(time(NULL)); srand(time(NULL));
@ -51,4 +52,66 @@ void fillWordsaladRand(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], u
} }
} }
} }
}
int findPossiblePositions(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], int wordidx, Position positions[])
{
char *word = words[wordidx];
int wordlen = strlen(word);
int positionamount = 0;
int rechtsfrei = 1;
int untenfrei = 1;
for(int i = 0; i < searchFieldLen; i++)
{
for(int k = 0; k < searchFieldLen; k++)
{
rechtsfrei = 1;
untenfrei = 1;
if(salad[i][k] == '.')
{
//nach rechts prüfen
if(searchFieldLen - k >= wordlen)
{
for(int p = k +1; p < k+ wordlen; p++)
{
if(salad[i][p] != '.')
{
rechtsfrei = 0;
break;
}
}
}
//nach unten prüfen
if(searchFieldLen - i >= wordlen)
{
for(int q = i+1; q < i+ wordlen; q++)
{
if(salad[q][k] != '.')
{
untenfrei = 0;
break;
}
}
}
if(rechtsfrei)
{
positions[positionamount].x = k;
positions[positionamount].y = i;
positions[positionamount].richt = RECHTS;
positionamount++;
}
if(untenfrei)
{
positions[positionamount].x = k;
positions[positionamount].y = i;
positions[positionamount].richt = UNTEN;
positionamount++;
}
}
}
}
return positionamount;
} }