Skip to content

Conversation

@sudo-owen
Copy link
Collaborator

No description provided.

claude added 10 commits January 8, 2026 16:28
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants