A Python-based Gomoku (Five in a Row) game with an MCTS-based AI. This project ALL done by ChatGPT o1, allowing you to play against an AI with selectable difficulty levels, switch languages on the fly, and experience additional features like undo, timers, and more. Support Windows, macOS, and Linux
You can download the pre-built Windows executable. Simply click the link below. Run the file to start the Gomoku game without setup.:
Download Gomoku for Windows (EXE)
My Inner Journey
This weekend, I decided to explore the limits of O1 by fully letting it lead a project. Over the course of 40 conversation rounds and about two hours, the result was a Gomoku program. It includes features like various AI difficulty levels supported by the Monte Carlo algorithm, multi-language support, cross-platform functionality, undo moves, timers, sound effects, and more. The entire interface and functionality were designed solely by O1 during our conversations. My role was simply to execute its instructions and provide feedback.
I watched as O1 planned, explored, debugged, and improved step by step. For instance, it initially used the minimax algorithm, but due to speed issues, it rewrote the logic with the Monte Carlo algorithm and multiprocessing. The interface and functionalities were incrementally enhanced and refined, with O1 simultaneously fixing its own bugs and seeking my feedback as user. It made mistakes but managed to detect and correct them. In some debugging conversations, I even sensed a kind of frustration from O1 over its errors. It also continually proposed new features for the program, and by the end, O1 was already discussing implementing online multiplayer. Unfortunately, my O1 usage was nearly exhausted, so I couldn’t let it continue.
Through this process, I felt as though I was collaborating with an experienced human developer, yet the efficiency was beyond human. A workload that might take a regular programmer about a week was completed in just over two hours. I have complex feelings about this. While O1 is still far from AGI, it is very close to replacing basic programmers. In the future, humans may only need to serve as leaders and product managers. The code has been uploaded to GitHub, and even the README, description, and packaging were completed by O1—I merely handled the uploads.
- Features
- Requirements
- Installation
- Usage
- Game Rules
- AI Difficulty
- Multi-language Support
- Undo and Timers
- Project Structure
- Contributing
- License
- Contact
-
MCTS-Based AI
Features a Monte Carlo Tree Search (MCTS) algorithm to determine the best move. Allows for different levels of difficulty. -
Multiple Difficulty Levels
Select from "Simple", "Medium", or "Hard" AI difficulty, each with different time limits and simulation counts. -
Multi-language Support
Built-in support for English (EN), Chinese (ZH), Spanish (ES), and French (FR). Switch languages in real-time from the UI. -
Graphical User Interface
Powered by Tkinter, providing an intuitive visual board with real-time updates. -
Timers and Undo
Each move (player or AI) is timed. You can also undo your moves (one undo action removes both the player's and AI's last moves). -
Configurable Player Turn
Choose whether to play first as Black or let the AI move first.
- Python 3.10
- Tkinter (usually included by default in most Python distributions)
No additional third-party GUI libraries are required; the standard library tkinter
is sufficient. However, the MCTS parallelization uses the multiprocessing
module, which is also part of the Python standard library.
-
Clone the Repository
git clone https://github.com/cooltesttry/Gomoku-O1.git cd Gomoku-O1
-
(Optional) Create a Virtual Environment
python -m venv venv source venv/bin/activate # On Linux/macOS # or venv\Scripts\activate # On Windows
-
Install the dependencies:
pip install -r requirements.txt
-
Run the Gomoku Game
python main.py
-
Select Language
- In the bottom-left corner of the main window, choose the language radio button (e.g., “中文”, “EN”, “ES”, “FR”).
- The interface text will update accordingly.
-
Select AI Difficulty
- In the bottom-right corner, click the “Difficulty” button to open a pop-up window.
- Choose Simple, Medium, or Hard.
- Confirm by clicking “OK”.
-
Start the Game
- Upon launching, a dialog box will ask if you want to move first (Black).
- Answer Yes to play Black first, or No to let the AI move first.
-
Making a Move
- Simply click on the board to place a stone on your turn.
- The AI will automatically take its turn afterwards.
-
Undo a Move
- Click the “Undo” button to reverse both your and the AI’s last moves.
- If no moves are available or the game has ended, you will see a message accordingly.
-
Restart the Game
- Use the “Restart” button at any time to reset the board and choose sides again.
- Board Size: 15x15 grid.
- Winning Condition: First player to place 5 consecutive stones in a row, column, or diagonal wins.
- Turns: Players alternate turns, placing one stone per turn.
- Undo Feature: Undoes the last move of each side (if the AI already moved).
This project uses Monte Carlo Tree Search (MCTS) under different simulation limits and time constraints for each difficulty:
Difficulty | Simulations | Time Limit (seconds) | Description |
---|---|---|---|
Simple | 500 | 2 | Faster but weaker AI. |
Medium | 1000 | 5 | Balanced level of AI thinking. |
Hard | 3000 | 12 | Deeper search, stronger AI. |
You can switch between English, Chinese, Spanish, and French at runtime. All UI text, including dialog messages, button labels, and status updates, will change immediately upon switching languages.
-
Undo:
- Each undo action removes the most recent moves of both the player and the AI (if the AI’s move occurred).
- Undo is disabled if no moves are made or if the game has ended.
-
Timers:
- Each turn (player or AI) has its own step timer in seconds.
- When the turn switches, the previous player's timer stops, and the next player's timer starts.
- Displays “Black Time” and “White Time” with the duration in seconds and milliseconds.
A possible structure (if the code is one file, you can list just that file):
.
├── main.py # Main entry point for the Gomoku game
├── README.md # Project documentation
└── LICENSE # Open-source license file
Key Components in main.py
:
-
Gomoku
class
Handles the main UI logic, board rendering, player interactions, timers, language switching, etc. -
mcts_search
function
Orchestrates the MCTS simulations to pick the best move for the AI. -
simulate
function
Handles the random playouts for each simulation, along with backpropagation. -
MCTSNode
class
Represents a single node in the MCTS tree, storing board state, children nodes, and visit/win counts.
py -m PyInstaller --onefile --noconsole --icon=gomoku.png --add-data "move_sound.mp3;." main.py
Contributions are welcome! If you’d like to help:
- Fork the repository and clone it locally.
- Create a new feature branch for your changes:
git checkout -b feature-YourFeatureName
- Make your changes or additions.
- Commit and push to your branch.
- Open a Pull Request describing your changes, and we’ll review it.
Please read our CONTRIBUTING.md (if available) for more details.
This project is licensed under the MIT License.
See the LICENSE file for details.
If you have any questions, suggestions, or feedback, feel free to open an issue
We hope you enjoy playing Gomoku with our AI and welcome any contributions you might make!