strat-gameplay-webapp/backend/terminal_client
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
..
update_docs CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
__init__.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
__main__.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
arg_parser.py CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
CLAUDE.md CLAUDE: Implement player models and optimize database queries 2025-10-28 14:08:56 -05:00
commands.py CLAUDE: Implement play rollback functionality for error recovery 2025-10-30 16:02:51 -05:00
completions.py CLAUDE: Add manual outcome testing to terminal client and Phase 3 planning 2025-10-29 20:53:47 -05:00
config.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
display.py CLAUDE: Implement player models and optimize database queries 2025-10-28 14:08:56 -05:00
help_text.py CLAUDE: Add manual outcome testing to terminal client and Phase 3 planning 2025-10-29 20:53:47 -05:00
main.py CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
repl.py CLAUDE: Implement play rollback functionality for error recovery 2025-10-30 16:02:51 -05:00