Implements source-aware triggered-ability damage for ETB and dies triggers
as part of the ongoing issue #86 damage-routing work.
Changes:
- Add deal_damage() centralized static method to GameEngine that handles
life reduction, stats tracking, elimination checks, and event logging
- Add etb_damage/dies_damage fields and target modes to Card model
- Add _detect_trigger_damage() heuristic in rules.py to parse ETB/dies
damage amounts and target modes from oracle text
- Wire ETB triggers to fire when creatures enter via _play_spells and
commander casting from command zone
- Wire dies triggers to fire in _send_to_graveyard for removal, board
wipes, and combat deaths
- Route combat damage through deal_damage() for consistent stat tracking
- Add 24 targeted regression tests covering deal_damage unit behavior,
trigger detection, ETB/dies firing, combat routing, and integration
All 355 existing tests continue to pass with 0 regressions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously _resolve_combat() used a binary power-vs-toughness kill check:
creatures only died if a single source had power >= their toughness in one
swing. This meant a 2/2 wouldn't die to two 1/1 tokens blocking it, and
repeated smaller hits across combats never accumulated.
Changes:
- models.py: add damage_marked field to Card (default 0)
- engine.py: accumulate damage via damage_marked += power instead of
binary a_pow >= toughness checks in _resolve_combat()
- engine.py: clear damage_marked = 0 in untap phase (MTG rule 514.2)
This enables multi-blocker lethality, incremental chip damage within a
combat step, and proper creature death-by-accumulated-damage interactions.
- Add ml_log param, ml_decisions list, flush_ml_decisions() to GameEngine
- Capture ML snapshots at each player turn in run_n()
- Stamp game_outcome (win/loss per seat) on all decisions
- Add _capture_ml_snapshot() matching DeepSeekGameEngine format
- Add game_id and archetype params to run_n() for ML tracking
- Import logging, uuid; add logger
Add "validation" key to _log_decision() entry dict in deepseek_brain.py.
Captures result.get("validation") (None if validator disabled)
for R1-14B output preservation and future analysis.
- CAST_PATTERN: Add optional (?:Add To Stack:\s*)? prefix to match Forge's verbose log format
- LAND_PLAY_PATTERN: Add optional (?:Land:\s*)? prefix to match Forge's verbose log format
- Add [PARSE] diagnostic logging after combat stats parsing to confirm spells/lands/cmdr stats per seat
Root cause: Forge verbose output prefixes cast lines with "Add To Stack: " and land lines with "Land: "
but the regexes expected Ai(N) at the start of the line, causing 0 matches for all combat stats.