Hello! This is a simple console based TicTocToe game. You can play with Minimax Algorithm AI.
- Docker
To run this project using Docker, follow the steps below:
git clone https://github.com/Keizo410/TicTacToe_AI.git
cd tictactoe
docker build -t tictactoe .
docker run -it --rm tictactoe
Thanks to the simplicity and limited state space of this game nature, heuristics is simple enough to be calculated just based on either win or lose. If we won, +10. Tie means 0. Lose -10.
Lines 17 to 27 in 8c17966
This method is sometimes called decision function, which literally decides which action to be taken for AI player side.
Lines 29 to 55 in 1711fb4
There are several ways to implement minmax algorithm. Some people creates 2 different function min and max for simulating the state each other. For this implementation, I used isMaximizing parameter to identify which player's turn this is. Important: You have to adjust the decision, heuristics, recusive call parameters depend on which player is responsible for the FIRST move. If this was not properly implemented, AI player chooses self-destructive move. On this implementation, AI is assumed to be the first move player, which means isMaximizing should be set to be FALSE in the decision method above as we start simulating the second player's move.
Lines 57 to 95 in ab1003e
These state space search AI for game playing is heavily based on how the game is implemented. TicTacToe is fairly simple and fun to program for beginners like me:)