Skip to content
Keras zero knowledge AI for gomoku and tic-tac-toe
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
ai_gomoku.py
eval_boards.txt
gomoku_6_5.h5
gomoku_8_5.h5

README.md

Keras zero knowledge AI for gomoku and tic-tac-toe

Blogpost for the algorithm: http://blog.teamleadnet.com/2018/07/zero-knowledge-ai-for-tic-tac-toe-and.html

Prerequisites

Keras with a valid backend (eg, tensorflow)

pip install tensorflow
pip install keras

To install optimised Tensorflow backend, go to https://github.com/lakshayg/tensorflow-build

Training

The system will start playing randomly against itself with the predefined parameters.

For board size 6x6 with 5 in a row for winning, stopping after random only wins 2% of the games

./ai_gomoku.py train --boardsize 6 --winsize 5 --stopon 2 --decay 0 --lr 0.001 --layer1size 128 --layer2size 128 --epochs 2 --randomuntil 0 --updatebatchsize 10000

Training time ~5 hours without GPU.

To watch the progress, start

tensorboard --logdir=logs/

and head to http://localhost:6006

Playing agianst the model

The player starts with X. Input the moves in the format of X, Y where X is the row, Y is the column, starting from zero.

./ai_gomoku.py play --boardsize 6 --winsize 5 --filename gomoku_6_5.h5 

Eg,

|      |
|      |
|      |
|      |
|      |
|      |
Your move? (x, y) 3,3
|      |
|      |
|   0  |
|   X  |
|      |
|      |
...

Evaluating boards

Copy-paste boards to STDIN to evaluate it's score based on a model. Boards are separated with two empty lines. End with a CMD+D.

Sample boards are provided in eval_boards.txt

To indicate empty rows add a single space in that line.

./ai_gomoku.py eval --boardsize 6 --winsize 5 --filename gomoku_6_5.h5 
You can’t perform that action at this time.