Tic Tac Toe AI

How I built the game and its AI levels.

About the project

This is a browser-based Tic-Tac-Toe game made with HTML, CSS and JavaScript.

I built the AI myself instead of using an external AI service. The project started with a simple random bot and gradually became more advanced.

There are four difficulty levels: Easy, Medium, Hard and Impossible.

How to play

You play as X and the AI plays as O.

Click an empty square to make your move. The AI will then make its move. Get three of your symbols in a row to win.

AI levels

01

Easy

The bot picks an available square randomly. It doesn't really try to beat you.

02

Medium

The bot checks for winning moves and blocks the player when necessary. It also prefers the center and corners.

03

Hard

This level uses the Minimax algorithm. The bot looks ahead at possible moves before deciding.

04

Impossible

This is the strongest bot in the game. It uses reinforcement learning to learn which moves are better from different board states.