From 9a6f8e16d55996c0a940bb6b54114726bf390cb1 Mon Sep 17 00:00:00 2001 From: Gregory Gauthier Date: Thu, 18 Dec 2025 09:13:20 +0000 Subject: [PATCH] fix word validation logic --- build.sh | 2 +- src/game.c | 5 +++++ src/main.c | 8 +++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 6b1ce49..f08d31a 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ mkdir -p build/cordle echo "Building application." -gcc -std=c90 -o build/cordle/cordle src/*.c -Iinclude -lncurses +gcc -std=c90 -pedantic -Wall -o build/cordle/cordle src/*.c -Iinclude -lncurses export RESULT=$? if (( RESULT == 0 )); then diff --git a/src/game.c b/src/game.c index d26535d..6e7d27e 100644 --- a/src/game.c +++ b/src/game.c @@ -4,6 +4,7 @@ /* game.c - Game logic implementation */ #include "../include/game.h" #include "../include/ui.h" +#include "../include/words.h" #include #include @@ -99,6 +100,10 @@ int make_guess(GameState *game, const char *guess) { upper_guess[i] = toupper(upper_guess[i]); } + if (!is_valid_word(game, upper_guess)) { + return 0; + } + strcpy(game->guesses[game->guess_count], upper_guess); check_guess(game, guess, game->guess_colors[game->guess_count]); game->guess_count++; diff --git a/src/main.c b/src/main.c index 28abfbf..faa1de5 100644 --- a/src/main.c +++ b/src/main.c @@ -176,11 +176,9 @@ int main_game_loop(int argc, char *argv[]) { game.current_guess_length = 0; strcpy(message, ""); } else { - /* Check if word is valid */ - if (!is_valid_word(&game, temp_guess)) { - strcpy(message, "Not in word list!"); - message_color = COLOR_ABSENT; - } + /* Validation failed in make_guess or is_valid_word */ + strcpy(message, "Not in word list!"); + message_color = COLOR_ABSENT; } } else { sprintf(message, "Word must be %d letters!", WORD_LENGTH);