Skip to content
Game 11 Unit 4 of 6 1 hr learning time

Ten Guesses

Wrap the scoring in a ten-turn loop and keep every result on screen — a history log the player reads to deduce the code, with the win and the run-out built in.

67% of Locksmith

A single scored guess is a clue; a game is ten of them, with every clue staying visible so the player can reason across turns. This unit wraps the bull/cow logic in a ten-guess loop and logs each result to its own line — the history that makes deduction possible.

  10 BORDER 0: PAPER 0: INK 7: CLS
 130 RANDOMIZE
 140 DIM c(4)
 150 FOR i = 1 TO 4: LET c(i) = INT (RND * 6) + 1: NEXT i
 160 CLS
 170 PRINT AT 14, 2; "Code: ";
 180 FOR i = 1 TO 4: PRINT c(i);: NEXT i
 190 INVERSE 1: PRINT AT 0, 0; "      *** LOCKSMITH ***        ": INVERSE 0
 200 FOR t = 1 TO 10
 210 PRINT AT 20, 0; "Guess "; t; " of 10: ";
 220 INPUT g$
 230 IF LEN g$ <> 4 THEN GO TO 210
 240 IF g$(1) < "1" OR g$(1) > "6" OR g$(2) < "1" OR g$(2) > "6" OR g$(3) < "1" OR g$(3) > "6" OR g$(4) < "1" OR g$(4) > "6" THEN GO TO 210
 250 DIM g(4)
 260 FOR i = 1 TO 4: LET g(i) = VAL g$(i): NEXT i
 270 LET bulls = 0
 280 FOR i = 1 TO 4
 290 IF g(i) = c(i) THEN LET bulls = bulls + 1
 300 NEXT i
 310 LET total = 0
 320 FOR d = 1 TO 6
 330 LET cc = 0: LET gc = 0
 340 FOR i = 1 TO 4
 350 IF c(i) = d THEN LET cc = cc + 1
 360 IF g(i) = d THEN LET gc = gc + 1
 370 NEXT i
 380 IF cc <= gc THEN LET total = total + cc
 390 IF gc < cc THEN LET total = total + gc
 400 NEXT d
 410 LET cows = total - bulls
 430 PRINT AT 2 + t, 2; g$; "  "; bulls; " bull  "; cows; " cow"
 490 IF bulls = 4 THEN PRINT AT 15, 2; "Code cracked!": STOP
 500 NEXT t
 510 PRINT AT 15, 2; "Out of guesses!"
 520 PRINT AT 16, 2; "The code was ";
 530 FOR i = 1 TO 4: PRINT c(i);: NEXT i
ZX Spectrum Locksmith: an inverse title, a history of three guesses each with bull and cow counts, and the next prompt
Each guess logged on its own line — the history the player reads to narrow the code.

A turn loop with a growing log

FOR t = 1 TO 10 (line 200) gives ten turns. The clever bit is the position of each result: line 430 prints to PRINT AT 2 + t, 2 — row 3 for turn 1, row 4 for turn 2, and so on — so each guess lands on its own line and the earlier ones stay put. The screen becomes a ledger: guess, bulls, cows, turn after turn. In a deduction game the history is the game; a result that scrolled away would take the player's reasoning with it. (The code still shows at the bottom while you test — it goes in the finale.)

Win inside the loop, lose after it

Two exits. Line 490 — IF bulls = 4 — ends the moment the guess is perfect: four bulls means the code is cracked, no need for the rest of the ten. If the loop runs all the way out without that happening, control falls past NEXT t to the "out of guesses" message, which reveals the code. A counted loop with an early exit on success is the shape of every "you have N tries" game.

Next: turn those two exits into proper win and lose screens.