diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 59fa7cc..3dc3936 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -9,6 +9,34 @@ char toLower(char ch) { return ch; } +// Hint function +char *hint = NULL; +int hintAvailable = 1; + +char generateHint(char *wordToGuess, char *guessedLetters) { + int length = strlen(wordToGuess); + char availableLetters[length]; // Array to store letters not guessed yet + int numAvailableLetters = 0; + + // Check each letter in the word + for (int i = 0; i < length; i++) { + char letter = wordToGuess[i]; + // Check if the letter has not been guessed + if (strchr(guessedLetters, letter) == NULL) { + availableLetters[numAvailableLetters++] = letter; // Store the available letter + } + } + + // Randomly select a letter from available letters + if (numAvailableLetters > 0) { + int randomIndex = rand() % numAvailableLetters; + return availableLetters[randomIndex]; + } else { + // No available letters, return a placeholder value + return '-'; + } +} + void playHangman() { char *wordToGuess; int mistakes = 0;