Zing Forum

Reading

Evolving Poker AI: Playing Texas Hold'em with Genetic Algorithms and Neural Networks

A pure Java implementation of a Texas Hold'em AI project that combines Monte Carlo hand strength precomputation, genetic algorithm evolution, and a hand-built feedforward neural network to enable robots to autonomously learn poker strategies in simulated games.

遗传算法神经网络德州扑克神经进化蒙特卡洛Java不完全信息博弈机器学习
Published 2026-06-01 07:43Recent activity 2026-06-01 07:49Estimated read 6 min
Evolving Poker AI: Playing Texas Hold'em with Genetic Algorithms and Neural Networks
1

Section 01

Introduction: Core Overview of the Pure Java Evolving Poker AI Project

This project is a pure Java implementation of a Texas Hold'em AI that combines Monte Carlo hand strength precomputation, genetic algorithm evolution, and a hand-built feedforward neural network to enable robots to autonomously learn poker strategies through simulated games. The project aims to study the evolutionary improvement of decision systems in uncertain environments, and its value extends beyond poker AI—it serves as a complete example of neuroevolution principles.

2

Section 02

Background: Why Choose Poker to Test AI Decision-Making Capabilities?

Poker is an imperfect information game where players must make decisions without knowing their opponents' hands, unlike the perfect information environments of chess or Go. Texas Hold'em requires players to estimate hand strength with limited data, respond to bets, manage chips, etc. This combination of uncertainty, probabilistic outcomes, and long-term strategy makes it an ideal scenario for testing neuroevolution.

3

Section 03

Core Project Architecture: Three-Stage Evolutionary Learning Loop

The system is divided into three stages: 1. Hand Strength Precomputation: Generate pre-flop/post-flop win rate tables using Monte Carlo simulations (5000 simulations per scenario); 2. Game Simulation: Implement complete poker rules via GameEngineSimulator, with robots using neural networks to make decisions; 3. Population Evolution: BotSelector manages the genetic algorithm process (evaluation → selection → elitism → mutation → crossover), and the fitness function rewards chip growth and balanced play.

4

Section 04

Neural Network Implementation: Hand-Built Java Feedforward Network

The network uses no external ML frameworks; its architecture is input layer (9 features) → hidden layer 1 (16 ReLU nodes) → hidden layer 2 (8 ReLU nodes) → output layer (3 action logits + 1 raise neuron). Input features include 9 items such as chip ratio and hand strength; outputs are fold/call/raise (raise amount is determined by a dedicated neuron). Training does not use backpropagation; instead, weights are adjusted via genetic algorithms.

5

Section 05

Code Structure and Key File Analysis

Code structure: The main module includes HandStrengthGenerator (Monte Carlo precomputation) and BotSelector (genetic algorithm loop); under BotSelector are PokerBot (agent + fitness), GameEngineSimulator (rule engine), etc. Key files like main.java (entry point), HandStrengthGenerator.java (hand strength tables), NeuralNetwork.java (hand-built network), etc., each have clear roles.

6

Section 06

Running Method and Observation of Evolutionary Results

Running commands: javac *.java → java main. Default parameters: 1000 generations, 500 robot population, big blind 6, etc. The precomputation stage takes a few minutes to generate hand strength tables. Observed patterns: Strategy convergence (robots adopt balanced strategies in later stages), balanced play is encouraged, evolved robots are more challenging. Top robot weights are stored in best_bot_weights.txt.

7

Section 07

Project Limitations and Future Improvement Directions

Current limitations: Performance tested only in a custom simulator; hand strength based on Monte Carlo approximation; no backpropagation/reinforcement learning/opponent memory; fitness function affects behavior; lack of comparison with fixed baseline strategies. Future optimizations can target these aspects.

8

Section 08

Project Summary: A Complete Example of Neuroevolution Learning

This project demonstrates the process of building a neuroevolution system from scratch without relying on external ML libraries, using genetic algorithms and neural networks to enable AI to autonomously learn poker strategies. It is an excellent learning resource for developers seeking to understand neuroevolution principles or implement neural networks in pure Java, and its complete workflow (precomputation → simulation → evolution) has broad reference value.