Rewrite core game logic to fix 10 critical bugs violating poker rules: - Add betMatched flag to separate chip tracking from bet-matching state - Implement last-aggressor tracking for proper betting round completion - Rewrite all action functions with validation enforcement - Add side pot support for multi-level all-in scenarios - Replace nested setTimeout AI turns with async promise chain - Add aiActing guard to prevent race conditions during AI play - Fix currentTurn advancement to always land on active players
50 lines
2.7 KiB
Markdown
50 lines
2.7 KiB
Markdown
# betting-round-flow Specification
|
|
|
|
## Purpose
|
|
TBD - created by archiving change fix-texas-holdem-rules. Update Purpose after archive.
|
|
## Requirements
|
|
### Requirement: Check action does not modify player chip count or bet contribution
|
|
When a player checks, the system SHALL only mark the player as having matched the current bet level without deducting chips or modifying their `currentBet` value.
|
|
|
|
#### Scenario: Check with zero current bet
|
|
- **WHEN** the current bet is 0 and Player A checks
|
|
- **THEN** Player A's `betMatched` becomes true, `currentBet` remains unchanged, and chip count remains unchanged
|
|
|
|
#### Scenario: Check after matching previous bet
|
|
- **WHEN** Player A has already called a bet of 100 (currentBet = 100) and the next player checks (no raise occurred)
|
|
- **THEN** Player A's state remains unchanged except `betMatched` is set to true
|
|
|
|
### Requirement: Betting round completes when action returns to last aggressor
|
|
The system SHALL end a betting round when all active players have matched the current bet and action returns to the position of the last player who raised or opened betting.
|
|
|
|
#### Scenario: Pre-flop BB option (no raises)
|
|
- **WHEN** SB posts 10, BB posts 20, and all players check around back to BB
|
|
- **THEN** BB may check without posting additional chips, and the betting round completes
|
|
|
|
#### Scenario: Raise requires action to return to raiser
|
|
- **WHEN** Player A raises to 100, Players B and C call, and Player D checks
|
|
- **THEN** the round does not complete until Player A either checks or faces no further raises
|
|
|
|
### Requirement: All-in players are excluded from betting round completion check
|
|
When determining if a betting round is complete, the system SHALL only consider active (non-all-in) players for the "all matched" condition.
|
|
|
|
#### Scenario: Active player skipped by all-in completion bug
|
|
- **WHEN** Player A bets 100, Player B goes all-in for 50, and Player C has not yet acted
|
|
- **THEN** the betting round does NOT complete; Player C must act before the round advances
|
|
|
|
#### Scenario: Single active player ends round
|
|
- **WHEN** all players except one have folded or gone all-in
|
|
- **THEN** the betting round completes immediately and the game proceeds to the next stage
|
|
|
|
### Requirement: Turn advancement skips non-active players correctly
|
|
The system SHALL advance turns to the next player with `status === 'active'`, skipping folded and all-in players.
|
|
|
|
#### Scenario: Folded player is skipped
|
|
- **WHEN** Player A folds and it's their turn position
|
|
- **THEN** the turn advances to the next active player clockwise from Player A
|
|
|
|
#### Scenario: All-in player is skipped during betting
|
|
- **WHEN** Player B goes all-in during a betting round
|
|
- **THEN** subsequent turns skip Player B and advance to the next active player
|
|
|