Skip to content
Spectrum · BASIC · Game 13BASIC● 6 of 6 units live

Three in a Row

Noughts and Crosses against the computer — a board held in an array, win detection from a DATA table of lines, and an opponent that blocks, wins, and plays strategy.

ZX Spectrum Three in a Row: a graphical 3x3 grid with cyan X crosses and red O noughts mid-game against the computer
What you will build: Noughts and Crosses against a computer that blocks, attacks, and plays strategy.

Three in a Row is Noughts and Crosses on the Spectrum — and you are playing against the machine. The computer is your opponent, and the heart of this game is teaching it to play well.

In Volume 2 — Patterns of State, this is the first game where the program is your adversary. Every game so far has reacted to the player; this one decides. It reads the board, weighs its options, and chooses a move — the first taste of game AI.

The board you can build from what you know: a nine-cell array drawn as a grid, the way Sonar drew its 8×8. The two new ideas are how the computer reads the board and how it plays it. Reading comes from a DATA table of the eight winning lines — DATA you used as a list in Cipher, here used as a lookup table — scanned by a reusable GO SUB check. Playing comes from a priority of rules: take a winning move, else block yours, else seize the centre or a corner. That ladder of rules is the AI.

What you will build:

  • A nine-cell board in an array, drawn as a 3×3 grid (familiar ground)
  • The player’s move — pick 1–9, with a guard against taken cells
  • Win detection from a DATA table of the eight winning lines (the new idea)
  • An opponent that wins when it can and blocks when it must (the new idea)
  • Strategy — preferring the centre and corners, playing the game to a draw
  • The finished game: title, win/lose/draw screens, a running score, and replay

6 units. About 7–10 hours. This builds on Meet BASIC and Volume 1 — earlier games assumed.

Unit roadmap

Phase 1

The board

A nine-cell array drawn as a 3x3 grid, with the player placing crosses

Units 1–2Complete
Phase 2

Reading the board

A DATA table of winning lines, scanned to detect a three-in-a-row

Units 3–3Complete
Phase 3

The opponent

A computer that wins, blocks and plays strategy, then the finished game

Units 4–6Complete