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

Sonar

A grid search game — find hidden targets using distance clues. Two-dimensional arrays, coordinates, and systematic thinking.

ZX Spectrum Sonar: a cyan 8x8 grid with a SONAR title bar and a Found/Guesses status line, ready for coordinate probing
What you will build: a sonar grid where you hunt three hidden targets by distance clues.

Sonar is Battleship with a twist. Three targets hide on an 8x8 grid. You call coordinates. A hit marks the cell with a star. A miss shows a number — the distance to the nearest target. The closer the number, the warmer you are.

This is the fourth game in Volume 2 — Patterns of State — and the first grid game. So far your state has been a single value or a one-dimensional list; here it lives in a two-dimensional array, rows and columns like a chessboard, and the player thinks in coordinates.

DIM you know (Quiz Master); ABS you know (Lucky Number). Sonar's new ideas are the second dimensionDIM g(8,8), addressed by g(row, col) — and the distance clue: a nested sweep of the whole grid that finds the nearest target with Manhattan distance. The 2D array is the state, and scanning it is the move.

What you will build:

  • An 8×8 grid held in a two-dimensional array, with three hidden targets (the new idea)
  • Probing by coordinate, and hit detection
  • The distance clue — a nested sweep finding the nearest target with ABS (the new idea)
  • Warmer and colder — the distance coloured red when close, blue when far
  • Winning on three hits, a guess count, and already-probed checks
  • The design concept: search — narrowing a location from its clues

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

Unit roadmap

Phase 1

The grid

A two-dimensional array drawn as a grid, with hidden targets and probing

Units 1–2 Complete
Phase 2

The clues

Manhattan distance to the nearest target, colour-coded

Units 3–4 Complete
Phase 3

The game

Winning, then a graphical grid, ratings and replay

Units 5–6 Complete