mantimon-tcg/backend/app/core
Cal Corum 2b8fac405f Implement energy/tools as CardInstance + evolution stack + devolve effect
Major refactor to properly track attached cards and evolution history:

Model Changes (app/core/models/card.py):
- Change attached_energy from list[str] to list[CardInstance]
- Change attached_tools from list[str] to list[CardInstance]
- Add cards_underneath field for evolution stack tracking
- Update attach_energy/detach_energy to work with CardInstance
- Add attach_tool/detach_tool methods
- Add get_all_attached_cards helper

Engine Changes (app/core/engine.py):
- _execute_attach_energy: Pass full CardInstance to attach_energy
- _execute_evolve: Build evolution stack, transfer attachments, clear status
- _execute_retreat: Detached energy goes to discard pile
- Fix: Evolution now clears status conditions (Pokemon TCG standard)

Game State (app/core/models/game_state.py):
- find_card_instance now searches attached_energy, attached_tools, cards_underneath

Turn Manager (app/core/turn_manager.py):
- process_knockout: Discard all attached energy, tools, and evolution stack

Effects (app/core/effects/handlers.py):
- discard_energy: Find owner's discard pile and move detached energy there
- NEW devolve effect: Remove evolution stages with configurable destination
- Fix: Use EffectType.SPECIAL instead of non-existent EffectType.ZONE

Rules Validator (app/core/rules_validator.py):
- Update energy type checking to iterate CardInstance objects

Tests:
- Update existing tests for new CardInstance-based energy attachment
- NEW test_evolution_stack.py with 28 comprehensive tests covering:
  - Evolution stack building (Basic -> Stage 1 -> Stage 2)
  - Energy/tool transfer and damage carryover on evolution
  - Devolve effect (single/multi stage, hand/discard destination, KO check)
  - Knockout processing with all attachments going to discard
  - find_card_instance for attached cards and evolution stack

All 765 tests pass.
2026-01-25 23:09:40 -06:00
..
effects Implement energy/tools as CardInstance + evolution stack + devolve effect 2026-01-25 23:09:40 -06:00
models Implement energy/tools as CardInstance + evolution stack + devolve effect 2026-01-25 23:09:40 -06:00
__init__.py Add game engine foundation: enums, config, and RNG modules 2026-01-24 22:14:45 -06:00
config.py Add rules validator, win conditions checker, and coverage gap tests 2026-01-25 12:57:06 -06:00
engine.py Implement energy/tools as CardInstance + evolution stack + devolve effect 2026-01-25 23:09:40 -06:00
rng.py Add game engine foundation: enums, config, and RNG modules 2026-01-24 22:14:45 -06:00
rules_validator.py Implement energy/tools as CardInstance + evolution stack + devolve effect 2026-01-25 23:09:40 -06:00
turn_manager.py Implement energy/tools as CardInstance + evolution stack + devolve effect 2026-01-25 23:09:40 -06:00
visibility.py Add visibility filter for client-safe game state views 2026-01-25 13:11:06 -06:00
win_conditions.py Add rules validator, win conditions checker, and coverage gap tests 2026-01-25 12:57:06 -06:00