Tic-Tac-Toe: Minimax to DQN
ML JOURNEY / FULL WALKTHROUGH

Tic-Tac-Toe: Minimax to DQN

Build the game engine, minimax, tabular self-play, and a DQN agent, then compare value and policy learners.

6 parts92 individual lessons7.7 estimated hours460 XP available
Tic-Tac-Toe: Minimax to DQN project artwork
0%0 of 92 complete
Start walkthrough
No compressed chapters.

Every source step is its own lesson with intuition, concepts, correctly rendered MathJax mathematics, implementation, tests, mistakes, and a checkpoint.

01
PART 1

Board Representation & Game Engine

Encode the 3x3 board, implement move legality, win/draw detection, turn tracking, and wrap everything into a reusable Game class with hard-coded and interactive play.

0/18
001create empty board+5 XP002encode player+5 XP003print board+5 XP004is cell empty+5 XP005place move+5 XP006get legal moves+5 XP007check row win+5 XP008check column win+5 XP009check main diagonal win+5 XP010check anti diagonal win+5 XP011is winner+5 XP012is draw+5 XP013get game status+5 XP014get current player+5 XP015switch player+5 XP016play hardcoded game+5 XP017play interactive game+5 XP018TicTacToeGame+5 XP
02
PART 2

Random and Minimax Baselines

Implement a random-move agent, run head-to-head rollouts, then build a full minimax (with alpha-beta pruning) and verify optimal play against random and itself.

0/12
019random move agent+5 XP020play random vs random game+5 XP021play random vs random matches+5 XP022compute outcome rates+5 XP023minimax terminal score+5 XP024minimax value+5 XP025minimax recursive+5 XP026minimax max min step+5 XP027minimax best move+5 XP028minimax alpha beta+5 XP029play minimax vs random matches+5 XP030play minimax vs minimax matches+5 XP
03
PART 3

Tabular Q-Learning Foundations

Design state hashing with symmetry canonicalization, hyperparameters, epsilon-greedy action selection over legal moves, reward shaping, and the full Q-learning update and episode loop with learning curves.

0/24
031encode board state key+5 XP032canonical board key+5 XP033initialize q table+5 XP034get q value+5 XP035set q value+5 XP036choose learning rate alpha+5 XP037choose discount factor gamma+5 XP038choose initial epsilon+5 XP039epsilon decay schedule+5 XP040epsilon greedy explore move+5 XP041epsilon greedy select action+5 XP042greedy argmax over legal actions+5 XP043random tie break argmax+5 XP044tic tac toe reward+5 XP045q learning nonterminal target+5 XP046q learning terminal target+5 XP047q learning update+5 XP048episode reset game+5 XP049episode agent pick action+5 XP050episode apply action+5 XP051episode apply q update+5 XP052episode check terminate+5 XP053train q learning agent+5 XP054compute batched outcome stats+5 XP
04
PART 4

Self-Play, Evaluation & Persistence

Train the Q-agent through self-play with perspective flipping, evaluate against random and minimax opponents, support human-vs-agent play, and save/load the Q-table.

0/9
055self play episode+5 XP056flip board perspective+5 XP057perspective reward sign+5 XP058train q agent self play+5 XP059evaluate q agent vs random+5 XP060evaluate q agent vs minimax+5 XP061inspect q values for state+5 XP062serialize q table to dict+5 XP063deserialize q table from dict+5 XP
05
PART 5

Deep Q-Network Agent

Move from a table to a neural function approximator: encode the board for an MLP, mask illegal actions, build a replay buffer and target network, train DQN end-to-end, and compare against earlier agents.

0/21
064encode board flat length nine+5 XP065encode board one hot length eighteen+5 XP066build mlp architecture+5 XP067initialize mlp parameters+5 XP068mlp forward pass+5 XP069mask illegal actions neg inf+5 XP070argmax action from q values+5 XP071mse loss on chosen action+5 XP072mlp backward pass+5 XP073adam update step+5 XP074create replay buffer+5 XP075append transition to buffer+5 XP076cap buffer size drop oldest+5 XP077sample minibatch from buffer+5 XP078build target network copy+5 XP079compute target q with target network+5 XP080sync target network periodically+5 XP081dqn select action+5 XP082dqn train step+5 XP083train dqn agent+5 XP084compare dqn tabular random minimax+5 XP