Veit F. a07117efaf fix: implement correct Texas Hold'em betting rules and game flow
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
2026-05-17 18:46:08 +02:00

35 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## ADDED Requirements
### Requirement: Side pots are created when players go all-in at different bet levels
When one or more players go all-in for less than the current bet level, the system SHALL create separate side pots to ensure only eligible players can win chips they contributed to.
#### Scenario: Single all-in creates main pot and side pot
- **WHEN** Player A bets 100, Player B goes all-in for 50, and Player C calls 100
- **THEN** a main pot of 150 (50×3) is created with all three players eligible, and a side pot of 100 (25×4) is created with Players A and C eligible
#### Scenario: Multiple all-ins create multiple side pots
- **WHEN** Player A bets 200, Player B goes all-in for 100, Player C goes all-in for 150, and Player D calls 200
- **THEN** a main pot of 400 (100×4) is created with all players eligible, a side pot of 100 (50×3) is created with Players A, C, D eligible, and a side pot of 100 (50×2) is created with Players A and D eligible
### Requirement: Side pots are awarded to eligible winners only
When determining winners for each pot, the system SHALL only award a pot to players who contributed chips to that specific pot level.
#### Scenario: All-in player wins main pot only
- **WHEN** Player B is all-in for 50 and has the best hand at showdown, Player A and C are still active with worse hands
- **THEN** Player B receives the main pot amount proportional to their contribution, and Players A/C compete for the side pot
#### Scenario: All-in player loses all pots
- **WHEN** Player B is all-in for 50 and has the worst hand at showdown
- **THEN** Player B receives no chips from any pot, and eligible players split the main pot proportionally
### Requirement: Side pot calculation handles edge cases correctly
The system SHALL correctly calculate side pots when all players go all-in or when an all-in does not constitute a raise.
#### Scenario: All players all-in creates single pot
- **WHEN** all remaining players go all-in during a betting round
- **THEN** a single main pot containing all chips is created with all players eligible, and no side pots are generated
#### Scenario: All-in that doesn't raise does not create side pot
- **WHEN** the current bet is 100 and Player B goes all-in for 80 (less than a full raise)
- **THEN** no side pot is created; the main pot contains all chips and active players may check to continue