Skip to content

♟♟♟♟♟ A Gomoku game AI based on Monte Carlo Tree Search, can be trained on policy-value network now. 一个蒙特卡洛树搜索算法实现的五子棋 AI,现可用神经网络训练模型。

License

Notifications You must be signed in to change notification settings

cloxnu/Omega_Gomoku_AI

Repository files navigation

Starkidstory

Header

Omega_Gomoku_AI

Omega_Gomoku_AI is a Gomoku game AI based on Monte Carlo Tree Search. It's written in Python. The neural network part uses the Keras framework.


Omega_Gomoku_AI is not only used for Gomoku game, but you can also customize the size of the board and an n-in-a-row game. Tic-tac-toe, for example, is a 3-in-a-row game, and played on a board of size 3.

This repo provides a visual game interface, easy-to-use training process, and easy-to-understand code.

Enjoy yourself ~~~

💥 Available now 💥

web

Run visual game using web server is available now!

1.3 is available, visual game etc. were added.

👣 Next step

✅ Monte Carlo tree -> ✅ Train models -> ✅ Visual game interface -> Custom battle.

📖 References & thanks

About the algorithm, Omega_Gomoku_AI refers to this article: Monte Carlo Tree Search – beginners guide, written by int8.

Omega_Gomoku_AI Inspired by AlphaZero_Gomoku and tictactoe_mcts.

🏠 Code structure

Usage

You can try Omega_Gomoku_AI yourself, and there are two ways to try it.

via Docker

If you have installed Docker, run the following command:

$ docker pull clox/omega_gomoku_ai:latest

Then, just run this:

$ docker run -it clox/omega_gomoku_ai:latest

Add --rm after -it can automatically remove the container when it exits.

That's all, the above is the simplest usage, It's a really simple way!

If you want to render the visual game using web server in Docker, remember to enable port mapping:

$ docker run -it -p 5000:5000 clox/omega_gomoku_ai:latest

In addition to mapping to port 5000, you can also change '5000' before the colon to other values.

It is worth noting that if you want to save the training data on your own machine, you need to add -v to mount directory.

$ docker run -it -v [Path]:/home/Model clox/omega_gomoku_ai:latest

[Path] here should fill in the local model path you want to save or load. Remember, cannot use relative directory here.

That's all, It's a really simple way!

PS:

Example of running the simplest version with Docker

Configuring...

config

Running...

running

via PC/Mac/Linux

Make sure you have a Keras backend (Tensorflow) environment installed on your computer, and after cloning this repo, then run the following command:

$ pip install -r requirements.txt

If necessary, the command 'pip' should be changed to 'pip3'.

In Mac/Linux, just run:

$ bash game.sh

is enough, execute the file game.sh in PC.

Or, you can also run:

$ python configure.py

to configure the game, and run:

$ python start.py

to start the game.

$ python train.py

to train a model.

$ python start_from_web.py

to start the visual game using web server.

Either installation way is fairly simple.

About the parameters of 'train.py'

If you want to train on some cloud platforms, etc. that need to be quick and convenient and do not allow user input, you may need to run train.py with parameters:

$ python train.py 1 my_model 1000

The first parameter '1' means use the '1st' neural network, it must be the serial number of the neural network.

The second parameter 'my_model' means training the model named 'my_model'. If there is, it will automatically train the 'latest.h5' record. If there is no, it will automatically create it.

The third parameter '1000' indicates that the number of self-play is '1000'. If it is less than or equal to 0, it is infinite. It must be an integer.

Enjoy...

By default, this is a 5-in-a-row game played on an 8 * 8 size of board, and AI with pure MCTS searches 2,000 times each turn.

AI thinking

AI_moves

Sometimes, AI with pure MCTS may do weird action, because 2,000 times searching is not enough in a 5-in-a-row game in fact. So you can adjust the board size to 3 * 3 or 6 * 6, set to a 3-in-a-row or 4-in-a-row game, like tac-tic-toe.

Sure, It's a good idea to adjust 2,000 times to more, but it will take more time to think.

Now, we open the choice of greedy value, you can adjust the exploration degree of Monte Carlo tree search by yourself.

10000_times

For example, I adjusted the number of Monte Carlo tree searches to 10,000 and played a 4-in-a-row game on a 6 * 6 board. It can be seen in the AI analysis that the Monte Carlo tree has traversed almost all of the board.

Will, AI with MCTS + neural network can solve this problem.

Training is available now.

training

Enjoy on the web

After opening the web server to run the game, open your browser and enter http://127.0.0.1:5000 or http://0.0.0.0:5000 to enjoy the game.

Chrome and Safari passed the support test.

License

Omega_Gomoku_AI is licensed under MIT license. See LICENSE for details.

To be continued...

About

♟♟♟♟♟ A Gomoku game AI based on Monte Carlo Tree Search, can be trained on policy-value network now. 一个蒙特卡洛树搜索算法实现的五子棋 AI,现可用神经网络训练模型。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published