Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect Four AI

An AlphaZero implementation for playing Connect Four with a web interface.

Connect Four AI

Installation

  1. Clone the repository:
git clone https://github.com/PaulTbbr/connect_4.git
cd connect_4
  1. Install dependencies:
pip install -r requirements.txt

Training

To train AlphaZero on connect 4:

python -m src.main train --game connect_four --n_blocks 9 --n_filters 128 --lr 0.001 --weight_decay 0.0001 --c 2 --n_searches 600 --n_iterations 8 --n_self_play_iterations 500 --n_epochs 4 --batch_size 128 --temperature 1.25 --dirichlet_epsilon 0.25 --dirichlet_alpha 0.3 --checkpoints_dir checkpoints/ 

For faster training with parallel self-play, add the flag --parallel.

Key Parameters:

  • --n_parallel_games: Number of concurrent self-play games (typically 50-200)
  • --n_self_play_iterations: Total games per iteration (should be multiple of n_parallel_games)
  • --batch_size: Mini-batch size for NN training
  • --c: Exploration constant (higher = more exploration)
  • --temperature: Controls policy randomness (1.0 = proportional to visit count)

Playing

Run the web application with:

python -m webapp.app

The game is hosted at http://localhost:5000.

Game Modes

  • Human vs Human: Two-player mode
  • Human vs MCTS: Play against Monte Carlo Tree Search
  • Human vs Alpha-MCTS: Play against an AlphaZero-trained model

Credits

Based on the AlphaZero implementation from:

About

AlphaZero implementation for playing connect 4.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages