strat-gameplay-webapp/backend/app/core
Cal Corum d1619b4a1f CLAUDE: Phase 3 - Substitution System Core Logic
Implemented comprehensive substitution system with DB-first pattern:

## Core Components (1,027 lines)

1. SubstitutionRules (345 lines)
   - Validates pinch hitter, defensive replacement, pitching change
   - Enforces no re-entry, roster eligibility, active status
   - Comprehensive error messages with error codes

2. SubstitutionManager (552 lines)
   - Orchestrates DB-first pattern: validate → DB → state
   - Handles pinch_hit, defensive_replace, change_pitcher
   - Automatic state sync and lineup cache updates

3. Database Operations (+115 lines)
   - create_substitution(): Creates sub with full metadata
   - get_eligible_substitutes(): Lists inactive players

4. Model Enhancements (+15 lines)
   - Added get_player_by_card_id() to TeamLineupState

## Key Features

-  DB-first pattern (database is source of truth)
-  Immutable lineup history (audit trail)
-  Comprehensive validation (8+ rule checks)
-  State + DB sync guaranteed
-  Error handling at every step
-  Detailed logging for debugging

## Architecture Decisions

- Position flexibility (MVP - no eligibility check)
- Batting order inheritance (pinch hitter takes spot)
- No re-entry (matches real baseball rules)
- Validation uses in-memory state (fast)

## Remaining Work

- WebSocket event handlers (2-3 hours)
- Comprehensive testing (2-3 hours)
- API documentation (1 hour)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 23:50:33 -06:00
..
__init__.py CLAUDE: Complete Week 4 - State Management & Persistence 2025-10-22 12:01:03 -05:00
ai_opponent.py CLAUDE: Implement Week 7 Task 1 - Strategic Decision Integration 2025-10-29 21:38:11 -05:00
cache.py CLAUDE: Implement Phase 3A - X-Check data models and enums 2025-11-01 15:32:09 -05:00
CLAUDE.md Offline catchup 2025-11-03 12:43:54 -06:00
dice.py CLAUDE: Complete Week 6 - granular PlayOutcome integration and metadata support 2025-10-29 20:29:06 -05:00
game_engine.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
play_resolver.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
roll_types.py CLAUDE: Complete Week 6 - granular PlayOutcome integration and metadata support 2025-10-29 20:29:06 -05:00
runner_advancement.py CLAUDE: Integrate X-Check advancement with full GameState support 2025-11-03 00:21:52 -06:00
state_manager.py CLAUDE: Phase 3E-Prep - Refactor GameState to use full LineupPlayerState objects 2025-11-03 14:11:40 -06:00
substitution_manager.py CLAUDE: Phase 3 - Substitution System Core Logic 2025-11-03 23:50:33 -06:00
substitution_rules.py CLAUDE: Phase 3 - Substitution System Core Logic 2025-11-03 23:50:33 -06:00
validators.py CLAUDE: Fix defensive decision validation for corners_in/infield_in depths 2025-10-30 10:25:01 -05:00
x_check_advancement_tables.py CLAUDE: Fix critical X-Check bugs and improve dice rolling 2025-11-02 23:09:16 -06:00