- Introduction
- Features
- Architecture Overview
- Backend Components
- Frontend Components
- Game Flow
- How to Run the Project
- Future Improvements
This project is a real-time multiplayer Texas Hold'em poker game built with a Spring Boot backend and a vanilla HTML/CSS/JavaScript frontend. It supports multiple players joining a shared table, making decisions (fold, call, raise), and competing for the pot using standard poker rules.
The game implements:
- Real-time updates using WebSockets.
- A robust poker hand evaluation algorithm.
- An interactive frontend showing player positions, actions, cards, and the game state.
- Real-Time Gameplay: All players see updates immediately (community cards, player turns, pot size).
- Hand Evaluation: The backend determines the winning hand using Texas Hold'em rules.
- User-Friendly Interface: A clean, responsive table design showing each player's name, stack, and actions.
- Dynamic Game Flow: Automatically progresses through betting rounds and deals the community cards.
- Turn-Based Actions: Players act one at a time, ensuring fairness.
The backend is built using Java (Spring Boot) and is responsible for:
- Managing the game state (players, bets, cards, turns).
- Broadcasting real-time updates via WebSockets.
- Evaluating hands using a hand evaluator.
The frontend is a vanilla HTML/CSS/JavaScript web client that:
- Displays the poker table, community cards, and player actions.
- Sends player actions (fold, call, raise) to the backend.
- Updates the UI in real time based on WebSocket messages.
The GameService class handles the core game logic:
- Player Management:
- Adds players when they join the game.
- Tracks their chip stacks, hole cards, and actions.
- Betting Rounds:
- Handles pre-flop, flop, turn, and river betting rounds.
- Ensures all players match the highest bet before moving to the next round.
- Game Progression:
- Deals cards (hole cards and community cards).
- Broadcasts updates (e.g., "new community card dealt").
- Ends the game by evaluating hands and distributing the pot.
The TexasHoldemHandEvaluator is responsible for:
- Generating All Possible Hands:
- From a player's hole cards and the community cards, generate all 5-card combinations.
- Ranking Hands:
- Determines the best hand based on standard poker categories (Royal Flush, Straight, Pair, etc.).
- Tie-Breakers:
- Uses tiebreaker logic (e.g., highest pair, kicker) to determine the winner.
Hand categories:
- Royal Flush
- Straight Flush
- Four of a Kind
- Full House
- Flush
- Straight
- Three of a Kind
- Two Pair
- One Pair
- High Card
- The backend uses Spring WebSocket to send real-time updates to all clients.
- Endpoints:
/topic/game-state: Broadcasts the current game state to all players./app/action: Receives player actions (fold, call, raise) and processes them.
- The main page has a poker table layout:
- Six player seats positioned around the table.
- Community cards displayed in the center.
- A pot information area showing the total chips.
- Each seat shows:
- Player's nickname.
- Chip stack.
- Hole cards (only visible to the current player).
- Handles all UI updates and WebSocket communication:
- Connecting to the Game:
- Players enter their nickname and join the table.
- Real-Time Updates:
- Receives messages from
/topic/game-stateand updates the table.
- Receives messages from
- Player Actions:
- Sends actions (fold, call, raise) to the backend via
/app/action.
- Sends actions (fold, call, raise) to the backend via
- Connecting to the Game:
- Keeps track of:
- Which player is sitting in which seat.
- The current turn (highlighted seat).
- The cards on the table (hole cards and community cards).
- The pot size.
The game follows the standard Texas Hold'em flow:
-
Joining the Game:
- Players enter their nickname and are seated at the table.
- The game starts when there are at least 2 players.
-
Pre-Flop:
- Each player is dealt 2 hole cards.
- Players take turns acting (fold, call, raise).
-
Flop:
- The first 3 community cards are dealt.
- Another round of betting occurs.
-
Turn:
- The 4th community card is dealt.
- Another round of betting occurs.
-
River:
- The 5th and final community card is dealt.
- The last betting round occurs.
-
Showdown:
- The backend evaluates all remaining players' hands and determines the winner.
- Chips are distributed, and a new game can begin.
- Install Java 17+.
- Install Maven.
- Install Node.js (for serving static files if needed).
- Clone the repository:
git clone https://github.com/your-repo/texas-holdem-poker.git cd texas-holdem-poker - Build and run the backend:
mvn spring-boot:run
The backend will start at http://localhost:8080.
- Open index.html in a browser to access the game.
- Open the game in multiple browser tabs to simulate multiple players.
Future Improvements
- Side Pots: Implement side pot logic for all-in scenarios.
- Authentication: Add user authentication to prevent duplicate nicknames.
- Better UI: Use a framework like React or Vue.js for a more dynamic frontend.
- Mobile Support: Optimize the UI for smaller screens.
- Spectator Mode: Allow players to watch the game without participating.
Conclusion
This Texas Hold’em Poker project demonstrates:
- Real-time multiplayer interaction.
- Complex backend logic for game state management and hand evaluation.
- A clean and intuitive frontend interface.
With additional features like side pots and authentication, this project could become a fully-fledged online poker platform.