You are browsing as a guest. Sign up (or log in) to start making projects!

Tic Tac Toe

  • 5 Devlogs
  • 9 Total hours

A trained Tic Tac Toe agent that you can play against.

Ship #1

I built a tic-tac-toe game with an agent trained using Q-learning instead of just scripting the obvious optimal-move logic. It started as a plain random-move simulator in Python, then I built out the training loop (state encoding, epsilon-greedy move choice, reward updates after wins, losses, and draws) and trained it over 500,000 games. From there I moved the game into the browser, no backend, it just fetches the trained Q-table as JSON and picks moves with it client side. Added a turn indicator, a short delay before the agent moves, and a style pass so it holds up on any screen size, plus a small chance for the agent to play a random move so it's not fully predictable every game.

What I'm most proud of is that the agent actually plays well. It's not hardcoded to know the best tic-tac-toe strategy, it earned that by playing itself half a million times.

  • 5 devlogs
  • 9h
  • 7.78x multiplier
  • 73 Stardust
Try project → See source code →
Open comments for this post

2h 14m 43s logged

Made the agent a little less predictable and gave the site an actual style pass.
The agent now plays a random move 7.5% of the time instead of always going for its best known move, so games don’t play out the same way every time.
Then did the styling I mentioned wanting to do: added a “your turn / agent’s turn” indicator, a short pause before the agent’s move shows up on the board (with a click guard so you can’t sneak in an extra move during that pause), and reworked the colors and spacing on the board, the reset button, and the title.
Starting to feel like a real little site instead of just a board with squares.

0
0
3
Open comments for this post

2h 52m 16s logged

Moved the game into the browser.
Built a web version with HTML, CSS, and JS, it loads the trained Q-table straight from the JSON file and picks the agent’s move client side, no server needed. Click a cell to play as X, the agent answers as O.
Also retrained the table with a small tweak, new board states now start at -0.1 instead of 0, and wrapped the training code so importing train.py doesn’t kick off a training run by accident. The old CLI script is retired now that the browser version covers the same thing.
It works but looks plain right now, next up is actually styling it properly.

0
0
3
Open comments for this post

24m logged

You can now actually play against the trained agent, from the terminal.
Added a CLI script where a human plays against the agent, the agent picks its moves greedily off the Q-table instead of exploring. Cleaned up the board printing with separators so it’s easier to read between turns while playing.
Right now it’s just a command line game. A full UI is the plan for later.

0
0
1
Open comments for this post

29m 41s logged

Swapped the random-move players for actual Q-learning.
Instead of both sides just picking randomly, moves now come from an epsilon-greedy policy: mostly pick the best known move for the current board state, occasionally pick a random one to keep exploring. Added state encoding (board from the current player’s perspective, so X and O see it the same way), a Q-value table, and updates after every move based on the reward (win, loss, or draw).
Also added saving and loading the trained table to q_table.json so training runs don’t have to start from zero, train.py now loads it in on startup.
Next step is actually building a playable UI.

0
0
3
Open comments for this post

3h 22m 5s logged

Started a tic-tac-toe project with a random-move simulator.
Built the basic board logic first: a 9-cell board, printing it out, checking valid moves, and checking for a winner across all 8 win lines.
Then wired up two players who just pick random moves and play until someone wins or it’s a draw. Ran it for 10 games in a row and printed the result of each one.
Nothing fancy yet, just the scaffolding to build the real thing on top of.

0
0
1

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…