Fix step to end to win step

Compute winning step where a player first reaches 26 gifts and sync both players to that exact step, advancing to that step for both and ensuring at least one undiscovered gift for the loser unless tie.

X-Lovable-Edit-ID: edt-921d1c7e-89b5-49dc-ae02-ffee236d632b
This commit is contained in:
gpt-engineer-app[bot] 2025-11-19 03:56:53 +00:00
commit 363e681f48

View file

@ -273,7 +273,26 @@ const PresentsPuzzle = ({
};
const stepToEnd = () => {
updateStep(99);
const { presents, aliceOrder: aOrder, bobOrder: bOrder } = initializeSimulation();
let aliceCount = 0;
let bobCount = 0;
let winningStep = 99; // default to last step if no winner found
// Find the step where someone first wins
for (let i = 0; i < 100; i++) {
if (presents.has(aOrder[i])) aliceCount++;
if (presents.has(bOrder[i])) bobCount++;
// Check if someone won on this step
if (aliceCount === 26 || bobCount === 26) {
winningStep = i;
break;
}
}
// Update to that step
updateStep(winningStep);
};
const stepToStart = () => {