strat-gameplay-webapp/backend/app
Cal Corum 9b03fb555b CLAUDE: Implement play rollback functionality for error recovery
Add ability to roll back the last N plays, useful for correcting mistakes
or recovering from corrupted plays. Deletes plays from database and
reconstructs game state by replaying remaining plays.

Database Operations (app/database/operations.py):
- delete_plays_after(): Delete plays with play_number > target
- delete_substitutions_after(): Delete lineup entries with after_play >= target
- delete_rolls_after(): Delete dice rolls (kept for reference, not used)

Game Engine (app/core/game_engine.py):
- rollback_plays(): Main rollback orchestration
  - Validates: num_plays > 0, enough plays exist, game not completed
  - Deletes plays and substitutions from database
  - Clears in-memory roll tracking
  - Calls state_manager.recover_game() to rebuild state
  - Returns updated GameState

Terminal Client (terminal_client/commands.py, terminal_client/repl.py):
- rollback_plays(): Command wrapper with user-friendly output
- do_rollback(): REPL command with argument parsing

Usage:
   > rollback 3

Validations:
- Cannot roll back more plays than exist
- Cannot roll back completed games
- Rolling back across innings is allowed
- Substitutions after rolled-back plays are undone

Testing:
-  Successfully rolls back 2 plays from 5-play game
-  Correctly validates rollback of 10 plays when only 2 exist
-  Game state properly reconstructed via replay

Note: Dice rolls kept in database for auditing (don't affect state).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 16:02:51 -05:00
..
api CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
config CLAUDE: Implement Week 7 Task 3 - Result chart abstraction and PD auto mode 2025-10-30 12:42:41 -05:00
core CLAUDE: Implement play rollback functionality for error recovery 2025-10-30 16:02:51 -05:00
database CLAUDE: Implement play rollback functionality for error recovery 2025-10-30 16:02:51 -05:00
models CLAUDE: Implement Week 7 Task 3 - Result chart abstraction and PD auto mode 2025-10-30 12:42:41 -05:00
utils CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
websocket CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
__init__.py CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
config.py CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
main.py CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00