-
Notifications
You must be signed in to change notification settings - Fork 2
Add double battle game mode support #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudo-owen
wants to merge
10
commits into
main
Choose a base branch
from
claude/add-double-battles-3PJU2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Milestone 1 of doubles refactor: - Add GameMode enum (Singles, Doubles) - Extend BattleData with slotSwitchFlagsAndGameMode (packed uint8) - Add p0Move2, p1Move2 to BattleConfig for slot 1 moves - Add constants for activeMonIndex 4-bit packing and switch flags - Update Engine startBattle to initialize doubles fields - Update getBattleContext/getCommitContext to extract game mode - Add gameMode field to Battle, ProposedBattle structs - Update matchmaker and CPU to pass gameMode - Update all tests with gameMode: GameMode.Singles All changes are backwards compatible - singles mode works unchanged.
Fixes compilation error from Milestone 1 - BattleConfigView was missing the new doubles move fields.
Milestone 2 progress: - Add getGameMode(battleKey) - returns GameMode enum - Add getActiveMonIndexForSlot(battleKey, playerIndex, slotIndex) - For doubles: uses 4-bit packing per slot - For singles: falls back to existing 8-bit packing These getters allow external contracts to query the game mode and active mons for specific battle slots.
Milestone 3: Doubles Commit Manager - Create DoublesCommitManager.sol with: - commitMoves(): commits hash of both slot moves - revealMoves(): reveals and validates both moves at once - Same alternating commit scheme as singles - Update Engine.setMove() to handle slot 1 moves: - playerIndex 0-1: slot 0 moves (existing behavior) - playerIndex 2-3: slot 1 moves (stored in p0Move2/p1Move2) Hash format: keccak256(moveIndex0, extraData0, moveIndex1, extraData1, salt)
- Add helper functions for doubles-specific active mon index packing - Add _computeMoveOrderForDoubles for 4-move priority sorting - Add _handleMoveForSlot for executing moves per slot - Add _handleSwitchForSlot for handling slot-specific switches - Add _checkForGameOverOrKO_Doubles for doubles KO tracking - Add _executeDoubles as main execution function for doubles mode - Add comprehensive tests for doubles commit/reveal/execute flow
- Fix getActiveMonIndexForBattleState to be doubles-aware - Fix getDamageCalcContext to use correct slot unpacking in doubles - Add DoublesTargetedAttack mock for testing slot-specific targeting - Add comprehensive doubles boundary condition tests: - test_doublesFasterSpeedExecutesFirst - test_doublesFasterPriorityExecutesFirst - test_doublesPositionTiebreaker - test_doublesPartialKOContinuesBattle - test_doublesGameOverWhenAllMonsKOed - test_doublesSwitchPriorityBeforeAttacks - test_doublesNonKOSubsequentMoves
- Add _handleSwitchCore for shared switch-out effects logic - Add _completeSwitchIn for shared switch-in effects logic - Add _checkForGameOver for shared game over detection - Refactor _handleSwitch to use shared functions - Refactor _handleSwitchForSlot to use shared functions - Refactor _checkForGameOverOrKO to use _checkForGameOver - Refactor _checkForGameOverOrKO_Doubles to use _checkForGameOver This reduces code duplication between singles and doubles execution paths.
Add validatePlayerMoveForSlot to IValidator and DefaultValidator: - Validates moves for specific slots in doubles mode - Enforces switch for KO'd mons, allows NO_OP if no valid targets - Prevents switching to mon already active in other slot - Update DoublesCommitManager to use new validation
Test scenarios for validatePlayerMoveForSlot: - Turn 0 only allows SWITCH_MOVE_INDEX - After turn 0, attacks are allowed for non-KO'd mons - Can't switch to same mon or other slot's active mon - One player with 1 KO'd mon (with/without valid switch targets) - Both players with 1 KO'd mon each (both/neither have targets) - Integration test for validation after KO - Reveal revert test for invalid moves on KO'd slot
When a player has a KO'd mon with valid switch targets, only they act next turn. Changes include: - Add _playerNeedsSwitchTurn helper to check if player needs switch turn - Update _checkForGameOverOrKO_Doubles to set playerSwitchForTurnFlag - Fix _handleMoveForSlot to allow SWITCH on KO'd slots - Fix _computeMoveOrderForDoubles to handle unset moves in single-player turns - Update tests for new turn flow behavior
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.