husus / gomokuAI-py

Implementation in python of a Gomoku AI from scratch based on MiniMax and Alpha-Beta Pruning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gomoku AI in Python

A simple Gomoku (or also called Five-In-A-Row) AI implemented in Python from scratch.

๐Ÿ”Ž Overview

Gomoku is a strategy board game with 2 players and on a 15x15 board. The objective of the game is to form an unbroken chain of 5 stones (vertically, horizontally, diagonally) and the first player to do that wins the game. In this project, you can play against the AI that uses the MiniMax algorithm with alpha beta prunning in order to make the next move. Everything is integrated with a GUI made through pygame.

๐Ÿ“Œ Requirement

In order to run this program, the pygame library must be installed first:

> pip install pygame

๐Ÿ“‚ Files Structure

โ”œโ”€โ”€ assets
โ”‚   โ””โ”€โ”€ black_piece.png
โ”‚   โ””โ”€โ”€ board.jpg
โ”‚   โ””โ”€โ”€ button.png
โ”‚   โ””โ”€โ”€ menu_board.png
โ”‚   โ””โ”€โ”€ white_piece.png
โ”œโ”€โ”€ gui
โ”‚   โ””โ”€โ”€ button.py
โ”‚   โ””โ”€โ”€ interface.py
โ”œโ”€โ”€ source
โ”‚   โ””โ”€โ”€ AI.py
โ”‚   โ””โ”€โ”€ gomoku.py
โ”‚   โ””โ”€โ”€ utils.py
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ play.py

๐ŸŽฎ The Game: Execution

For playing against the AI, run the following commands:

> git clone https://github.com/husus/gomokuAI-py
> cd gomokuAI-py
> python3 play.py

The image below is the starting screen of the game interface that would appear after the above-mentioned commands have been run correctly. The player can choose between black or white, and the other color will be assigned to the AI. Remember that according to the Gomoku rules, black always starts first.
start_screen

To make the moves, it is necessary to simply click on the empty intersections of the board and one stone will be placed. The game keeps going by alternating turns between the human player and the AI until one of the two wins by forming an unbroken chain of five stones of the same color. Once the game ends, the following screen will pop out and the player can choose whether to restart the game or not. By selecting no, the pygame window will be closed automatically.
end_screen




Disclaimer

This repository is part of the submission of the final project for the MSc course 20602 - COMPUTER SCIENCE (ALGORITHMS) at Bocconi University.

About

Implementation in python of a Gomoku AI from scratch based on MiniMax and Alpha-Beta Pruning

License:MIT License


Languages

Language:Python 100.0%