fertig
This commit is contained in:
1 parent
eb37f451d0
commit
6259f06391
9 files changed
+109
-1
No files matched your search
Vendored
+7
@@ -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": []
|
||||
}
|
||||
Vendored
+28
@@ -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"
|
||||
}
|
||||
+61
-1
@@ -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
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user