An implementation of a single player 3D Tic Tac Toe game using the pygame library
In this project , we made an AI for the 3D Implementation of Tic-Tac- Toe (4x4x4) using the minimax algorithm. Due to the high computation required to calculate all possible outcomes we limit the lookahead to 2 moves.
This effectively breaks down the minimax implementation to a directwin achiever or blocker. To improve the performance of the AI , we added a if-else if sequence to choose moves which are more likely to lead to a win condition , this effectively simulates a heuristic in which the more preferred moves would return a higher score.
It is good to note that on implementing the same AI without the heuristic but with a lookahead of 3 or 4 we have about the same or deteriorated performance in terms of speed and deteriorated or about the same performance in terms of outperforming the player respectively when compared with the implementation mentioned in the previous paragraphs
The main file , contains UI implemented in pygame. It calls the Movebest() function when it ts the AI's turn to play Contains the implementation of Movebest() and minimax() functions , where the Movebest function uses the minimax function and the if-else if sequence to change the board state according to the optimal move for the AI Contains the isComplete() function used to check for win condition and the hasSpace() function to check for draw condition(Board is full) Contains the init_board() function used to initialize the 4x4x4 board with all states set to empty Contains ProgressBar class used while debugging and testing Contains functions for debugging to check board state from different views ⦁ Python 3 ⦁ Pygame ⦁ PipTo run and play against the AI , move all the files into one directory and after opening a command terminal in that directory , use the command:
python main.py
It is important to note that the execution requires python and pygame installed on the system in the current environment The game will play out like a regular tic tac toe game , alternating between player(X) and AI(O) , the Player can click on the square they wish to play their move on.
