Building an Unbeatable Tic-Tac-Toe AI with the Minimax Algorithm
I wanted to build something using AI. And it uses AI. I was thinking, what is the best thing to make? And it came to my mind: a game that everyone knows and plays and is easy to play. Tic-tac-toe.
But training an AI to play tic-tac-toe will take time. So it hit me: why not use minimax?
What is minimax?
The minimax algorithm is a decision-making algorithm that is basically used in two-player games like chess or tic-tac-toe.
- The AI lists every legal move it can make.
- For each move, it imagines the opponent's best possible response.
Not just that:
- It assumes the opponent always makes the best move.
- It evaluates every possible continuation before choosing.
But why choose tic-tac-toe?
Tic-tac-toe is small enough that it can be searched completely, while other games like chess need more because they have many more possibilities.
But the idea is not to...
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE