Phase changes and passing priority are cryptic
First, some questions:
Now I shall report some strangeness. This is from my game-state unit-tests, with my comments in dark red:
Game-state initialized.
Cards added to Human's library.
Human draws 5 cards.
Cards added to Computer's library.
Computer draws 3 cards.
Phase.handleBeginPhase() completed.
For Turn 1 (Human's) Upkeep Step, Human's possible moves are [passes priority].
Human passes priority.
For Turn 1 (Human's) Upkeep Step, Computer's possible moves are [passes priority].
So far, so good.
Computer passes priority.
For Turn 1 (Human's) Upkeep Step, Human's possible moves are [passes priority].
What? We should be in the Draw step now.
Human passes priority.
For Turn 1 (Human's) Draw Step, Computer's possible moves are [passes priority].
Computer passes priority.
For Turn 1 (Human's) Draw Step, Human's possible moves are [passes priority].
Human passes priority.
OK, both players passed priority, but the Human player should have had priority at the start of the Draw step.
For Turn 1 (Human's) Main1 Step, Computer's possible moves are [passes priority].
Computer passes priority.
For Turn 1 (Human's) Main1 Step, Human's possible moves are [plays land "Island", passes priority].
Human plays land "Island".
For Turn 1 (Human's) BeginCombat Step, Human's possible moves are [passes priority].
How did we get to BeginCombat from Main1 without both players passing? Granted, nobody had any other possible moves to make, so maybe this is an optimization. Am I right? It does not seem to be a case of auto-passing priority (e.g., from GUI settings).
I'm considering fixing this in the following manner:
*Otherwise, I'm sure to introduce bugs.
- Why does passing priority into the next phase not automatically call Phase.handleBeginPhase? It seems this is only called from InputControl.updateInput when Phase.doPhaseEffects returns true.
- Can someone explain why MagicStack.add calls Phase.passPriority when the simultaneousStackEntryList is non-empty?
Now I shall report some strangeness. This is from my game-state unit-tests, with my comments in dark red:
Game-state initialized.
Cards added to Human's library.
Human draws 5 cards.
Cards added to Computer's library.
Computer draws 3 cards.
Phase.handleBeginPhase() completed.
For Turn 1 (Human's) Upkeep Step, Human's possible moves are [passes priority].
Human passes priority.
For Turn 1 (Human's) Upkeep Step, Computer's possible moves are [passes priority].
So far, so good.
Computer passes priority.
For Turn 1 (Human's) Upkeep Step, Human's possible moves are [passes priority].
What? We should be in the Draw step now.
Human passes priority.
For Turn 1 (Human's) Draw Step, Computer's possible moves are [passes priority].
Computer passes priority.
For Turn 1 (Human's) Draw Step, Human's possible moves are [passes priority].
Human passes priority.
OK, both players passed priority, but the Human player should have had priority at the start of the Draw step.
For Turn 1 (Human's) Main1 Step, Computer's possible moves are [passes priority].
Computer passes priority.
For Turn 1 (Human's) Main1 Step, Human's possible moves are [plays land "Island", passes priority].
Human plays land "Island".
For Turn 1 (Human's) BeginCombat Step, Human's possible moves are [passes priority].
How did we get to BeginCombat from Main1 without both players passing? Granted, nobody had any other possible moves to make, so maybe this is an optimization. Am I right? It does not seem to be a case of auto-passing priority (e.g., from GUI settings).
I'm considering fixing this in the following manner:
- Augment Phase.passPriority so that it maintains a Set of the players who have passed when the stack was empty. Once all players have passed, it gives priority to the turn-owner and sets needToNextPhase.
- I'll try to retain the calls (which I do not comprehend*) to InputControl.resetInput, MagicStack.chooseOrderOfSimultaneousStackEntryAll, MagicStack.hasSimultaneousStackEntries, and MagicStack.resolveStack.
- Change MagicStack so that whenever something is pushed onto the MagicStack, it resets Phase's memory of what players have passed. (All players must pass priority for a phase to end.)
*Otherwise, I'm sure to introduce bugs.
