Commit Graph

10 Commits

Author SHA1 Message Date
Cal Corum
939ae421aa Add exception logging to effect registry (Issue #14)
Effect handler exceptions now logged at ERROR level with full context:
- effect_id, source_player_id, source/target card IDs, params
- Full traceback via logger.exception()

Game still returns safe EffectResult.failure() to prevent crashes,
but debugging information is now preserved in logs.
2026-01-26 13:32:43 -06:00
Cal Corum
1fbd3d1cfa Add knockout detection to damage effect handlers (Issue #13)
Both deal_damage and attack_damage now check if the target is knocked out
after applying damage. If KO'd, EffectResult includes:
- details['knockout'] = True
- details['knockout_pokemon_id'] = target's instance_id
- Message includes 'knocked out!' notification

Knockout check correctly respects HP modifiers via effective_hp().

Added 9 tests covering knockout detection, HP modifier behavior,
weakness-triggered knockouts, and resistance preventing knockouts.
2026-01-26 11:44:38 -06:00
Cal Corum
554178dc6e Track stadium ownership for correct discard (Issue #12)
Added stadium_owner_id field to GameState to track who played the stadium:

- stadium_owner_id: str | None tracks the player who played the current stadium
- When a stadium is replaced, old stadium discards to OWNER's pile (not current player)
- Added stadium_owner_id to VisibleGameState for client visibility
- Updated existing test and added 2 new tests for stadium ownership

This fixes the bug where replacing an opponent's stadium would discard
to the current player's pile instead of the opponent's.

797 tests passing.
2026-01-26 11:38:38 -06:00
Cal Corum
9432499018 Add forced action queue for double knockouts (Issue #10)
Changed forced_action from single item to FIFO queue to support
scenarios where multiple forced actions are needed simultaneously:

- forced_actions: list[ForcedAction] replaces forced_action: ForcedAction | None
- Added queue management methods:
  - has_forced_action() - check if queue has pending actions
  - get_current_forced_action() - get first action without removing
  - add_forced_action(action) - add to end of queue
  - pop_forced_action() - remove and return first action
  - clear_forced_actions() - clear all pending actions
- Updated engine, turn_manager, rules_validator, and visibility filter
- Added 8 new tests for forced action queue including double knockout scenario

This fixes the bug where simultaneous knockouts (e.g., mutual poison damage)
would lose one player's select_active action due to overwriting.

795 tests passing.
2026-01-26 11:33:47 -06:00
Cal Corum
8e084d250a Fix per-ability usage tracking (Issue #9)
Changed ability_uses_this_turn from int to dict[int, int] to track each
ability's usage independently:

- ability_uses_this_turn: dict[int, int] maps ability index to use count
- can_use_ability() now requires ability_index parameter
- Added get_ability_uses() and increment_ability_uses() helper methods
- reset_turn_state() clears the dict instead of setting to 0

This fixes the bug where using one ability could incorrectly block
another ability on the same Pokemon from being used.

789 tests passing.
2026-01-26 11:11:23 -06:00
Cal Corum
0534c57430 Add SelectPrizeAction executor and turn limit check (Issues #11, #15)
Issue #11 - SelectPrizeAction:
- Add _execute_select_prize() method to GameEngine
- Add prize card mode support to process_knockout()
- Add _award_prize_cards() helper for random/player-choice selection
- Support multi-prize selection (EX/VMAX worth 2-3 prizes)

Issue #15 - Turn Limit Check:
- Add turn limit check at start of start_turn()
- Add GameEndReason.TURN_LIMIT enum value (distinct from TIMEOUT)
- Game ends when turn limit exceeded, winner determined by score
- Equal scores result in DRAW

Added 12 new tests for prize card mode and turn limit functionality.
788 tests passing.
2026-01-26 11:04:03 -06:00
Cal Corum
7fae1c61e8 Add CardDefinition validation for required fields (Issue #2)
- Add model_validator to enforce card-type-specific required fields
- Pokemon: require hp (positive), stage, pokemon_type
- Pokemon Stage 1/2 and VMAX/VSTAR: require evolves_from
- Trainer: require trainer_type
- Energy: require energy_type (auto-fills energy_provides)
- Update all test fixtures to include required fields
- Mark Issue #2 as FIXED in SYSTEM_REVIEW.md

765 tests passing
2026-01-26 10:28:37 -06:00
Cal Corum
8af326ecee Fix SYSTEM_REVIEW.md - correct count of fixed issues (4/8, not 5/8)
Issues #2, #3, #4, #6 are still open:
- #2: CardDefinition field validation not added
- #3: end_turn() knockout processing not fixed
- #4: Win condition timing not fixed
- #6: Engine doesn't call process_knockout for status KOs

The refactor improved process_knockout() internals but didn't fix the
callers that should invoke it.
2026-01-26 10:08:58 -06:00
Cal Corum
dd2cadf82d Update SYSTEM_REVIEW.md with fixed issues from energy/evolution refactor
Mark issues #1, #5, #7, #8 as FIXED:
- #1: find_card_instance now includes energy_zone + attached cards
- #5: Energy stored as CardInstance objects, not just IDs
- #7: Confusion handling added to attack execution
- #8: discard_energy handler moves cards to owner's discard

Update test count to 766 and add change log section.
2026-01-26 09:45:06 -06:00
Cal Corum
8668a0d824 Add system review document from multi-agent code review
Comprehensive review of core engine implementation identifying:
- 8 critical issues (energy tracking, knockout processing, confusion handling)
- 7 medium priority issues (prize selection, stadium ownership, etc.)
- Low priority observations and missing functionality
- Recommended fix priority in 3 phases
- Test coverage status per module (94% overall)
2026-01-25 14:09:57 -06:00