Fix guess count
Track and display questions and guesses made by the user.
This commit is contained in:
parent
a1208e7d5b
commit
d6f1449d23
2 changed files with 26 additions and 5 deletions
|
|
@ -46,6 +46,9 @@ const GuessingGame: React.FC<GuessingGameProps> = ({ showSocialShare = true }) =
|
|||
const [questionsAsked, setQuestionsAsked] = useState<string[]>([]);
|
||||
const [userScore, setUserScore] = useState(0);
|
||||
const [currentSearchIndex, setCurrentSearchIndex] = useState(0);
|
||||
|
||||
// Question mode stats
|
||||
const [questionModeStats, setQuestionModeStats] = useState<{questionsAsked: number, finalGuesses: number}>({questionsAsked: 0, finalGuesses: 0});
|
||||
|
||||
const maxRange = range[0];
|
||||
|
||||
|
|
@ -296,6 +299,7 @@ const GuessingGame: React.FC<GuessingGameProps> = ({ showSocialShare = true }) =
|
|||
setQuestionsAsked([]);
|
||||
setUserScore(0);
|
||||
setCurrentSearchIndex(0);
|
||||
setQuestionModeStats({questionsAsked: 0, finalGuesses: 0});
|
||||
};
|
||||
|
||||
const getStrategyDescription = (strategy: ComputerStrategy) => {
|
||||
|
|
@ -482,7 +486,10 @@ const GuessingGame: React.FC<GuessingGameProps> = ({ showSocialShare = true }) =
|
|||
setUserGuess={setUserGuess}
|
||||
onGuess={handleGuess}
|
||||
onUpdateValidNumbers={setValidNumbers}
|
||||
onWin={() => setGameState('won')}
|
||||
onWin={(questionsAsked, finalGuesses) => {
|
||||
setQuestionModeStats({questionsAsked, finalGuesses});
|
||||
setGameState('won');
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -553,11 +560,21 @@ const GuessingGame: React.FC<GuessingGameProps> = ({ showSocialShare = true }) =
|
|||
<div className="space-y-2">
|
||||
<CheckCircle className="w-16 h-16 text-success mx-auto" />
|
||||
<h3 className="text-2xl font-bold text-success">Game Complete!</h3>
|
||||
{gameMode === 'user-guesses' ? (
|
||||
{gameMode === 'user-guesses' && userGuessingMode === 'standard' ? (
|
||||
<p className="text-lg">
|
||||
You found the number <span className="font-bold">{secretNumber}</span> in{' '}
|
||||
<span className="font-bold">{guesses.length}</span> guesses!
|
||||
</p>
|
||||
) : gameMode === 'user-guesses' && userGuessingMode === 'questions' ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-lg">
|
||||
You found the number with <span className="font-bold">{questionModeStats.questionsAsked}</span> questions and{' '}
|
||||
<span className="font-bold">{questionModeStats.finalGuesses}</span> final guesses!
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Total interactions: <span className="font-bold">{questionModeStats.questionsAsked + questionModeStats.finalGuesses}</span>
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<p className="text-lg">
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ interface QuestionGuessingModeProps {
|
|||
setUserGuess: (value: string) => void;
|
||||
onGuess: (guessValue?: number) => void;
|
||||
onUpdateValidNumbers: (newValidNumbers: Set<number>) => void;
|
||||
onWin: () => void;
|
||||
onWin: (questionsAsked: number, finalGuesses: number) => void;
|
||||
}
|
||||
|
||||
const QuestionGuessingMode: React.FC<QuestionGuessingModeProps> = ({
|
||||
|
|
@ -31,6 +31,7 @@ const QuestionGuessingMode: React.FC<QuestionGuessingModeProps> = ({
|
|||
const [question, setQuestion] = useState('');
|
||||
const [questionHistory, setQuestionHistory] = useState<{question: string, answer: string, understood: boolean}[]>([]);
|
||||
const [questionFeedback, setQuestionFeedback] = useState('');
|
||||
const [finalGuessCount, setFinalGuessCount] = useState(0);
|
||||
|
||||
// Function to determine the optimal answer to keep search space as large as possible
|
||||
const getOptimalAnswer = (question: string): { understood: boolean, answer: boolean, questionType?: string, value?: number, isNegated?: boolean } => {
|
||||
|
|
@ -314,8 +315,11 @@ const QuestionGuessingMode: React.FC<QuestionGuessingModeProps> = ({
|
|||
return;
|
||||
}
|
||||
|
||||
const newFinalGuessCount = finalGuessCount + 1;
|
||||
setFinalGuessCount(newFinalGuessCount);
|
||||
|
||||
if (validNumbers.size === 1 && validNumbers.has(guess)) {
|
||||
onWin();
|
||||
onWin(questionHistory.length, newFinalGuessCount);
|
||||
} else if (validNumbers.has(guess)) {
|
||||
// Remove this number from valid numbers since it's not the answer
|
||||
const newValidNumbers = new Set(validNumbers);
|
||||
|
|
@ -324,7 +328,7 @@ const QuestionGuessingMode: React.FC<QuestionGuessingModeProps> = ({
|
|||
|
||||
// Check if we're down to one number
|
||||
if (newValidNumbers.size === 1) {
|
||||
onWin();
|
||||
onWin(questionHistory.length, newFinalGuessCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue