Tic Tac Toe - Creating Unbeatable AI

Introduction to Minimax Algorithm

Greg Surma
6 min readNov 12, 2018

In today’s article, I am going to show you how to create an unbeatable AI agent that plays the classic Tic Tac Toe game. You will learn the concept of the Minimax algorithm that is widely and successfully used across the fields like Artificial Intelligence, Economics, Game Theory, Statistics or even Philosophy.

AI X vs Human O

Table of Contents

Before we go into the AI part, let’s make sure that we understand the game.

About Tic Tac Toe

Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game.

I recommend you to play the game yourself, feel free to check out my iOS Tic Tac Toe app.

--

--