From c25a17a74ae7722287f63a5b54568809fecdf845 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 10 Aug 2025 15:36:09 +0000 Subject: [PATCH] Add contradiction detection Implement logic to detect contradictory answers in the computer's question-answering mode. If contradictions are found, the game will abort and prompt the user to restart. --- src/components/GuessingGame.tsx | 44 +++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/components/GuessingGame.tsx b/src/components/GuessingGame.tsx index 10c6061..41824e5 100644 --- a/src/components/GuessingGame.tsx +++ b/src/components/GuessingGame.tsx @@ -18,7 +18,7 @@ interface GuessingGameProps { type GameMode = 'user-guesses' | 'computer-asks'; type UserGuessingMode = 'standard' | 'questions'; type ComputerStrategy = 'random' | 'linear' | 'binary'; -type GameState = 'setup' | 'playing' | 'won' | 'lost'; +type GameState = 'setup' | 'playing' | 'won' | 'contradiction'; interface Question { text: string; @@ -240,7 +240,8 @@ const GuessingGame: React.FC = ({ showSocialShare = true }) = if (!currentQuestion) return; const questionText = `${currentQuestion.text} → ${answer ? 'Yes' : 'No'}`; - setQuestionsAsked([...questionsAsked, questionText]); + const newQuestionsAsked = [...questionsAsked, questionText]; + setQuestionsAsked(newQuestionsAsked); setUserScore(userScore + 1); let newPossibleNumbers = [...possibleNumbers]; @@ -278,6 +279,12 @@ const GuessingGame: React.FC = ({ showSocialShare = true }) = } } + // Check for contradictions - if no numbers remain, the answers are contradictory + if (newPossibleNumbers.length === 0) { + setGameState('contradiction'); + return; + } + setPossibleNumbers(newPossibleNumbers); }; @@ -555,6 +562,39 @@ const GuessingGame: React.FC = ({ showSocialShare = true }) = )} + {gameState === 'contradiction' && ( +
+
+ +

Contradiction Detected!

+

+ Your answers are contradictory - no number can satisfy all the conditions you've given. +

+
+

Please check your answers in the question history below.

+

You may have accidentally given incorrect responses.

+
+
+ + {questionsAsked.length > 0 && ( +
+

Your Answer History:

+
+ {questionsAsked.map((question, index) => ( +
+ {question} +
+ ))} +
+
+ )} + + +
+ )} + {gameState === 'won' && (