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

Locksmith

A code-breaking game — guess the secret combination and decode the clues. Arrays, nested loops, and deduction.

ZX Spectrum Locksmith: a LOCKSMITH title bar above a history of guesses, each scored with red filled and white hollow pegs
What you will build: a Mastermind-style code-breaker with peg clues and a visible history.

Locksmith is Mastermind on the Spectrum. The computer picks a secret four-digit code — each digit from 1 to 6. You guess, and the computer tells you how close you are: a bull means you have the right digit in the right place; a cow means you have a digit that appears in the code, but at the wrong position. Ten guesses to crack it.

This is the third game in Volume 2 — Patterns of State — and the first pure logic game: no randomness during play, no time pressure, no reflexes. The whole game is deduction, and the whole program is one real algorithm.

Arrays you have (Quiz Master); parsing and slicing a string you have (Cipher). What Locksmith adds is comparing two arrays to score a guess — and the genuinely tricky part, the cow algorithm: counting how many of each digit the code and the guess share, without double-counting the ones already placed. Getting that right is the heart of the game.

What you will build:

  • A secret code in an array, and a four-digit guess parsed into another
  • Bulls — exact matches, found by comparing the two arrays position by position
  • Cows — the digit-counting algorithm that scores misplaced digits (the hard part)
  • Ten guesses with a running history log of each result
  • Win and lose screens, then peg clues, a title, and replay
  • The design concept: deduction — each clue narrows what the code can be

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

Unit roadmap

Phase 1

The clues

A secret code, a parsed guess, and the bull and cow logic

Units 1–3 Complete
Phase 2

The game

Ten guesses with a history log, then win and lose

Units 4–5 Complete
Phase 3

The finished game

Peg clues, a title, and replay

Units 6–6 Complete