Locksmith
A code-breaking game — guess the secret combination and decode the clues. Arrays, nested loops, and deduction.
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
The clues
A secret code, a parsed guess, and the bull and cow logic
The game
Ten guesses with a history log, then win and lose
The finished game
Peg clues, a title, and replay