Medium⏱ time2 hr$ cost0
Tic-Tac-Toe AI
Program an unbeatable opponent that plans ahead using the minimax algorithm.
Start building ↓
Result first
The build
Step 01
Code the board
Represent the 3×3 game state.
Step 02
List moves
Generate all legal moves.
Step 03
Score with minimax
Recursively rate each move for both players.
Step 04
Play
The AI picks the best-scoring move.
Working Principle
Minimax looks ahead at every possible future board, assuming both players play their best, and chooses the move with the best worst-case result.
The science behind it
A closer look
It's adversarial search: the AI maximises its outcome while expecting the opponent to minimise it — the root of game AI.
Take it further
Variables to test
- 1 Add alpha-beta pruning — how much faster?
- 2 Try a 4×4 board — why does it slow down?
More AI
AI
Hand-Drawn Digit Classifier
Train a tiny neural network in the browser to recognise digits you draw with a mouse.
Medium⏱2 hr$0
AI
Rock-Paper-Scissors Vision
Use a webcam and a no-code model to recognise your hand and play rock-paper-scissors.
Easy⏱1 hr$0
AI
Spam Email Classifier
Train a model on example messages so it can flag new ones as spam or not.
Medium⏱2 hr$0