From 85b73a97c2aa3d8aed381ebd5cb294c4e0f2c21a 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 14:20:23 +0000 Subject: [PATCH] Refine AI strategy in guessing game The AI's strategy for answering questions in the guessing game has been refined to be more strategically optimal. Previously, when asked "is the number not divisible by 7?" and the answer was "No", the AI would grey out all numbers not divisible by 7. This commit corrects the logic to grey out only the multiples of 7, aligning with the "No" answer to the negated question. This ensures that the AI's responses are more precise and lead to a more efficient search space reduction. --- .../guessing-game/QuestionGuessingMode.tsx | 58 ++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/src/components/guessing-game/QuestionGuessingMode.tsx b/src/components/guessing-game/QuestionGuessingMode.tsx index 419a0da..b9704d5 100644 --- a/src/components/guessing-game/QuestionGuessingMode.tsx +++ b/src/components/guessing-game/QuestionGuessingMode.tsx @@ -55,17 +55,31 @@ const QuestionGuessingMode: React.FC = ({ if (baseQuestion.includes('is') && baseQuestion.includes('number')) { // Is the number... if (baseQuestion.includes('even')) { - // Count how many valid numbers are even vs odd const evenCount = Array.from(validNumbers).filter(n => n % 2 === 0).length; const oddCount = validNumbers.size - evenCount; - // Choose answer that keeps more numbers - const answer = evenCount > oddCount; + + let answer: boolean; + if (isNegated) { + // Question is "Is it NOT even?" - answer "Yes" if odd numbers are more + answer = oddCount > evenCount; + } else { + // Question is "Is it even?" - answer "Yes" if even numbers are more + answer = evenCount > oddCount; + } return { understood: true, answer, questionType: 'even', isNegated }; } if (baseQuestion.includes('odd')) { const oddCount = Array.from(validNumbers).filter(n => n % 2 !== 0).length; const evenCount = validNumbers.size - oddCount; - const answer = oddCount > evenCount; + + let answer: boolean; + if (isNegated) { + // Question is "Is it NOT odd?" - answer "Yes" if even numbers are more + answer = evenCount > oddCount; + } else { + // Question is "Is it odd?" - answer "Yes" if odd numbers are more + answer = oddCount > evenCount; + } return { understood: true, answer, questionType: 'odd', isNegated }; } if (baseQuestion.includes('prime')) { @@ -78,13 +92,29 @@ const QuestionGuessingMode: React.FC = ({ }; const primeCount = Array.from(validNumbers).filter(n => isPrime(n)).length; const nonPrimeCount = validNumbers.size - primeCount; - const answer = primeCount > nonPrimeCount; + + let answer: boolean; + if (isNegated) { + // Question is "Is it NOT prime?" - answer "Yes" if non-primes are more + answer = nonPrimeCount > primeCount; + } else { + // Question is "Is it prime?" - answer "Yes" if primes are more + answer = primeCount > nonPrimeCount; + } return { understood: true, answer, questionType: 'prime', isNegated }; } if (baseQuestion.includes('perfect square')) { const perfectSquareCount = Array.from(validNumbers).filter(n => Math.sqrt(n) % 1 === 0).length; const nonPerfectSquareCount = validNumbers.size - perfectSquareCount; - const answer = perfectSquareCount > nonPerfectSquareCount; + + let answer: boolean; + if (isNegated) { + // Question is "Is it NOT a perfect square?" - answer "Yes" if non-perfect squares are more + answer = nonPerfectSquareCount > perfectSquareCount; + } else { + // Question is "Is it a perfect square?" - answer "Yes" if perfect squares are more + answer = perfectSquareCount > nonPerfectSquareCount; + } return { understood: true, answer, questionType: 'perfectSquare', isNegated }; } } @@ -96,7 +126,21 @@ const QuestionGuessingMode: React.FC = ({ const divisor = parseInt(matches[1]); const divisibleCount = Array.from(validNumbers).filter(n => n % divisor === 0).length; const nonDivisibleCount = validNumbers.size - divisibleCount; - const answer = divisibleCount > nonDivisibleCount; + + // For negated questions, we need to think about which answer keeps more numbers + let answer: boolean; + if (isNegated) { + // Question is "Is it NOT divisible by X?" + // If we answer "Yes" (it is NOT divisible), we keep non-divisible numbers + // If we answer "No" (it IS divisible), we keep divisible numbers + answer = nonDivisibleCount > divisibleCount; // Answer "Yes" if non-divisible are more + } else { + // Question is "Is it divisible by X?" + // If we answer "Yes" (it is divisible), we keep divisible numbers + // If we answer "No" (it is NOT divisible), we keep non-divisible numbers + answer = divisibleCount > nonDivisibleCount; // Answer "Yes" if divisible are more + } + return { understood: true, answer, questionType: 'divisible', value: divisor, isNegated }; } }