This commit is contained in:
hentschdu103698 committed 2026-11-02 14:02:33 +01:00
1 parent eb37f451d0
commit 6259f06391
9 files changed
+108

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
+28
View File
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
+60
View File
@@ -13,5 +13,65 @@
// 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)
{
// Initialize the salad with empty characters
for (unsigned int i = 0; i < searchFieldLen; i++) {
for (unsigned int j = 0; j < searchFieldLen; j++) {
salad[i][j] = EMPTY_CHAR;
}
}
// Seed the random number generator
srand((unsigned int)time(NULL));
// Place each word in the salad
for (unsigned int w = 0; w < wordCount; w++) {
const char *word = words[w];
unsigned int wordLen = strlen(word);
int placed = 0;
for (int tries = 0; tries < MAX_RAND_TRIES_PER_WORD && !placed; tries++) {
// Randomly choose orientation: 0 for horizontal, 1 for vertical
int orientation = rand() % 2;
unsigned int row, col;
if (orientation == 0) { // Horizontal
row = rand() % searchFieldLen;
col = rand() % (searchFieldLen - wordLen + 1);
// Check if the space is free
int canPlace = 1;
for (unsigned int k = 0; k < wordLen; k++) {
if (salad[row][col + k] != EMPTY_CHAR) {
canPlace = 0;
break;
}
}
if (canPlace) {
for (unsigned int k = 0; k < wordLen; k++) {
salad[row][col + k] = word[k];
}
placed = 1;
}
} else { // Vertical
row = rand() % (searchFieldLen - wordLen + 1);
col = rand() % searchFieldLen;
// Check if the space is free
int canPlace = 1;
for (unsigned int k = 0; k < wordLen; k++) {
if (salad[row + k][col] != EMPTY_CHAR) {
canPlace = 0;
break;
}
}
if (canPlace) {
for (unsigned int k = 0; k < wordLen; k++) {
salad[row + k][col] = word[k];
}
placed = 1;
}
}
}
if (!placed) {
return -1; // Failed to place the word after max tries
}
}
BIN
View File
Binary file not shown.
Binary file not shown.
+13
View File
@@ -8,5 +8,18 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
unsigned int wordCount = 0;
char buffer[MAX_WORD_LEN];
while (wordCount < maxWordCount && fscanf(file, "%s", buffer) == 1) {
for (int i = 0; buffer[i]; i++) {
buffer[i] = tolower(buffer[i]);
}
strncpy(words[wordCount], buffer, MAX_WORD_LEN - 1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
}
return wordCount;
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.