Blog: Unbeatable Tic Tac Toe Game -AI
Almost everyone knows a trick or two to win the tic tac toe game ,and sometimes one also falls for similar tricks . But there is always some move which can help you counter the opponents step into either winning the game or at least draw.
Here’s how I did it in Artificial Intelligence using the minimax algorithm.
First a little basics , suppose you draw a cross at a position in the grid , say remaining 8 grids are empty , now the opponent has 8 possible moves say the opponent marked a circle at some position now you have 7 choices , you will choose the one which will help you to win or draw the game but here’s something which we usually not consider , we might think that this move will help us to win but eventually in the subsequent moves it will be beneficial for the opponent , speaking technically we see only the next level of the tree after our move not the complete tree.
Minimax Algorithm is something which does the same it check for a specified depth in the tree and returns the best move for the player . I implemented the minimax algorithm with no restriction in the depth . The user interface is created using Python .
Click here to learn more about Minimax Algorithm .
Click here to view my project and play the game.