Fix Zeckendorf game: add more Fibonacci numbers (up to 55) to ensure targets are reachable

This commit is contained in:
Neeldhara Misra 2025-07-22 11:08:21 +05:30
parent c8d3475104
commit 179e247f71

View file

@ -4,8 +4,8 @@ import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import SocialShare from '@/components/SocialShare';
// First 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21
const FIBONACCI_NUMBERS = [21, 13, 8, 5, 3, 2, 1, 1];
// First 10 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
const FIBONACCI_NUMBERS = [55, 34, 21, 13, 8, 5, 3, 2, 1, 1];
interface ZeckendorfGameProps {
showSocialShare?: boolean;
@ -13,7 +13,7 @@ interface ZeckendorfGameProps {
const ZeckendorfGame: React.FC<ZeckendorfGameProps> = ({ showSocialShare = true }) => {
const [targetNumber, setTargetNumber] = useState<number>(0);
const [flippedCards, setFlippedCards] = useState<boolean[]>(new Array(8).fill(false));
const [flippedCards, setFlippedCards] = useState<boolean[]>(new Array(10).fill(false));
const [currentSum, setCurrentSum] = useState<number>(0);
const [timer, setTimer] = useState<number>(0);
const [isGameActive, setIsGameActive] = useState<boolean>(false);
@ -39,7 +39,7 @@ const ZeckendorfGame: React.FC<ZeckendorfGameProps> = ({ showSocialShare = true
for (let i = 0; i < numTerms; i++) {
let index;
do {
index = Math.floor(Math.random() * 8);
index = Math.floor(Math.random() * 10);
} while (usedIndices.has(index));
usedIndices.add(index);
@ -53,7 +53,7 @@ const ZeckendorfGame: React.FC<ZeckendorfGameProps> = ({ showSocialShare = true
const startNewGame = useCallback(() => {
const newTarget = generateValidTarget();
setTargetNumber(newTarget);
setFlippedCards(new Array(8).fill(false));
setFlippedCards(new Array(10).fill(false));
setCurrentSum(0);
setTimer(0);
setIsGameActive(true);
@ -135,7 +135,7 @@ const ZeckendorfGame: React.FC<ZeckendorfGameProps> = ({ showSocialShare = true
</div>
{/* Cards representing Fibonacci numbers */}
<div className="grid grid-cols-8 gap-3">
<div className="grid grid-cols-10 gap-3">
{FIBONACCI_NUMBERS.map((fib, index) => (
<div key={fib} className="flex flex-col items-center space-y-2">
<Card