This is a Texas Hold'em Poker AI project that implements various AI strategies for playing poker. The project includes a complete game engine, multiple AI player implementations, and an evaluation system.
final_project-1/
├── agents/ # AI player implementations
│ ├── expectation_player.py # Expected value calculation strategy
│ ├── MCT_player.py # Monte Carlo Tree Search strategy
│ ├── Info_player*.py # Information theory strategies (multiple versions)
│ ├── hand_strength.py # Hand strength calculation utilities
│ ├── random_player.py # Random strategy (for testing)
│ ├── call_player.py # Call strategy (for testing)
│ └── ...
├── game/ # Game engine
│ ├── game.py # Main game program
│ ├── players.py # Base player class
│ └── engine/ # Core game engine modules
├── start_game.py # Quick start game script
├── evaluation.py # Evaluation script
├── final_evaluation.py # Final evaluation script
└── requirement.txt # Dependency list
-
ExpectationPlayer (
agents/expectation_player.py)- Decision strategy based on expected value calculations
- Uses hand win rate estimation to calculate expected values for different actions
- Considers pot size, bet amounts, and other factors
-
MCTPlayer (
agents/MCT_player.py)- Monte Carlo Tree Search (MCTS) strategy
- Evaluates optimal actions through simulation
-
InfoPlayer Series (
agents/Info_player*.py)- Information theory-based strategies
- Multiple improved versions (Info_player, Info_player2, Info_player2_5, Info_player3)
-
Other Strategies
just_win_player.py: Only bets when win rate is sufficiently highOne_Shot.py: One-shot decision strategybaseline_agent.py: Baseline strategy
- Complete Texas Hold'em rules implementation
- Multi-player support
- Complete game state management
- Hand evaluation system
- Python 3.8+
- Required Python packages (see
requirement.txt)
- Clone or download the project:
cd final_project-1- Install dependencies:
pip install -r requirement.txtRun start_game.py to play a game:
python start_game.pyYou can modify player configuration in start_game.py:
config = setup_config(max_round=20, initial_stack=1000, small_blind_amount=5)
config.register_player(name="p1", algorithm=baseline7_ai())
config.register_player(name="p2_INFO3", algorithm=info3_ai())Run the evaluation script to test different AI performances:
python evaluation.pyOr use the final evaluation script:
python final_evaluation.pyTo implement your own AI player, you need to inherit from the BasePokerPlayer class and implement the following methods:
from game.players import BasePokerPlayer
class MyPlayer(BasePokerPlayer):
def declare_action(self, valid_actions, hole_card, round_state):
# Implement decision logic
# Return (action, amount)
# action: 'fold', 'call', 'raise'
pass
def receive_game_start_message(self, game_info):
# Receive game start message
pass
def receive_round_start_message(self, round_count, hole_card, seats):
# Receive round start message
pass
def receive_street_start_message(self, street, round_state):
# Receive street start message (preflop, flop, turn, river)
pass
def receive_game_update_message(self, new_action, round_state):
# Receive game update message (other players' actions)
pass
def receive_round_result_message(self, winners, hand_info, round_state):
# Receive round result message
pass
def setup_ai():
return MyPlayer()For detailed message format specifications, please refer to data_flow.md.
Provides hand strength calculation functionality:
win_rate(hole_card, community_cards, simulations=2000): Calculate hand win rateclassify_hand(cards): Classify hand type (straight flush, four of a kind, full house, etc.)compare_hands_wrapper(my_hole, opp_hole, community): Compare two hands
Main game program:
setup_config(): Configure game settingsstart_poker(): Start the game
Defines the BasePokerPlayer base class that all AI players need to inherit from.
- Game Type: Texas Hold'em
- Default Settings:
- Max rounds: 20
- Initial stack: 1000
- Small blind: 5
- Big blind: 10
These parameters can be adjusted in setup_config().
The evaluation script calculates the following metrics:
- Win Rate: Win rate against different baseline AIs
- Stack Change: Chip difference at the end of the game
- Tie Rate: Proportion of ties
start_game.py: Quick start for a single gameevaluation.py: Batch evaluation of different AI performancesfinal_evaluation.py: Final evaluation script (includes more detailed statistics)confidence_interval.py: Calculate confidence intervalsdata_flow.md: Detailed message format specification document
- Some baseline players are compiled
.sofiles (baseline0-7), ensure these files are in the correct location - AI decisions have a time limit (50 seconds), exceeding the limit will automatically fold
- Hand strength calculation uses Monte Carlo simulation, the number of simulations can be adjusted
Please refer to the LICENSE.md file.
Project ID: b10202064
- Texas Hold'em rules
- Monte Carlo Tree Search algorithm
- Information theory applications in game AI