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:
commit
ca39141f80
1 changed files with 4 additions and 1 deletions
|
|
@ -273,6 +273,9 @@ const PresentsPuzzle = ({
|
|||
};
|
||||
|
||||
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();
|
||||
|
||||
let aliceCount = 0;
|
||||
|
|
@ -465,7 +468,7 @@ const PresentsPuzzle = ({
|
|||
</Button>
|
||||
<Button
|
||||
onClick={stepToEnd}
|
||||
disabled={isRunning || currentStep >= 99}
|
||||
disabled={isRunning || currentStep >= 99 || winner !== null}
|
||||
variant="outline"
|
||||
className="gap-2"
|
||||
title="Step to end"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue