Tic-tac-toe vs AI
Play tic-tac-toe on a real board: click a square (or press keys 1-9), three in a row wins at once and a full board without a line is a draw. The computer runs a full minimax search, preferring the centre and corners among equal moves and breaking the rest with the seed, so it answers identically for the same position and can never be beaten; two-player mode is available as well.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Tic-tac-toe board
Click an empty square; click the board once to use the keyboard, and keys 1-9 place a stone directly.
- X stones
- 0
- O stones
- 0
- Empty
- 9
- Moves
- 0
- Winning line
- -
- Winner
- -
Arrow keys / W A S D move the cursor, Enter places a stone, keys 1-9 place directly
Move log
0 move(s) in total
No move recorded yet
What this tool does
- Play a few quick games: the default is human versus computer (the computer plays O) and it answers with a full minimax search.
- Verify that the game is a draw against perfect play: you cannot beat the computer, and the status line reports the real result.
- Play a friend: switch to two-player mode and alternate on the same board, with the three-in-a-row check done by the real rules.
Example
Input
Opponent = computer plays O (seed demo); X clicks the top-left square (1,1)
Output
Move 1 · You (X) played 1,1 Move 2 · The computer (O) played 2,2 (minimax score 0) Status: Move 2 · X to move
Among equally optimal moves the seed plus a “centre > corners > edges” preference decides, so the same position with the same seed always answers the same.
Frequently asked questions
How do I place a stone?
Click any empty square; you can also click the board to focus it, move the cursor with the arrow keys / W A S D and press Enter, or press keys 1-9 directly (left to right, top to bottom). A taken square only tells you to pick another — it never overwrites a stone.
Can the computer really not lose?
Correct. It runs a full minimax search, which on a 3x3 board reaches the end of the game, so every move is optimal and the best you can get is a draw. Among equally optimal moves it prefers the centre, then corners, then edges, and only then falls back to the seed.
How is the result decided?
Three in a row in any row, column or diagonal wins immediately (the winning line is highlighted); a full board without a line is a draw. Both outcomes come from a real line search rather than a guess.
Is there a computer in two-player mode?
No. In two-player mode both X and O are placed by people, the computer never replies and no “computer” wording appears; “Undo move” returns to the previous position in both modes.
Keywords:tic tac toeminimax