Commit 6d9099d
authored
feat: hand history tracking (#35)
* feat: add chronological board card tracking to game engine
- Add boardOrder slice to HandState to preserve dealing sequence
- Implement BoardCards() method for chronological access
- Update hand_runner to use BoardCards() instead of bitset iteration
- Add TestBoardCardsPreserveDealingOrder with deterministic verification
- Add integration tests for board emission ordering
This fixes PHH board card ordering by tracking the actual sequence
cards are dealt rather than relying on bitset iteration order.
* feat: implement PHH hand history encoder and types
- Add HandHistory struct with all spec-compliant fields
- Implement TOML encoder with proper field ordering
- Add card notation helpers (10h → Th conversion)
- Support player rotation (SB-first ordering per spec)
- Implement bulk .phhs format with section headers
- Add comprehensive encoder tests
Implements the Poker Hand History (PHH) standard format
as specified at https://phh.readthedocs.io/
* feat: add hand history monitor with buffered recording
- Implement Monitor with mutex-protected buffer and async flushing
- Add Manager for server-wide flush coordination
- Support player rotation and blind tracking per PHH spec
- Track chronological board progression per street
- Implement failure state machine (3 strikes → disable)
- Prevent race conditions in CreateMonitor with double-check locking
- Add comprehensive tests with race detection
Buffering reduces disk I/O to ~1 write per 100 hands or 10 seconds.
* feat: integrate hand history into server with CLI flags
- Wire Manager into Server lifecycle with graceful shutdown
- Add hand history config fields (dir, flush interval, hole cards)
- Create Monitor per game with automatic registration
- Add --hand-history flags to spawn and server commands
- Flush all buffers on server shutdown (zero data loss)
- Update Server tests to cover hand history integration
Hand history recording disabled by default for backward compatibility.
* feat: add hand history render command and playback
- Implement 'hand-history render' command for PHH file replay
- Add playback engine that reverses player rotation to seat positions
- Infer button position from PHH ordering (SB-first convention)
- Support both .phh and .phhs formats
- Add comprehensive playback tests
- Support --limit flag for rendering subset of hands
Enables post-game analysis and hand review workflows.
* docs: add hand history documentation and examples
- Add comprehensive hand-history.md with format guide and examples
- Update operations.md with hand history usage instructions
- Add analyze-phh.py example for Python integration
- Add implementation plan document
- Update README with hand history feature
- Update TODO.md to mark v1.0 complete
Provides complete documentation for hand history feature including
PHH format specification, CLI usage, and integration examples.
* feat: use UTC for all hand history timestamps
- Convert all timestamps to UTC in populateTimeFields
- Remove time_zone_abbreviation field (non-standard)
- Update documentation to clarify UTC usage
- Update tests to reflect UTC-only format
Ensures consistent time handling across all PHH files regardless
of server timezone configuration.
* docs: update hand history plan to reflect completion
- Mark status as complete with all phases done
- Remove outdated bug section (all bugs fixed)
- Update file format examples to show [1] section headers
- Update acceptance criteria with all items checked
- Add completed implementation details (UTC, player rotation, showdown tracking)
- Remove reference to deleted analyze-phh.py example
* feat: add partial flush recovery and section counter resumption
- Add dedicated flushMu to prevent concurrent flush races
- Track partial flush progress and only remove successfully written hands
- Resume section counter from existing file on Monitor creation
- Prevent section number gaps on partial failures
- Add helpers: writeHand, finalizeFlush, readLastSectionCounter
Ensures hand history files maintain consistency even with partial
flush failures or server restarts.1 parent c7263c8 commit 6d9099d
File tree
31 files changed
+3575
-88
lines changed- cmd/pokerforbots
- docs
- internal
- game
- phh
- server
- hand_history
- plans
31 files changed
+3575
-88
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | | - | |
| 130 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
124 | | - | |
| 125 | + | |
0 commit comments