JPoker is a simple implementation of Texas Hold 'em (head-to-head no-limit tournament style) to learn cards and Java.
Implementation
Since I'm not a card player and the goal of this project isn't to gain a deep understanding of the game, I'll use these approximations of the standard rules. Any deviations are hereby declared house rules. In particular, the Ace card is always low because that just makes sense. :)
Game flow
On launch:
- each player gets $1,000 in chips.
- set big blind = $10 (one hundredth of buy-in; this is the minimum bet during play), and small blind = $5 (half big blind).
- randomly choose who gets dealer button (i.e. who starts).
The Preflop:
- dealer pays small blind into pot; other pays big blind. The big blind counts as the initial bet for call/raise.
- assign each player two cards ("hole cards"), one at a time, starting with non-dealer. Each player only sees their own cards.
- betting round.
The Flop:
- Deal three community cards.
- betting round. (No initial bet, so first player can check/bet instead of call/raise.)
The Turn:
- Deal one community card.
- betting round. Minimum bet is now double big blind.
The River:
- Deal one community card.
- betting round (identical to turn).
The Showdown:
- each player shows their hand.
- Best hand wins the pot based on poker hand ranking. If both players have the same hand type, the player with the highest combined card value wins. If they have identical card values, they split the pot.
Post-hand:
- If player can't pay big blind, they lose.
- Else set dealer to whoever went second in the last hand, and go to preflop #1.
Betting rounds
In a betting round:
- each player chooses an action:
- "Fold": pay nothing further to the pot and forfeit hand; other player takes pot, start new hand.
- "Call" (or "Check" if no previous bet): match the last bet (i.e. increase total pot contribution to match last player's).
- "Raise" (or "Bet" if no previous bet): bet any amount between double last bet and total remaining chips.
- if player can't call/raise due to insufficient funds, they skip all actions until the end of the hand.
- repeat steps 1โ2 until both players have the same amount in the pot.
Running the game from source
- Compile the project into a
.jar
file. - Run the compiled file with
java -jar JPoker.jar
.
References
- Rules
- Texas Hold'em Rules and Game Play, PokerListings
- Hold'em Betting Rules: No-Limit, Limit, Pot-Limit, PokerListings
- Texas Hold'em, John McLeod
- Texas hold 'em, Wikipedia
- How To Play | Texas Holdem Rules, WSOP
- Texas Hold'em Poker Heads Up, IzzYgames
- ANSI/VT100 Terminal Control Escape Sequences