-
Notifications
You must be signed in to change notification settings - Fork 0
feat: hand history tracking #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ad8d05d to
90cc33e
Compare
90cc33e to
86f56ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
31b333b to
2526697
Compare
- 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.
- 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/
- 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.
- 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.
- 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.
- 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.
fd759bb to
49e03fb
Compare
- 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.
49e03fb to
e59144c
Compare
|
@codex review please? |
- 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- 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.
|
@codex issues addressed, review again please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Hand History Tracking with PHH Format
Implements hand history recording using the PHH (Poker Hand History) standard format - a TOML-based academic standard (IEEE CoG 2024) designed for poker AI research. Enables post-game analysis, bot debugging, and ML training dataset creation.
Key Features
100% PHH Spec Compliance: Implements all required and optional fields from the official specification. No custom extensions.
Chronological Board Tracking: Fixed board card ordering by tracking actual dealing sequence instead of bitset iteration. Flop/turn/river cards emit in correct order.
Player Rotation: SB-first ordering per PHH spec with proper blind tracking per position.
High-Performance Buffered Recording: In-memory buffering with async disk I/O. Flushes every 10s/100 hands. Zero performance impact (350+ hands/sec maintained).
Multi-Game Architecture: Per-game file isolation (
hands/game-{id}/session.phhs), mutex-protected buffers, partial flush recovery, section counter resumption on restart.Failure Recovery: 3-strike disable policy, graceful degradation, no data loss on partial flush failures.
Privacy Controls: Hole cards masked as
????by default during deal. Showdown cards (publicly revealed) always recorded. Opt-in with--hand-history-hole-cardsto include all private hole cards.UTC Timestamps: All timestamps normalized to UTC for consistency.
Usage
Example Output
Player-indexed arrays (
players,seats,antes,blinds_or_straddles,starting_stacks,finishing_stacks,winnings) start with the small blind and wrap clockwise per PHH spec.Implementation
Core Changes:
internal/game/hand.go- AddedboardOrderslice andBoardCards()method for chronological trackinginternal/phh/- PHH encoder, types, card notation helpers, bulk.phhsformatinternal/server/hand_history/- Buffered monitor with player rotation, manager with flush coordinationcmd/pokerforbots/hand_history_cmd.go- Render command with playback engineConfiguration Flags:
--hand-history- Enable recording (default: disabled)--hand-history-dir- Base directory (default:hands)--hand-history-flush-secs- Flush interval (default: 10s)--hand-history-flush-hands- Flush count threshold (default: 100)--hand-history-hole-cards- Include all private hole cards (default: false)Performance: ~200KB memory per game, ~2MB per 1000 hands, <1% throughput overhead
Testing
go test -race ./...)Documentation
Breaking Changes
None. Opt-in feature, disabled by default.