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.
This commit is contained in:
gpt-engineer-app[bot] 2025-08-10 15:36:09 +00:00
parent d6f1449d23
commit c25a17a74a

View file

@ -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<GuessingGameProps> = ({ 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<GuessingGameProps> = ({ 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<GuessingGameProps> = ({ showSocialShare = true }) =
</div>
)}
{gameState === 'contradiction' && (
<div className="text-center space-y-4">
<div className="space-y-2">
<XCircle className="w-16 h-16 text-destructive mx-auto" />
<h3 className="text-2xl font-bold text-destructive">Contradiction Detected!</h3>
<p className="text-lg">
Your answers are contradictory - no number can satisfy all the conditions you've given.
</p>
<div className="text-sm text-muted-foreground space-y-1">
<p>Please check your answers in the question history below.</p>
<p>You may have accidentally given incorrect responses.</p>
</div>
</div>
{questionsAsked.length > 0 && (
<div className="space-y-2 text-left">
<h4 className="font-semibold text-center">Your Answer History:</h4>
<div className="space-y-1 max-h-40 overflow-y-auto border rounded-lg p-3 bg-muted/30">
{questionsAsked.map((question, index) => (
<div key={index} className="text-sm p-2 bg-card rounded border">
{question}
</div>
))}
</div>
</div>
)}
<Button onClick={resetGame} size="lg" className="w-full">
Start Over
</Button>
</div>
)}
{gameState === 'won' && (
<div className="text-center space-y-4">
<div className="space-y-2">