01 · Easy
Mostly random
Easy picks a random empty square. About half the time it first checks whether any square wins on the spot, and takes it if one does, so it can still pounce. It never blocks you.
Unit 10 · Class activity
Xinyue (Lily) FengTic-Tac-Toe
You are X. The AI is O. Choose how clever it is — from coin-flip to unbeatable — and switch on Show AI thinking to see how it scores every square.
Arrow keys move between squares. Enter or Space places your X.
Each number is the minimax score of moving there: how the game ends if both sides then play perfectly, counted from the AI’s side. A win is worth 10, minus one for every move it takes. minimax’s pick: the highest score on the AI’s turn, the lowest on yours.
All three opponents look at the same board. What changes is how far ahead they look before they move.
01 · Easy
Easy picks a random empty square. About half the time it first checks whether any square wins on the spot, and takes it if one does, so it can still pounce. It never blocks you.
02 · Medium
This is the rule-based AI from Lily’s Unit 10 “Play with AI” assignment, kept rule for rule as she wrote it. It runs down five rules in order: win if it can, block your winning move, take the center, take a random corner, take a side. It only ever looks one move ahead, so it can’t see a fork coming: start in a corner, answer its center with the opposite corner, then block the corner it takes. That block gives you two ways to win, and it can only stop one.
03 · Hard
Hard searches ahead to the end of the game with minimax, assuming you always find your best reply. Each finished game scores +10 for an AI win, −10 for a loss and 0 for a draw, one point closer to zero for every move it took, so quicker wins and slower losses rank higher. Alpha-beta pruning skips branches that can’t change its decision, so the search takes milliseconds. Perfect play from both sides is a draw, so against Hard the best you can do is draw.
With Show AI thinking on, every empty square shows the minimax score of the next move going there, from the AI’s side: positive means the AI can force a win, 0 a draw, negative a loss. On its turn the AI is the maximizer, and Hard always plays a top score while Easy and Medium may not. On your turn you are the minimizer: the lowest number is your best reply.