A probe count is useful only if its rule is clear. We will count distinct valid cells, including the winning cell. Repeating a probe will move the marker but leave the count alone.
Replace lines 27, 160, 280.
Add lines 120, 130, 140, 250, 270, 1180, 2500, 2510, 2520.
27 LET n=0: LET lr=0: LET lc=0: LET pr=0: LET pc=0
120 LET seen=g(pr,pc)
130 LET d=seen
140 IF seen<>-1 THEN GO TO 200
160 LET g(pr,pc)=d: LET n=n+1
250 GO SUB 2500
270 IF seen<>-1 THEN LET s$="Already probed. No extra count."
280 IF d=0 THEN LET s$="Found in "+STR$ n+" distinct probes."
1180 GO SUB 2500
2500 PAPER 0: INK 7
2510 PRINT AT 1,0;"Distinct probes: ";n;" "
2520 RETURNComplete program for this step
10 LET stage=6
20 LET tr=3: LET tc=6
25 DIM g(8,8)
26 FOR r=1 TO 8: FOR c=1 TO 8: LET g(r,c)=-1: NEXT c: NEXT r
27 LET n=0: LET lr=0: LET lc=0: LET pr=0: LET pc=0
28 LET d=0: LET v=0: LET a$="": LET b$="": LET p$=""
30 GO SUB 1000
80 LET s$="N=1-2, M=3-4, F=5+ steps.": GO SUB 2600
100 LET p$="Row": GO SUB 3000: LET pr=v
110 LET p$="Column": GO SUB 3000: LET pc=v
120 LET seen=g(pr,pc)
130 LET d=seen
140 IF seen<>-1 THEN GO TO 200
150 LET d=ABS (pr-tr)+ABS (pc-tc)
151 IF d>4 THEN LET d=3: GO TO 160
152 IF d>2 THEN LET d=2: GO TO 160
153 IF d>0 THEN LET d=1
160 LET g(pr,pc)=d: LET n=n+1
200 LET oldr=lr: LET oldc=lc: LET lr=pr: LET lc=pc
210 IF oldr=0 THEN GO TO 240
220 LET r=oldr: LET c=oldc: GO SUB 2100
240 LET r=pr: LET c=pc: GO SUB 2100
250 GO SUB 2500
260 LET s$="Far: at least 5 steps away."
261 IF d=2 THEN LET s$="Medium: 3 or 4 steps away."
262 IF d=1 THEN LET s$="Near: 1 or 2 steps away."
270 IF seen<>-1 THEN LET s$="Already probed. No extra count."
280 IF d=0 THEN LET s$="Found in "+STR$ n+" distinct probes."
290 GO SUB 2600
310 GO TO 100
1000 BORDER 1: PAPER 0: INK 7: CLS
1010 PRINT AT 0,6;"SONAR N1-2 M3-4 F5+"
1020 FOR c=1 TO 8
1030 PRINT AT 2,6 +3 *(c-1);c
1040 NEXT c
1050 PRINT AT 3,4;"+------------------------+"
1060 PRINT AT 20,4;"+------------------------+"
1070 FOR r=1 TO 8
1080 PRINT AT 4 +2 *(r-1),2;r
1090 FOR k=0 TO 1
1100 PRINT AT 4 +2 *(r-1)+k,4;":";AT 4 +2 *(r-1)+k,29;":"
1110 NEXT k
1120 FOR c=1 TO 8
1130 GO SUB 2100
1150 NEXT c
1160 PAPER 0: INK 7
1170 NEXT r
1180 GO SUB 2500
1190 RETURN
2000 LET y=4 +2 *(r-1): LET x=5 +3 *(c-1)
2010 PAPER 1: INK 7
2020 IF r+c=2 *INT ((r+c)/2) THEN PAPER 5: INK 0
2030 RETURN
2100 GO SUB 2000
2110 LET z=g(r,c): LET b$=". "
2120 IF z=-1 THEN GO TO 2160
2130 LET b$=" F"
2140 IF z=2 THEN LET b$=" M"
2145 IF z=1 THEN LET b$=" N"
2150 IF z=0 THEN LET b$=" *"
2160 LET m$=" "
2170 IF r=lr AND c=lc THEN LET m$=">"
2180 PRINT AT y,x;m$;b$;AT y+1,x;" "
2190 RETURN
2500 PAPER 0: INK 7
2510 PRINT AT 1,0;"Distinct probes: ";n;" "
2520 RETURN
2600 PAPER 0: INK 7
2610 PRINT AT 21,0;" ";
2620 PRINT AT 21,0;s$;
2630 RETURN
3000 PAPER 0: INK 7
3010 INPUT (p$+" (1-8, Q): "); LINE a$
3015 IF LEN a$>16 THEN GO SUB 1000
3020 IF a$="q" OR a$="Q" THEN GO TO 9000
3030 IF LEN a$<>1 THEN GO TO 3100
3040 IF a$<"1" OR a$>"8" THEN GO TO 3100
3050 LET v=VAL a$
3060 RETURN
3100 LET s$="Use one digit from 1 to 8.": GO SUB 2600
3110 GO TO 3010
9000 LET s$="Finished. RUN to try again.": GO SUB 2600
9010 STOPLook before calculating
seen = g(pr,pc) reads what the board already knows. If it is -1, this cell is new: calculate the band, store it and add one to n. If it is anything else, copy the known code into d and jump to line 200. The marker and display still update, but the calculation and increment are skipped.
The test must use the unknown sentinel, not zero. A stored zero is a known discovery and must be recognised as a repeat too. The message at 270 explains a repeated probe; the found message at 280 takes precedence for a hit. New rounds will set n back to zero.
The short routine at 2500 prints the count on screen row 1. Both the ordinary probe path and the full redraw call it. Printing the count does not increase it.
After probing A, then B, then A again, what should change on the third turn?
Show the explanation
The latest marker moves from B to A and the message explains the repeat. Both clues remain. The count stays at two because the third turn did not reveal a new cell.
Rebuild from knowledge
Try (1,2), (8,8), (1,2). Check that the count is two. Probe (3,6) to find the target and bring it to three. Probe the target again; the count should still be three. For now this checkpoint keeps accepting probes after a hit.
Now enter Q to stop. In direct command mode, enter CLS, followed by GO SUB 1000. The screen should reconstruct all three clues, the latest marker and the count. Direct commands run immediately without replacing numbered lines. Enter GO TO 100 to resume asking for probes; RUN would instead initialise a new search.
Try a long invalid row answer after revealing several cells. The recovery redraw should produce the same board. Rejecting input and repainting the display are not new probes.
g is now enough to reconstruct every revealed clue, but it is not the whole game state. The target coordinates, count and latest marker have their own variables. Keeping these roles separate makes the next job easier: resetting a complete round deliberately.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapters 5 and 12 (routines and arrays).
Run it here
This unit's program, built for you.
- Program
- step-01.tap
- Machine
- ZX Spectrum 48K (PAL)