Killer Robots is a text-based strategy game in which the player navigates a 10×20 grid maze, using numeric keypad-style movement (1–9) to lure pursuing robots into electrified walls marked with “X”. The maze is stored as two parallel 2D integer arrays — A() for the live game state and B() for a saved copy — allowing the same board layout to be replayed without regenerating it. Robot positions are tracked in arrays L() and M(), and each robot uses a sign-function intercept algorithm (SGN) to home in on the player one step at a time. The special moves include a random teleport (0), a no-move declaration (10), and suicide (-1); the computed GOTO at line 940 dispatches movement directions using a chain of Boolean-multiplied line numbers, a classic ZX81 idiom. An anomaly exists at lines 290–320 where N() is DIMensioned twice (first as N(12), then as N(Z)), with the second declaration silently replacing the first.
Program Analysis
Program Structure
The program is divided into a clear sequence of phases:
- Title and instructions (lines 0–230): Displays game rules and movement keys, waits for ENTER.
- Initialisation (lines 260–760): Dimensions arrays, populates the maze with walls and characters, saves a snapshot of the initial state.
- Display loop (lines 780–840): Prints the current 10×20 grid from array
A(). - Player input and movement (lines 850–1210): Reads the move code, dispatches to the appropriate coordinate update.
- Robot intercept loop (lines 1220–1470): Moves each robot one step toward the player.
- Win/lose detection and replay (lines 1480–1800): Checks whether all robots have been destroyed; offers replay with the same or a new layout.
Array Layout and State Management
The maze is a 10-row by 20-column grid. Two parallel arrays store state:
A(10,20)— the live game array, holding character codes for space,X,*, or+.B(10,20)— a snapshot of the initial maze and robot positions, used to restore the same layout on replay.
Robot positions are also stored redundantly in L(Z) (row) and M(Z) (column), allowing the intercept subroutine to update coordinates without scanning the full grid. A further snapshot of only the first five robots’ positions is saved in N() and O() for replay purposes — though this only covers robots 1–5 regardless of Z.
Notable Technique: Computed GOTO
Line 940 implements direction dispatch using a chain of Boolean arithmetic expressions:
GOTO (1100 AND Y9=1)+(1080 AND Y9=2)+...+(1000 AND Y9=9)
On the ZX81/TS1000, a true Boolean comparison evaluates to 1 and false to 0, so exactly one term is non-zero and the sum gives the target line number directly. This avoids a cascade of IF … THEN GOTO statements and is a well-known space-saving idiom on this platform.
Robot Movement Algorithm
The intercept subroutine at lines 1230–1380 uses SGN(J-X) and SGN(K-Y) to compute a unit-step vector from each robot’s current position toward the player. This is a simple but effective Manhattan-direction chase: the robot moves diagonally, horizontally, or vertically by exactly one cell each turn. If the destination cell is occupied by a wall (X), the robot is destroyed in place (its source cell is cleared, and no + is written). If the destination holds the player (*), flag G9 is set to 99 and the player is killed.
Bugs and Anomalies
| Location | Issue |
|---|---|
| Lines 290–320 | DIM N(12) is immediately superseded by DIM N(Z) three lines later. The first declaration is wasted; only N(Z) takes effect. This is likely a copy/paste remnant from the original BASIC. |
| Lines 710–730 | The replay snapshot loop runs FOR C=1 TO 5, saving only the first five robot positions into N() and O() regardless of how many robots Z specifies. Replaying with more than five robots will restore only a partial set of positions. |
| Lines 1740–1760 | The restore loop on replay also runs FOR C=1 TO 5, consistent with the snapshot but still silently ignoring robots 6 through Z. |
| Line 1170 | The random leap places the player at any interior coordinate but does not check whether the destination cell is a wall or a robot; landing on a wall triggers the death message at line 1600 correctly, but landing on a robot cell is not explicitly handled before the move is committed. |
| Lines 240–250 | The ENTER-to-begin wait loop polls INKEY$ for a non-empty key rather than specifically checking for ENTER, so any key press advances past the instruction screen. |
Key BASIC Idioms
CODE (" "),CODE ("X"),CODE ("*"),CODE ("+")are used throughout instead of numeric literals, making the cell-content comparisons self-documenting and portable.SLOW/FAST(lines 5 and 265) bracket the setup phase to improve display readability during the instruction screens.- The subroutine at lines 520–550 (
GOSUB 520) finds a random empty interior cell by rejection sampling, retrying if the chosen cell is not a space. - Line 940 uses leading zeros in
0950and0980— syntactically valid but unusual, likely preserved from the original David Ahl listing.
Replay Mechanism
When “SAME SET-UP?” is answered Y, the program restores A() from B(), restores the first five robot coordinates from N()/O(), and restores the player start position J1/K1, then jumps to line 770 to reset the no-move flag and redraw. A N answer triggers RUN at line 1685 which reinitialises everything from scratch including prompting for a new robot count.
Content
Source Code
0 REM ROBO (KILLER ROBOTS) FROM DAVID AHL, BASIC COMPUTER GAMES CONVERTED TO SINCLAIR BASIC BY ANTHONY WILLING, WITH INSTRUCTIONS ADDED
3 CLS
5 SLOW
10 PRINT TAB 8;"%K%I%L%L%E%R% %R%O%B%O%T%S"
15 PRINT
20 PRINT
30 PRINT
40 PRINT "YOU ARE WITHIN A MAZE. THE WALLS ARE ELECTRICALLY CHARGED, AND THERE ARE MANY ROBOTS TRYINGTO DESTROY YOU."
50 PRINT
60 PRINT "THE ONLY CHANCE TO SURVIVE IS TOMANEUVER THE ROBOTS INTO THE WALLS."
70 PRINT
80 PRINT "YOU ARE THE ""*"""
90 PRINT "ROBOTS ARE THE ""+""S"
100 PRINT "THE WALLS ARE THE ""X""S"
110 PRINT AT 21,3;"(PRESS ENTER TO CONTINUE)"
120 PAUSE 4E4
130 CLS
140 PRINT "MOVES ARE 7.8.9"
150 PRINT " 4.%5.6"
160 PRINT " 1.2.3"
170 PRINT
180 PRINT "ENTER:"
190 PRINT "10 = NO MOVE FOR REST OF GAME"
200 PRINT "-1 = COMMIT SUICIDE--HOPELESS"
210 PRINT " 0 = A HUGE RANDOM LEAP"
213 PRINT
215 PRINT "HOW MANY ROBOTS (5-30)?"
217 INPUT Z
220 PRINT AT 21,4;"(PRESS ENTER TO BEGIN)"
230 PRINT AT 21,4;"(%P%R%E%S%S% %E%N%T%E%R% %T%O% %B%E%G%I%N)"
240 IF INKEY$<>"" THEN GOTO 260
250 GOTO 220
260 CLS
265 FAST
270 DIM A(10,20)
280 DIM B(10,20)
290 DIM N(12)
300 DIM L(Z)
310 DIM M(Z)
320 DIM N(Z)
330 DIM O(Z)
340 FOR B=1 TO 10
350 FOR C=1 TO 20
360 LET X=INT (1+10*RND)
370 IF X=5 THEN GOTO 400
380 LET A(B,C)=CODE (" ")
390 GOTO 410
400 LET A(B,C)=CODE ("X")
410 NEXT C
420 NEXT B
430 FOR D=1 TO 10
440 LET A(D,1)=CODE ("X")
450 LET A(D,20)=CODE ("X")
460 NEXT D
470 FOR F=1 TO 20
480 LET A(1,F)=CODE ("X")
490 LET A(10,F)=CODE ("X")
500 NEXT F
510 GOTO 560
520 LET H=INT (1+8*RND)+2
530 LET I=INT (1+18*RND)+2
540 IF A(H,I)<>CODE (" ") THEN GOTO 520
550 RETURN
560 GOSUB 520
570 LET A(H,I)=CODE ("*")
580 LET J=H
590 LET K=I
600 FOR N=1 TO Z
610 GOSUB 520
620 LET A(H,I)=CODE ("+")
630 LET L(N)=H
640 LET M(N)=I
650 NEXT N
660 FOR C=1 TO 10
670 FOR D=1 TO 20
680 LET B(C,D)=A(C,D)
690 NEXT D
700 NEXT C
710 FOR C=1 TO 5
720 LET N(C)=L(C)
730 LET O(C)=M(C)
740 NEXT C
750 LET J1=J
760 LET K1=K
770 LET Y9=0
780 CLS
781 FOR E=1 TO 10
790 FOR D=1 TO 20
800 LET N$=CHR$ (A(E,D))
810 PRINT N$;
820 NEXT D
830 PRINT
840 NEXT E
850 IF Y9<>10 THEN GOTO 880
860 PRINT
870 GOTO 1180
880 INPUT Y9
890 LET J2=J
900 LET K2=K
910 IF Y9=0 THEN GOTO 1150
920 IF Y9<0 THEN GOTO 1570
930 IF Y9=10 THEN GOTO 1390
940 GOTO (1100 AND Y9=1)+(1080 AND Y9=2)+(1050 AND Y9=3)+(1130 AND Y9=4)+(1180 AND Y9=5)+(1030 AND Y9=6)+(0950 AND Y9=7)+(0980 AND Y9=8)+(1000 AND Y9=9)
950 LET J=J-1
960 LET K=K-1
970 GOTO 1180
980 LET J=J-1
990 GOTO 1180
1000 LET J=J-1
1010 LET K=K+1
1020 GOTO 1180
1030 LET K=K+1
1040 GOTO 1180
1050 LET J=J+1
1060 LET K=K+1
1070 GOTO 1180
1080 LET J=J+1
1090 GOTO 1180
1100 LET J=J+1
1110 LET K=K-1
1120 GOTO 1180
1130 LET K=K-1
1140 GOTO 1180
1150 PRINT "YOU JUMP..."
1160 LET J=INT (1+8*RND)+2
1170 LET K=INT (1+18*RND)+2
1180 IF A(J,K)=CODE ("X") THEN GOTO 1600
1190 LET A(J2,K2)=CODE (" ")
1200 LET A(J,K)=CODE ("*")
1210 GOTO 1390
1220 REM %I%N%T%E%R%C%E%P%T%O%R% %M%O%V%E%S
1230 IF A(X,Y)=CODE ("X") THEN GOTO 1360
1240 LET X2=X
1250 LET Y2=Y
1260 LET X=SGN (J-X)
1270 LET Y=SGN (K-Y)
1280 LET X=X+X2
1290 LET Y=Y+Y2
1300 IF A(X,Y)=CODE ("*") THEN GOTO 1370
1310 IF A(X,Y)=CODE (" ") THEN GOTO 1340
1320 LET A(X2,Y2)=CODE (" ")
1330 RETURN
1340 LET A(X,Y)=CODE ("+")
1350 LET A(X2,Y2)=CODE (" ")
1360 RETURN
1370 LET G9=99
1380 RETURN
1390 FOR N=1 TO Z
1400 LET X=L(N)
1410 LET Y=M(N)
1420 LET G9=0
1430 GOSUB 1230
1440 IF G9<>0 THEN GOTO 1580
1450 LET L(N)=X
1460 LET M(N)=Y
1470 NEXT N
1480 FOR N=1 TO Z
1490 IF A(L(N),M(N))<>CODE (" ") THEN GOTO 1510
1500 LET A(L(N),M(N))=CODE ("+")
1510 NEXT N
1520 FOR N=1 TO Z
1530 IF A(L(N),M(N))<>CODE ("X") THEN GOTO 780
1540 NEXT N
1550 PRINT "YOU DESTROYED ALL ROBOTS-YOU WIN"
1555 PRINT
1560 GOTO 1630
1570 PRINT "GIVE UP, EH??"
1580 PRINT "*****YOU HAVE BEEN KILLED*****"
1585 PRINT
1590 GOTO 1630
1600 PRINT "%H%I%G%H% %V%O%L%T%A%G%E"
1610 PRINT "ZAP...SIZZLE..YOU ARE DEAD"
1620 PRINT
1630 PRINT "ANOTHER GAME? (Y/N)"
1640 INPUT V$
1650 IF V$<>"Y" THEN GOTO 5000
1660 PRINT "SAME SET-UP? (Y/N)"
1670 INPUT V$
1680 IF V$<>"Y" THEN CLS
1685 IF V$<>"Y" THEN RUN
1690 FOR C=1 TO 10
1700 FOR D=1 TO 20
1710 LET A(C,D)=B(C,D)
1720 NEXT D
1730 NEXT C
1740 FOR C=1 TO 5
1750 LET L(C)=N(C)
1760 LET M(C)=O(C)
1770 NEXT C
1780 LET J=J1
1790 LET K=K1
1800 GOTO 770
5000 STOP
5020 SAVE "1021%4"
5030 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
