Killer Robots

This file is part of and Timex Sinclair Public Domain Library Tape 1005. Download the collection to get this file.
Developer(s): David Ahl, Tony Willing
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Game

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:

  1. Title and instructions (lines 0–230): Displays game rules and movement keys, waits for ENTER.
  2. Initialisation (lines 260–760): Dimensions arrays, populates the maze with walls and characters, saves a snapshot of the initial state.
  3. Display loop (lines 780–840): Prints the current 10×20 grid from array A().
  4. Player input and movement (lines 850–1210): Reads the move code, dispatches to the appropriate coordinate update.
  5. Robot intercept loop (lines 1220–1470): Moves each robot one step toward the player.
  6. 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

LocationIssue
Lines 290–320DIM 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–730The 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–1760The restore loop on replay also runs FOR C=1 TO 5, consistent with the snapshot but still silently ignoring robots 6 through Z.
Line 1170The 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–250The 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 0950 and 0980 — 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

Appears On

Assembled by Tim Ward from many sources. Contains programs 10211 – 10251.

Related Products

Related Articles

Related Content

Image Gallery

Killer Robots

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
\n1000 LET J=J-1
\n1010 LET K=K+1
\n1020 GOTO 1180
\n1030 LET K=K+1
\n1040 GOTO 1180
\n1050 LET J=J+1
\n1060 LET K=K+1
\n1070 GOTO 1180
\n1080 LET J=J+1
\n1090 GOTO 1180
\n1100 LET J=J+1
\n1110 LET K=K-1
\n1120 GOTO 1180
\n1130 LET K=K-1
\n1140 GOTO 1180
\n1150 PRINT "YOU JUMP..."
\n1160 LET J=INT (1+8*RND)+2
\n1170 LET K=INT (1+18*RND)+2
\n1180 IF A(J,K)=CODE ("X") THEN GOTO 1600
\n1190 LET A(J2,K2)=CODE (" ")
\n1200 LET A(J,K)=CODE ("*")
\n1210 GOTO 1390
\n1220 REM %I%N%T%E%R%C%E%P%T%O%R% %M%O%V%E%S
\n1230 IF A(X,Y)=CODE ("X") THEN GOTO 1360
\n1240 LET X2=X
\n1250 LET Y2=Y
\n1260 LET X=SGN (J-X)
\n1270 LET Y=SGN (K-Y)
\n1280 LET X=X+X2
\n1290 LET Y=Y+Y2
\n1300 IF A(X,Y)=CODE ("*") THEN GOTO 1370
\n1310 IF A(X,Y)=CODE (" ") THEN GOTO 1340
\n1320 LET A(X2,Y2)=CODE (" ")
\n1330 RETURN 
\n1340 LET A(X,Y)=CODE ("+")
\n1350 LET A(X2,Y2)=CODE (" ")
\n1360 RETURN 
\n1370 LET G9=99
\n1380 RETURN 
\n1390 FOR N=1 TO Z
\n1400 LET X=L(N)
\n1410 LET Y=M(N)
\n1420 LET G9=0
\n1430 GOSUB 1230
\n1440 IF G9<>0 THEN GOTO 1580
\n1450 LET L(N)=X
\n1460 LET M(N)=Y
\n1470 NEXT N
\n1480 FOR N=1 TO Z
\n1490 IF A(L(N),M(N))<>CODE (" ") THEN GOTO 1510
\n1500 LET A(L(N),M(N))=CODE ("+")
\n1510 NEXT N
\n1520 FOR N=1 TO Z
\n1530 IF A(L(N),M(N))<>CODE ("X") THEN GOTO 780
\n1540 NEXT N
\n1550 PRINT "YOU DESTROYED ALL ROBOTS-YOU WIN"
\n1555 PRINT 
\n1560 GOTO 1630
\n1570 PRINT "GIVE UP, EH??"
\n1580 PRINT "*****YOU HAVE BEEN KILLED*****"
\n1585 PRINT 
\n1590 GOTO 1630
\n1600 PRINT "%H%I%G%H% %V%O%L%T%A%G%E"
\n1610 PRINT "ZAP...SIZZLE..YOU ARE DEAD"
\n1620 PRINT 
\n1630 PRINT "ANOTHER GAME? (Y/N)"
\n1640 INPUT V$
\n1650 IF V$<>"Y" THEN GOTO 5000
\n1660 PRINT "SAME SET-UP? (Y/N)"
\n1670 INPUT V$
\n1680 IF V$<>"Y" THEN CLS 
\n1685 IF V$<>"Y" THEN RUN 
\n1690 FOR C=1 TO 10
\n1700 FOR D=1 TO 20
\n1710 LET A(C,D)=B(C,D)
\n1720 NEXT D
\n1730 NEXT C
\n1740 FOR C=1 TO 5
\n1750 LET L(C)=N(C)
\n1760 LET M(C)=O(C)
\n1770 NEXT C
\n1780 LET J=J1
\n1790 LET K=K1
\n1800 GOTO 770
\n5000 STOP 
\n5020 SAVE "1021%4"
\n5030 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top