Fix step to end edge case

Ensure step-to-end stops at current final state instead of rewinding to an earlier winning step; add guard to do nothing if already at end or winner determined, preserving final outcome. Adjust logic to prevent recalculation after completion.

X-Lovable-Edit-ID: edt-7b7e08ff-28cd-4aed-9f1f-08fce229a90b
This commit is contained in:
gpt-engineer-app[bot] 2025-11-19 03:59:09 +00:00
commit ca39141f80

View file

@ -273,6 +273,9 @@ const PresentsPuzzle = ({
}; };
const stepToEnd = () => { const stepToEnd = () => {
// Don't do anything if already at end or winner already determined
if (currentStep >= 99 || winner !== null) return;
const { presents, aliceOrder: aOrder, bobOrder: bOrder } = initializeSimulation(); const { presents, aliceOrder: aOrder, bobOrder: bOrder } = initializeSimulation();
let aliceCount = 0; let aliceCount = 0;
@ -465,7 +468,7 @@ const PresentsPuzzle = ({
</Button> </Button>
<Button <Button
onClick={stepToEnd} onClick={stepToEnd}
disabled={isRunning || currentStep >= 99} disabled={isRunning || currentStep >= 99 || winner !== null}
variant="outline" variant="outline"
className="gap-2" className="gap-2"
title="Step to end" title="Step to end"