Contents
Breakout, 3D Maze, Letters, Matches, Russian Roulette, Compart, Talkback, Moon Lander, Bouncing Ball, Patchwork, Bugrace, Space Battle, Hammurabi, Higher/Lower, Buzz-Word, Othello, Number Guessing A, Number Guessing B, Hex Pawn, Drive, Biorythm, Sums tester, Scramble, Designs, Hunt the Wampus, Simon, Screens, Hangman
Programming Tips
Other BASICs
Tape Recording
The 6522 Versatile Interface Adapter chip
The 8255 Programmable Peripheral Interface chip
Block 0 RAM
ROM Routines
VDU codes
The complete book has been scanned. The scans have been OCR processed, but only the English text has been amenable to proof-reading and automatic spell-checking. The program listings are not so suitable, since spell checkers are not aware of Atom BASIC syntax.
Checking the program listings is as tedious as typing them in from scratch, because the OCR process produces so many errors. Rather than type them in as text, only for someone to type them into an Atom (real or emulated), these have been left as image files for now.
If anyone is interested enough to enter one of these programs, let me know and I can send you the image files which are legible. I have not put them on my website because I'm close to my 15 Mbyte limit and the compressed scans alone would consume around 5 Mbyte. These are between 48 and 126K per page, 5.45 Mbytes in total, so don't ask for more than you really want!
In return I would ask for a copy of the program in either text form or 'virtual' tapes as used by Atom emulators.
I also have the OCR text of the program source. Pretty heavily mangled, but might be slightly better than typing the whole lot from scratch.
Text; 2K
VDU ½K
Integer
A noisy and fast moving version of the popular computer game, Breakout starts with a wall 5 bricks thick across the top of the screen and a small star passing from side to side across the bottom of the screen.
Pressing either of the SHIFT keys will make the star shoot up diagonally towards the wall. If it hits a brick then that brick will either fall out of the wall, or - if it is held up by another brick - will turn grey and fall as soon as it is no longer supported.
Points are scored by sending the star off the top of the screen through a gap in the wall. An arrow then appears at the point of exit and your score is increased by one. But be careful; if you accidentally hit an arrow it will fall and you lose that point.
You have a limited time in which to score as many points as possible. A count-down display of the time remaining is shown at the top left of the screen. When the game has finished, a new one may be started by pressing any key.
The program uses two machine language routines (lines 5020 to 5160) to generate various sound effects.
The program draws on the screen by storing appropriate values (e.g. #2A for a *) in the VDU screen memory locations 8000-81FF.
Thus line 20 draws the initial 5 rows of bricks, line 40 plots a *, and line 55 deletes the old *.
The main program loop is from lines 30 to 210, which moves the star across the screen; line 32 branching to e if you have scored a point, line 36 reducing your score if you have hit an arrow. If you hit anything, line 37 branches to the routine at line 2000. Lines 40-55 shift the image of the star - using subroutine 5 to provide sound effects if it is moving upwards. Lines 56-60 sets W to -32 when the SHIFT key has been pressed.
Lines 490-530 increment your score, PLOT an arrow in the place where you broke through the wall, using the subroutine s to generate the winning sound.
Line 2000 is reached if the star hits anything, and returns to the main loop at line 210 if a solid brick is below the one hit. Line 2002 is executed if you have hit an arrow. Lines 2005-2040 make the falling brick images and sounds. Lines 2050-2070 repeat the process if any grey blocks are left unsupported.
Line 1010 is reached at the end of the program; it waits for any key to be pressed, then starts a new game.
Text; 5K
VDU; 1K
Integer
This program generates a random maze of specified dimensions then plots it in 3D as though you were actually inside it. You then have to find your way out by moving forward (key F), or by turning right (R) or left (L). Pressing key H (for HELP!!!) will give you your co-ordinates and the direction in which you are pointing.
The exit is represented by two vertical poles;
<DIAGRAM HERE>
The maximum size of maze allowed is 19 x 18.
Text; 2K
VDU; ½K
Integer
This program plots a number of letters on the screen. You then have to erase them all by moving the cursor over each letter in turn. If you hit the edge of the screen or donut erase the letters in alphabetic order then the game finishes and you lose.
Once the game has started the cursor is continually moving. To change it's direction press one of the keys 4,5,6 or 7; which make it, go down, ups left or right respectively.
As it moves, the cursor leaves a trail that can cause great confusion if you have to retrace your steps, as you are then unable to see exactly where you are.
The difficulty of the game can be varied by specifying a different number of letters (1 to 26) to be erased, or by varying the speed of movement to 10) in response to questions asked when the game is started. You are also asked for a 'course number'. This is used to seed the random number generator used to position the letters, so that you may run exactly the same game again by specifying the same course number.
When the game has finished - either because you have made a mistake or because, you have successfully erased all of the letters, then another game is automatically started.
By leaving out the REM lines and abbreviating the other lines, 'letters' can be made to fit into 1K text RAM space.
A machine language routine (lines 20-75) is used to scan the keyboard by directly manipulating the 8255 I/O chip ports. Line 9 prevents the assembly listing from appearing on the screen when the program is executed. Line 90 subsequently re-enables the display.
Since the random number seed occupies 5 bytes of RAM, (locations 8 to 12), while an integer variable takes only 4 bytes, pre-setting the seed to the 'course' number (C; line 115) involves setting RAM location 12 to zero as well as storing the value of C in the other four bytes.
Text; 1K
VDU ½K
Integer
Matches is a simplified form of NIM. Starting with a row of from 21 to 32 matches, the player and the computer take turns to remove 1, 2 or 3 matches. The player left with the last match loses.
Line 100 establishes the starting number of matches and displays them by calling subroutine 900. Lines 110 to 140 then present the instructions above the displayed row of matches.
Lines 300-340 get the player's choice and check that it is valid, lines 400-470 then calculate the computer's move. If neither side has won then the current state of the game is displayed and the next move played.
Text; 1K
VDU; ½K
Integer
Russian Roulette is a game for two or more players who take turns to place a loaded revolver to their heads and pull the trigger. Five of the revolver's chambers are empty, the sixth contains a live round. The game is over when a player refuses to take his turn, or when the revolver fires.
In response to the question 'DO YOU WANT TO PULL THE TRIGGER', enter either Y or N, then press the Return key.
The two PRINT $12 statements (lines 20 & 210) clear the VDU screen and position the cursor at the top left corner.
Line 230 gives a half-second pause to heighten the tension. Line 300 generates a 'click' sound; line 510 makes a suitable 'raspberry' noise.
Lines 400-450 may be improved by artistically minded programmers.
Text; 1K
VDU; 1K
Integer
This program draws a sequence of five abstract pictures in either black and white, or black, grey and white.
1 REM COMPART BY D.DINI AUG '80 5 DIM A(7); !A = #10204080; A!4 = #1020408 10 P.$12 20 P." computer art"'' 25 IN. "DO YOU WANT SINGLE(1) OR DOUBLE(2) SHADE DRAWINGS"I 30 P. "PRESS ANY KEY TO START" 35 LINK #FFE3 37 FOR D = 1 TO 5 40 CLEAR 1; IF I = 2; ?#B000 = #10 44 MOVE 1,1; X = 126; Y = 62 45 DRAW 1,Y; DRAW X,Y; DRAW X,1; DRAW 1,1 50 P = ABS RND % 123 + 2; Q = ABS RND % 59 + 2 60 GOSUBd 70 FOR Z = 1 TO 10000; NEXT Z 80 NEXT D 90 RUN 1000dX = RND % 2; Y = RND % 2 1010 V = X+P; W = Y+Q; GOSUB t 1020 IF C GOTO n 1030 T = 0 1040 P = P + X; Q = Q + Y 1050 PLOT 13,P,Q 1060 GOTO 1010 1070nT = T + 1 1080 IF T < 100 GOTO d 1090 RETURN 2000tB = V/8+(63-W)*16+#8000 2100 C = (?B&(A?(V&7))<>0); RETURN
If double shade drawings are selected, then I=2 and line 40 sets the VDU controller to mode 1a.
Line 70 gives a short pause at the end of each drawing for you to admire it before the computer begins its next opus.
Text; 2K
VDU; 2-6K
Integer
While this program does not answer Man's dream of a talking computer, it does allow you to record a few seconds of speech in ATOM's memory, then play it back on demand.
The speech is converted to digital form then stored in the VDU RAM area (above the text screen area), each 1K byte giving one second of recording time. In any digital speech recording system a compromise must be made between quality of reproduction and the amount of storage needed - in this case the choice has been to extend the recording time as much as possible and accept a pretty dreadful quality for the reproduced signal) although a noticeable improvement can be made by careful choice of the recording-level and by turning any amplifier 'treble' control to minimum.
Recording is done from a microphone connected via a suitable amplifier to ATOM's 'CASS IN' port. The level needed by ATOM is about the same as when loading programs from tape, so the cassette recorder amplifier will probably be suitable. Playback is through ATOM's built-in loudspeaker.
When the program is run, it asks if you want to Record or Play-back If you choose to record then the screen will be covered by snow' for a few seconds while the program initialises the VDU RAM area. You are then asked to press any key to start the recording process. While recording, the screen will again be sprinkled with white lines as the data is stored.
As given, the program expects the full 6K bytes of VDU RAM. If less RAM is available, the CPY @#98 instructions in lines 1080 and 1590 should be changed to;
CPY @#94 for 5K bytes VDU RAM #90 4 " " #8C 3 " " #88 2 " "
The main work is done by the two machine language routines at lines 1000-1120 and 1500-1630. When recording, the voltage on the CASS IN port is examined every 125 µS, and one bit of the memory is set to either '1' or '0' depending on whether the signal was positive or negative. When playing back, a single bit is taken from the memory every 125 µS and the state of the loudspeaker drive line set high or low accordingly. A large part of the machine language routines (notably lines 1040, 1100, 1110, 1560, 1600 & 1610) consists of 'time wasting' instructions inserted so that the over-all loop time is always 125 uS.
Note that lines 210-230 preset the RAM before recording so that each byte has bits 1-7 =0 and bit 0 = 1.
Text; 2K
VDU; 1K
Integer
You are piloting a rocket landing on the Moon; the **!!**!!** computer has failed again (and the engine sounds rough). At the start of the simulation you are 450 metres up, travelling horizontally at 300 metres per second, and starting to fall from orbit. You should aim to land within the Lunar Landing Area (the small white rectangle on the Moon's surface) with a vertical velocity of less than 50 m/s and a horizontal velocity of less than 20.
Your controls are the keys F, R and U, which apply forward, reverse or upward thrust respectively but only one at a time. Instrument readings of height, velocities and fuel remaining are given on the right of the screen. Happy landings.
10 REM MOON LANDER 20 DIM P(-1); P.$21 30[;JSR #FE71;STY #80;RTS;];P.$6 100 J = #1B8020; K = #1B8080; L = #1B80E0 110 M = #1B8140; N = #B002; O = #DE 120 D = 0; A = 45000; V = 0; H = 300; F = 1250 130 T = 1000; Y = A/T+2; X = D/T 140 CLEAR 0; @ = 5; MOVE 0,0; DRAW 63,0; MOVE 0,1 150 DRAW 63,1; MOVE 31,2; DRAW 33,2 160 !O = #1D8000; P. "ALT" 170 !O = #1D8060; P. "H-V" 180 !O = #1D80C0; P. "V-V" 190 !O = #1C8120; P."FUEL" 200a FOR U = 1 TO 5; IF A < 1 A = 0; G.c 210 WAIT; PLOT 15,X,Y; X = D/T; Y = A/T+2 220 WAIT; PLOT 13,X,Y; ?N = #D3 230 LINK TOP; R = ?#80; IF F < 1 F = 0; G. b 240 IF R = 53 V = V - 5; F = F - 5; ?N = #D7 250 IF R = 50 H = H - 3; F = F - 3; ?N = #D7 260 IF R = 38 H = H + 3; F = F - 3; ?N = #D7 270b A = A - V; D = D + H; V = V +2; N. 280c!O = J; P.A/100; !O = K; P.H; !O = L; P.V; !O = M; P. F 290 IF A > 0 G.a 300 IF ABS V < 50 IF ABS H < 20 G. d 310 FOR I = 1 TO 4; MOVE (X-6), 4 320 PLOT 5,X,0; ?N = ?N:4; PLOT 1,6,4; ?N = ?N:4; WAIT 330 PLOT 7,X,0; ?N = ?N:4; PLOT 3,(-6),4; ?N = ?N:4; 340 NEXT; MOVE X,0; PLOT 3,0,3 350 !O = #8080; P."ANOTHER CRATER !" 360 IF ABS V < 100 G.e 370 !O = #80C0; P."WHERE WAS THE PILOT ?"; G.e 400d!O = #8080; S = ABS (H*V) 410 IF s<300 P."SMOOTH - -" 420 IF S>299 p."BUMPY ! ! " 430 !O = #80C0; @ = 0; X = ABS (X-32) 440 IF X > 1 P. "BUT "X" KM FROM BASE" 450 IF X > 5 P. " walk" 460 IF X > 1 OR S > 200 G.e 470 P. "HELLO BUCK ROGERS " 499e ?#E1 = #80; END
A small machine language routine (line 30) is used to scan the keyboard and put the number of any key pressed into RAM location 80. Lines 100-190 set up the constants J-O which are used for speed in the main program loop, the starting values and position, and prepare the screen. Note lines 160-190 (and 280) which move the print cursor by storing a four-byte word in locations #DE-E1.
The main body of the program is lines 200 to 290 which continually plot the latest position of your craft (lines 210,220), scan the keyboard and adjust the velocities and fuel level accordingly (lines 230-260) and update your position (line 270). Every five iterations, line 280 updates the instrument readings.
When you have touched ground, lines 300-370 draw an explosion and make suitable comments if you landed too fast. If you have survived, lines 400-499 pass comment on your prowess as a pilot.
Text; ½K
VDU.; ½K
Integer
A simple demonstration of a moving display) this program shows a ball bouncing endlessly between the walls of an enclosure. Use ESC to stop the program.
1 REM BOUNCING BALL 10 CLEAR 0; X = 1; Y = 24; H = -1; V = 1 20 MOVE 0,0 30 PLOT 1,63,0; PLOT 1,0,47 40 PLOT 1,-63,0; PLOT 1,0,-47 50aWAIT; IF X = 1 OR X = 62 WAIT; H = -H 60 WAIT; IF Y = 1 OR Y = 46 WAIT; V = -V 70 WAIT; PLOT 15, X, Y 80 WAIT; X = X+H; Y = Y+V 90 WAIT; PLOT 13,X,Y; GOTO a
Line 10 sets up the 48 x 64 graphics mode and the starting position (X,Y) and velocity (H,V) of the ball. Lines 25-40 then DRAW the four walls.
The main body of the program is the loop covering lines 50-90. Lines 50 and 60 reverse the direction of travel if the ball touches one of the walls; line 70 deletes the old image of the ball from the screen, and lines 80 and 90 calculate the new position and plot it.
Text; ½K
VDU; ½K
Integer
Patchwork displays a very long sequence of 'kaleidoscope' patterns. Other sequences may be obtained by changing line 140.
10 REM PATCHWORK 100 CLEAR 0 110 FOR A = 1 TO 100 120 FOR B = 1 TO 31 130 FOR C = 0 TO 31 140 E = (C*5/(B+A+1)+B)%2*2+13 145 D = B+C 146 F = B*23/31; G=D*23/31; H=-63-D; I=-63-B; J=47-F; K=47-G 150 WAIT; PLOT E,D,F 160 PLOT E,H,F 170 WAIT; PLOT E,D,J 180 PLOT E,H,J 190 WAIT; PLOT E,B,G 200 PLOT E,I,G 210 WAIT; PLOT E,B,K 220 PLOT E,I,K 230 NEXT; NEXT; NEXT
Text; 1K
VDU; 1K
Integer
Another simple moving display program, Bug race shows two specks skittering down a racetrack. The program stops when one bug reaches the end of the course - then after a short pause it runs another race.
1 CLEAR 0 3 INPUT "HIT RETURN TO START BUGRACE" $TOP 5 CLEAR 1; A = 0; B = 15; C = 0; D = 47 10 DO WAIT 20 PLOT 15,A,B; PLOT 15,C,D 30 A = A+ABS RND%2; B = B + RND%2 40 C = C+ABS RND%2; D = D + RND%3 50 IF B< 1 B = 1 55 IF B>30 B = 30 60 IF D<33 D = 33 65 IF D>62 D = 62 70 WAIT 80 PLOT 13,A,B; PLOT 13,C,D 90 UNTIL (A = 127) OR (C = 127) 100 FOR X = 1 TO 100; WAIT; NEXT 110 GOTO 1
Line 5 sets up the 64 x 128 graphics mode and the starting points (A,B for the first bug, C,D for the second).
The main body of the program is the loop through lines 10-90. Line 20 erases the previous images; line 80 plots the new positions of the racers. The WAIT statements in lines 10 and 70 ensure that the VDU RAM is only accessed during the display blanking periods (and also slow the competitors down to a decent pace). Lines 30,40 calculate the new positions, and lines 50-65 make sure that the racers do not stray out of their lanes.
Text; 2K
VDU; 1K
Integer
You are engaged in a fast moving battle against alien spaceships that must be zapped before they can destroy you and go on to conquer Cambridge. Before the fight started, you had a chance to choose the number of enemy ships and the general level of skill needed to survive. Now' the battle is under way, the screen shows you the relative position of the nearest alien. To kill him you just have to steer your ship until his image comes within the inner aiming rectangle on your screen, then press the firing key. But be quick about it - he is liable to shoot back. New recruits to the Atomic Space Service are advised to gain experience in fights at skill level 1 before tackling trickier opponents.
1 REM SPACE BATTLE - BY T. MABBS 10 P.$12"*** SPACE BATTLE ***"' 15 P."KEY B TO GO RIGHT"' 20 P." C LEFT"' 25 P." D DOWN "' 30 P." E UP"' 35 P." F TO FIRE"'
Source code
Lines 10-80 display the instructions at the start of the game, get the number of aliens (A) and skill level (L), then calculate the size of the aiming window (O,P,Q,R). U and V are the horizontal and vertical velocities of the alien ship, S is the number of shots fired.
The main body of the program is the loop through lines 200-280, which plots the latest position of the alien ship (line 200), then scans the keyboard (subroutine b) and acts accordingly.
Line 2l0 sometimes calls the subroutine at line 500 to give the enemy a chance to fire at you or change direction.
Lines 300-350 are the 'your shot' subroutine; line 300 makes a suitable noise, line 320 draws the shot lines and line 330 erases them. If the alien ship was within the aiming rectangle the program jumps to line 400 to draw a brief explosion with sound effects provided by line 420. If you have destroyed all of the enemy ships the program then goes to line 1000, otherwise line 440 draws a new screen with the next alien.
Lines 500-580 are executed when the alien fires at you. Lines 500 and 520 show the enemy fire and make a suitably frightening noise, line 530 changes his direction of travel. If you have suffered a direct hit (C=64, D=32) then the game ends via lines 560 to 580.
Lines 900-910 scan the keys B-F by direct manipulation of the I/O ports at B000 and B001, and put a '1' in one or the RAM locations 80-84 if the corresponding key was pressed.
Text; 2K
VDU; ½K
Integer
Hammurabi was possibly the first 'world simulation' computer game to be written. You play the part of Hammurabi; King of ancient Sumaria. Each year your faithful servant - Atom - tells you how big your kingdom is, how many subjects you have, and how much grain is left from the harvest and from previous years. You then have to decide whether to trade land for grain with neighbouring kingdoms, how much to allocate as food for the coming year, and how much grain is to be used as seed.
Your subjects will die of starvation if you don't allocate enough food for the coming year (about 15 bushels each), but if you give them too much the surplus is wasted. Each year's harvest depends on the amount of seed used, but planting more than two bushels per acre is wasteful as is allocating more than 25 bushels of seed to each of your subjects. The harvest is also subject to a large random factor (the weather). Rats can devastate your grain stores, and your kingdom is subject to plagues about every seventh year.
10 REM HAMMURABBI 20 H = 100; S = 3000; A = 1000; Y = 0; @=0,P. $12 100 P.'"O HAMMURABI, KING OF SUMARIA,"' 120 P."YOUR SUBJECTS NOW NUMBER " H ","' 130 P."YOUR KINGDOM COVERS " A " ACRES,"' 140 P."YOU HAVE " S " BUSHELS OF GRAIN,"' 200 L = 20+RND%5; P. "LAND IS " L " BUSHELS PER ACRE,"' 210 INPUT"HOW MANY ACRES DO YOU BUY " E; IF E*L>S GOSUB a; G.210 220 IF E>0 GOTO 260 230 GOSUB a 240 INPUT "HOW MANY ACRES DO YOU SELL" E; E = -E 250 IF (-E)>A GOSUB a; GOTO 240 260 A = A+E; S = S-L*E 270 INPUT "HOW MANY BUSHELS FOR FOOD " F; IF F>S GOSUB a; GOTO 270 280 S = S-F 290 INPUT 'HOW MANY BUSHELS FOR SEED " P; IF P>S GOSUB a; GOTO 290 300 S = S-P; IF P>2*A P = 2*A 310 IF P>25*H P = 25*H 320 R = ABS RND%(1+S/2); C = P/4+ ABS RND%(1+P*4); S = S+C-R; D = H-F/15 330 D = H-F/15; IF D<1 D=0 340 H = H-D; N = H/20+RND%(11+H/20); H = H+N 350 Z = 0; IF RND%4 = 3 Z = H/3+RND%(1+H/4) 360 H = H-Z; Y = Y+1 400 P.$12; FOR 1 = 1 TO 50; WAIT; NEXT 410 P. "O KING, I BEG TO REPORT THAT"' 420 P. "IN YEAR " Y " OF YOUR REIGN"' 430 P. "YOU HARVESTED " C " BUSHELS"' 440 IF R>0 P. "BUT RATS ATE " R " BUSHELS"' 450 P. D" PEOPLE STARVED, " N " WERE BORN"' 480 IF Z>0 P. Z " DIED OF PLAGUE"' 490 IF H>0 GOTO 100 500 P+''"AS YOU HAVE NO SUBJECTS LEFT,"' 510 P. "THIS IS THE END OF YOUR REIGN"''; END 1000a P. $11$13"
Line 20 sets up the initial values of H (population), S (grain in store), A (acres of land) and Y (year).
The main body of the program is lines 100 to 490, which are executed once for each year of your reign. Lines 100-140 report on the extent of your kingdom, lines 200-290 then ask for your decisions about the amounts of grain to be used for food and seed, each answer being quietly checked for validity and diplomatically ignored if you ask for the impossible (subroutine a being used to delete an erroneous entry from the screen and re-position the cursor; note that there should be exactly 32 spaces, between the quotation marks in line 1000). Lines 300-360 calculate the results for the year, in terms of R (bushels of grain eaten by rats), 0 (deaths from starvation), Z (deaths from plague) and N (births). If you have any subjects left after another year of misrule, the program then loops back to line 100.
Text; 1K
VDU; ½K
Integer
Higher/Lower is played by one person against the computer. For each play the computer picks two numbers between 1 and 99, displays the first, then asks the player to bet on whether the second number is higher or lower than the first. Starting with a stake of £100, a really successful player can break the bank by amassing £10,000 or more. The game will also end if the player has no money left.
10 REM HIGHER/LOWER 20 @=0; P=100 100 M=1+ABSRND%99; N=ABSRND%100; IF N=M GOTO 100 110 P.$12"I HAVE CHOSEN TWO NUMBERS (0-99)"' 120 P."THE FIRST IS "M''"IS THE SECOND NUMBER"' 130 P."HIGHER (H) OR LOWER (L) "$TOP 140 IF CH$TOP<>CH"H" AND CH$TOP<>CH"L" GOTO 130 150 P.'"YOU HAVE GOT "P" POUNDS,"' 160 INPUT"HOW MUCH DO YOU BET "B; IF B>P OR B<0 GOTO 160
200 P=P+B 210 IF CH$TOP=CH"H" AND N<M P=P-2*B 220 IF CH$TOP=CH"L" AND N>M P=P-2*B 230 P.'"IT WAS "N'"YOU NOW HAVE "P" POUNDS"'' 240 IF P=0 P.'"SORRY AND GOODBYE*"';END 250 IF P>9999 P."CONGRATULATIONS - YOU'VE BROKEN THE BANK"'END
300 INPUT "ANOTHER BET (Y/N) "$TOP; IF CH$=CH"Y" GOTO 100 310 END
Text; 1K
VDU; ½K
Integer
An aid for the busy executive, Buzz-Word generates impressive sounding phrases for use in reports to higher management.
3 lists, each containing 5 words, are stored at the end of the program listing. Each list starts with a label (a, b or c), each word or phrase starts with a *. The program displays one word or phrase - chosen at random - from each list.
Text; 3K
VDU; ½K
Integer
Othello is played between the computer (C) and its human opponent (H) on an 8 x 8 board. At the start of the game, each player has two pieces in the centre of the board.
H and C take turns to place a new piece in one of the vacant squares so as to 'capture' one or more opponent's pieces. Pieces are captured if they lie on a horizontal, vertical or diagonal line terminated at one end by the piece just placed, and at the other end by an existing piece belonging to the player making the move. Pieces captured change type to that of the player capturing them.
Each move must capture at least one piece, or else the player forfeits that move. The game ends when all 64 squares have been filled or when neither player can move. The winner is then the player with the most pieces.
The program displays the current scores and the state of the board after each move. The human player should enter his move as the row (1-8) and column (A-H) of the selected square (e.g. 8A), or he may forfeit his move by just pressing the Return key. The program will not accept invalid moves.
The algorithm used to calculate the computer's move is a fairly simple one, which allows the human player a reasonable chance of winning.
10 REM OTHELLO 100 M=1;H=8;C-3; DIM A(99); DIM NN(7); DIM B(9) 110 NN(0)=11;NN(1)=10;NN(2)=9;NN(3)=1 120 NN(4)=-1;NN(5)=-9;NN(6)=-10;NN(7)=-11 130 P.$12;?#E1=0;P." A B C D E F G H"' 140 @=7; FOR I = 1 TO 8; P.I" * * * * * * * *"'; NEXT 150 FOR I = 0 TO 99; A?I=0; NEXT 160 T=C; P=44; GOSUB a; P=55; GOSUB a 170 T=H; P=44; GOSUB a; P=55; GOSUB a
200 REM YOUR MOVE 210 GOSUB b; IF ($B="" AND M=0) OR y+Z=64 GOTO 900 230 INPUT "YOUR TURN (E.G. 3d) "$B; IF $B="" GOTO 300
240 IF ?B<CH"1" OR ?B>CH"A" OR ?B1<CH"A" OR ?B1>CH"H" GOTO 260 256 P=(?B-CH"0")*10+?B1-CH"A"+1; T=H; F=0; GOSUB c; IF S>0 GOTO 270 260 P.$11; GOSUB g; GOTO 230 270 F=1; GOSUB c
300 REM COMPUTER'S MOVE 310 GOSUB b; IF ($B="" AND m=0) OR Y+Z=64 GOTO 900 320 M=0; D=0; F=0; T=C; P."LET ME THINK ...." 330 FOR U=1 TO 8; FOR V=1 TO 8; P=U+10*V; GOSUB c; IF S=0 GOTO 365 340 IF U=1 OR U=8 S=S*2 340 IF U=1 OR U=8 S=S*2 340 IF U=2 OR U=7 OR v=7 S=S/2 355 IF S=D D=D-ABSRND%2 360 IF S>D D=S; M=P 365 NEXT V; NEXT U
370 GOSUB G; IF M>0 F=1; P=M; GOSUB c 380 IF M=0 P."i CAN'T MOVE"; FOR I=1 TO 25; WAIT; NEXT 390 GOTO 200
900 REM WRAP IT UP 910 IF Y>Z P."YOU WON - CONGRATULATIONS"' 920 IF Y=Z P."** A DRAW **"' 930 IF Y<Z P."I WON - OF COURSE"' 940 ?#E1=#80; END
1000a REM PLACE A PIECE 1010 X=2*(P%10)+32*(P/10); X?8006=128+X?#8006 1020 FOR I = 1 TO 30; WAIT NEXT 1030 A?P=T; X?#8006=R; RETURN
2000b REM ADD SCORES 2010 Y=0; Z=0 2020 FOR I=11 TO 88 2030 IF A?I=H Y=Y+1 2040 IF A?I=C Z=Z+1 2050 NEXT 2060 P.$30; FOR I = 1 TO 3; GOSUB g; P.$10; NEXT 2070 FOR I = 1 TO 3; GOSUB g; P.$10; NEXT 2080 FOR I = 1 TO 3; P.$11; NEXT 2090 @=0; P."YOU HAVE "Y", "I HAVE "Z" "'';RETURN
3000c REM EXAMIN POSITION & MOVE IF F=1 3010 R=P; S=0; IF A?P<> RETURN 3015 IF F=1 GOSUB a 3020 FOR J=0 TO 7; Q=R; P=R; K=0
3030d Q=Q+NN(J) IF A?Q=0 GOTO f 3040 IF A?Q=T GOTO e 3050 K=K+1; GOTO d
3060e S=S+K; IF F=0 OR K<1 GOTO f 3070 FOR L=1 TO K; P=P+NN(J); GOSUB a; NEXT 3080f NEXT J; RETURN
4000g REM CLEAR LINE 4010 P.$13" "$11;RETURN
There should be exactly 32 spaces between the quotation marks in line 4010.
By cutting out the REM statements and abbreviating wherever possible, Othello can be made to run in 2K of text RAM.
The 10 x 10 byte array A(99) is used to hold the current state of the board; each byte being either 0 (free square), H or C. A 10 x 10 array is used because by considering it to represent the 8 x 8 board plus an empty surrounding border no special treatment is needed for squares on the edge of the playing board when looking for possible moves. The variable P is used to represent the position being examined, and the array NN holds the 8 possible movements from P.
Lines 100-170 set the starting values and DRAW the board at the start of play.
Lines 200-270 get your move, check that it is valid, then update the displayed board image and the array A().
The computer calculates its best move in lines 300-390 by examining every possible position, then choosing that with the highest score S. Line 355 introduces a random element if two positions have equal scores. The algorithm used does not do any form of 'look-ahead' but just sums the number of enemy pieces that could be captured, then increases the score if the square being examined is on the edge of the board, or decreases the score if it is just one row or column away from the edge.
Text; ½K
VDU; ½K
Integer
In this simple game, the computer picks a random number from 1 to 9, the player then has 5 chances to guess it. Unless the player has considerable ESP talent, he should only be able to win about half of the games played.
10 REM NUMBER GUESSING A 20 N = 1 + ABS RND % 9; @ = 0 30 PRINT $12"I AM THINKING 0F"' 40 PRINT "N NUMBER FROM 1 TO 9"' 50 PRINT 'YOU HAVE 5 GUESSES' "' 100 FOR G = 1 TO 5; INPUT X 110 IF X = N GOTO 200 120 PRINT $11, X "IS WRONG"' 130 NEXT & 140 PRINT "IT WAS" N1; END 200 PRINT $7; WAIT; PRINT $7 210 PRINT "*** CORRECT ***"; END
Text; ½K
VDU; ½K
Integer
This number guessing game gives the player 7 chances to guess a number from 1 to 99, but tells the player whether each guess was too high or too-low - which is enough information to allow the correct number to be deduced in every game.
10 REM NUMBER GUESSING B 20 N = 1 + ABS RND % 99; @ = 0 30 PRINT $12"I AM THINKING OF"' 40 PRINT "A NUMBER FROM 1 TO 99"'' 50 PRINT "YOU HAVE SEVEN GUESSES"'' 100 FOR G = 1 TO 7 110 INPUT X; IF X = N GOTO 200 120 IF X<N PRINT $11, X " IS TOO SMALL"' 130 IF X>N PRINT $11, X " IS TOO BIG."' 140 NEXT G 150 PRINT "IT WAS "N'; END 200 PRINT $7; WAIT; PRINT $7 210 PRINT "*** CORRECT ***"; END
Line 20 chooses the number (N) and sets the print field width to zero for a neater display.
The PRINT $11 statements in lines 120 and 130 move the cursor back one line so that the comment 'IS TOO SMALL' or 'IS TOO BIG' appears on the same line as the entered value.
Line 200 generates the sound of success.
Text; 3K
VDU; 1/2K
Integer
Hexpawn is a simple game played between the computer (C) and its human opponent (H) on a 3 x 3 board. It is interesting to the computer programmer as it has the right level of complexity to useful for experiments in computer 'learning' techniques. In the program given here, the computer remembers each board position (or pattern) that it encounters, and over the course of many games it learns the best move to make from each position. Given enough practice it can become very good.
As the player will soon notice, the program does not attempt to work out the best move to make from any new position, but just selects the first legal move that it can find. However, if that move results in the computer losing, then it will not play the move again if confronted by the same position in another game.
At the start of each game each player has three pieces; the computer's being along the top row of the board, the human player's being along the bottom row. The pieces are similar to chess pawns and may be moved straightforward to an empty square, or may be moved diagonally forward to take an opponent's piece. A player loses when he cannot move any of his pieces. The program assumes that its opponent knows how to play properly, and the computer will surrender if it finds itself in a position that it has learnt will always lead to defeat.
At the end of each game the computer will ask if you want to another. Note that if the program is actually stopped at any time by ESC, BREAK or by refusing the invitation to play another game, then re-starting it by typing RUN will make the computer forget all it has learned. Type GOTO 100 to avoid this.
There should be exactly 32 spaces between the quotation marks in line 1010.
The current state of the board is held in the 9 byte vector A(), each byte being 0 (empty square), 1 (computer's piece) or 2 (human player's piece).
The 201-byte vector S() is used to hold previously encountered board positions and the possible moves which did not lead to disaster. Each board position is represented by three bytes, which give the states of the three columns of the board, each coded to have a value of 64 to 127 (as X, Y & Z in lines 320-340). These are followed by single byte representations of the possible moves (if any) from that position coded as values from 128 to 255 (see lines 430 & 520). The end of the list is signalled by a zero byte. When the computer finds itself in a losing position, it removes the move that lead to defeat from the list (line 710).
The learning process is simplified by allowing the computer to recognise 'reflections' of board positions - thus when searching the list to see if it has played from that position before line 380 sets U=1 if it finds the mirror image position, and lines 520 to 560 subsequently invert the move selected.
When a new position is encountered, it is added to the list by line 410, then the program examines all possible from that position and adds legal ones to the list (lines 420-440).
Text; 1K
VDU; ½K
Integer
Drive is a game in which you have to steer a rapidly moving object through a course that is gradually filled with white and grey squares. The grey squares represent the enemy targets; if you hit one it is destroyed and you gain a point. The white squares, however, are dangerous if you hit one it will explode, killing you and scattering potentially lethal debris. You can survive 3 'deaths' before the game ends - and gain an extra 'life' for every 10 grey blocks hit.
The REPT and SHIFT keys are used for steering, moving you up and down the screen respectively. When the game ends (because you have run out of lives') press the space bar to play another. While the game is in progress three numbers across the top of the screen show (from left to right) your current score of grey blocks zapped, the number of lives you have left, and the best score to date in previous games.
Abbreviations have been used wherever possible to fit the program into 1K text RAM.
Line 20 draws the top and bottom boundaries of the course.
The main body of the program is within the loop between lines 30 and 999. An inner loop (lines 40-110) moves the object across the screen, using subroutine p to check for collision with a white square, and line 70 to see if you have destroyed a grey one. The program branches to see if you are killed; to PLOT the debris from the explosion and to see if you have any lives left. If you are still alive, line 100 plots your new position, and lines 102,104 test the state of the SHIFT and REPT keys.
Text; 2K
VDU; ½K
Integer
This program plots graphs of your physical (P), emotional (E) and intellectual (I) cycles for a four-week period.
As well as showing the ups and downs of your biological cycles, the graphs also warn of those critical days when a cycle is crossing through the centre line. For a finale, the program calculates how many days you have lived.
The program is based on the assumption that your cycles follow sine-wave patterns with periods of 23, 28 and 33 days, staring from your birth.
Text; 2K
VDU; ½K
Integer
And now to prove that the computer has an educational value. Sums Tester provides an exercise in simple mental arithmetic by posing 10 questions to be answered in 60 seconds. The questions involve simple addition and subtraction of numbers from 1 to 99 (no negative answers), and multiplication and division using factors up to 12, and are chosen at random by the program.
If you don't finish within the time allowed, the test ends; in any case your score and the total time taken to answer are shown at the end of the test.
The program loops between lines 200 and 540 ten times; each time line 300 decides whether the question is to involve addition, subtraction, multiplication or division, and calls one of the subroutines starting at lines 1000, 1100, 1200 and 1300.
Lines 9000-9080 are two machine language routines similar, to those in the 'Keyboard Timeout' program given elsewhere in this book, which increment a counter (locations #80,#81) every 1/60th of a second while the program is waiting for an answer. The counter is preset to (-T) seconds at the start of the program by line 110. If the counter times out (by reaching zero), the machine-language routine executes a BRK instruction which - because of line 120 - makes the program jump immediately to line 700.
Lines 400-450 get the answer to each question as a string and convert that to a number if possible. If the input cannot be a number then the program goes back to line 400 to ask again. This approach is used in preference to a simple 'INPUT Z' because it prevents the program crashing if the user gives a non-numeric response (such as just pressing the Return key), and it also stops him cheating by for example answering "WHAT IS 63+38" by "63+38".
Text; 2K
VDU; ½K
Integer
Scramble is a computer version of the old sliding letter square puzzle, in which you have to re-arrange 24 letters in a 5 x5 board by moving one letter at a time into the empty square.
When the program is run, it first shows you the board with the letters in order. It then scrambles them according to the degree of difficulty you have chosen for the game. You then have to restore the board to its original ordered form in less than 100,000 moves.
The letters are stored directly in the appropriate VDU RAM locations, lines 130-160 set up the initial (ordered) board with the letters A-X and a blank position.
Lines 300-370 then 'scramble' the board by making 5xD moves (D being the degree of difficulty chosen for the game); the array DD(3) being used to hold the four possible movements from any position J. Line 350 checks that the computer does not attempt to move outside of the playing area, and that it does not attempt to move the same piece two times running when scrambling the board.
Lines 420-460 get your move and check that it is legal. Lines 470-490 then make your move on the screen, highlighting the positions you are moving between, then lines 500-540 see if you have put the board back into its correct order. If not, the program branches to line 600 and so back for your next move.
Lines 900-930 form a subroutine which is used to clear the bottom part of the screen and re-position the text cursor ready for the next move.
Text; 1k
VDU; 6K
Integer
Three short programs that use the highest resolution graphics mode to generate attractive moiré patterns each program can produce a number of different designs, a fresh one being drawn each time a key is pressed.
Text; 4K
VDU ½K
Integer
This is a game for the brave and adventurous. You are hunting the dread Wampus, in the pitch-black depths of his cave kingdom, armed only with a bow and five arrows. Super strong bats also inhabit the caves, and though they will not harm you directly, they may make you lose the trail by carrying you off to another cave - and that might be the one with the bottomless pit! Good hunting, and don't run out of arrows.
The body of the program is the loop from lines 120 to 400. Lines 120-230 show which cave you are in (W), and which you can move to (S,U,V). Lines 231,245 directly examine the keyboard keys 1 and 2 to see if you want to shoot or move to another cave. If you decide to move, lines 260-270 find out which cave you want to move to and check that this is possible.
Having moved you, the program then uses lines 290-310 to warn you of any dangers lurking in adjacent caves (X is the cave occupied by the Wampus that infested by superbats, and Z is that without a floor). If you had entered the cave of the bottomless pit, line 320 drops you in it. Lines 340-370 activate the bats when you intrude upon them. If the Wampus is next door, lines 410-450 decide whether he will eat you or merely move away.
When you decide to shoot, lines 600-618 find out which caves you will shoot through - and note them in AA(). Lines 619-910 then tell you what - if any - effect your shot has had.
Text; 1k
VDU; ½K
Integer
The Simon of legend said "Do what I do". In this musically accompanied game, ATOM says "Remember the sequence of letters I flash onto the screen, then press the same sequence of keys". If you do well, ATOM will gradually increase the number of letters displayed each time, but if you consistently fail to remember, then ATOM will give up in disgust.
A small machine language routine (lines 120-140) is used to provide the musical accompaniment by generating a short note of a pitch determined by the value put into the RAM location 80.
The main body of the program is the loop through lines 200 to 390, an inner loop (lines 220-250) chooses and displays the sequence of N letters, saving them as the string $S. If the player answers incorrectly, lines 320-330 show him what he should have entered.
Text; 2K
VDU; 2-6K
Integer
This program is useful as a lecture aid, as an advertising gimmick, or as an auto-banner for Computer Lib demonstrations, as it allows you to create a number of text 'screens' in RAM, to edit them as required, and to play them through at any rate. It will also save the screens to a tape file, and subsequently load them back into RAM.
The number of screens that can be used is limited by the amount of VDU RAM available; the minimum useable amount of 2K bytes gives 3 screens - while an ATOM fitted with the full 6K bytes of VDU RAM can handle 11 screens.
When the program is first run the screens are cleared, then a 'menu' is presented. You may then enter;
When the program is started it calls the subroutine at line 9000 which modifies ATOM's normal keyboard read and BRK routines so that pressing the ESC key does not stop the program, but makes it jump to line 8000 instead
The screens are stored in the VDU RAM space above 81FF, this area being otherwise unused when the VDU is in text mode. Lines 100-140 fill this area with the VDU 'space' code and also count the number (S) of 512 byte blocks available for use as screens.
Lines 200-295 present the menu - and refuse to accept anything except a valid response from the user. If a screen number is entered the program jumps to line 1000 with T equal to the number of the selected screen. This screen is then copied into the visible area of the VDU RAM space (8000 - 81FF) by lines 1000, 1010 and the cursor positioned at the top left corner by line
1020. Line 1030 allows you to type onto the screen by repeatedly calling the (now modified) Operating System OSECHO routine.
Lines 2000-2150 are executed if you have chosen to Play through the screens; line 2120 being used to bring the appropriate screen into the viewing area.
Lines 3000-3060 save selected screens as a file on tape by using the Operating System OSSAVE routine - after getting the new file's name and setting up the appropriate data for the OSSAVE routine (lines 3020-3050). Lines 4000-4020 similarly use the OSLOAD routine to load a tape rile of screens into RAM.
Lines 6000-6020 are a subroutine which is used to convert an input string $Z to a number Z; if $Z cannot be interpreted as a number then the subroutine returns T as 0.
When the ESC key is pressed the program jumps to lines 8000-8030 which remove the cursor (line 8000), then if the program had been in Edit mode, the screen is saved in the appropriate area of RAM before branching back to line 200 to display the menu.
HangmanText; 2K |
This is a computerised version of the word guessing game; Hangman. The computer picks a word, shows you how many letters it has, and then you try to guess the letters one at a time. If the letter you choose is in the word, the computer shows you where, but it you are wrong then the computer starts to hang you. For each mistake, the computer fills in part of a drawing of you dangling from a gallows. The ninth mistake is fatal.
1 REM HANGMAN 10 DIM W(20), R(1); N = 10 20 CLEAR 0; GOTO 10050a*CAMBRIDGE*ATOM*FIEND*SLAYS 51 *FOREIGN*MICRO*DURING*PIZZA 52 *EATING*COMPETITION100 X = ?18 * 256; D = #D; Y = CH "A" 110 DO DO X = X + 1; UNTIL ?X = D; UNTIL X?3 = Y 120 X = X + 3; Y = CH "X" 100 X = ?18 * 256; D = #D; Y = CH"A" 110 DO DO X = X + 1; UNTIL ?X = D; UNTIL X?3 = Y 120 X = X + 3; Y = CH "*" 130 FOR P = 1 TO 1+ABS RND % N 140 D0 X = X+1; IF ?X = D X = X+3 150 UNTIL ?X = Y; X = X+1 160 NEXT P; Z = 0 170 DO W?Z = X?Z; Z = Z+1 180 UNTIL X?Z = D OR X?Z = Y OR X?Z = CH" " 190 W?Z = D 200 FOR X = 1 TO LEN(W); X?#80F0 = #2E; NEXT 210 MOVE 0,9; DRAW 24,9 220 E = 0 300 DO !#DE = #81C0 310 P. "LETTER "$8$8$8; INPUT $R 320 UNTIL ?R>CH"@" AND ?R < CH"[" 400 X = 1 410 IF X?#80F0=#2E IF ?R = W?(X-1) GOTO 600 420 IF X<LEN(W) X = X+1; GOTO 410 430 GOSUB(1000+100*E); E = E+1 500 !#DE = #8111; P. $W 510 !#DE = #81C0; P. "<** YOU ARE dead !!! **" 520 ?#E1 = #80; END 530 END600 X ? #80F0 = ?R - 40; C = 0 610 FOR X = 1 TO LEN(W) 620 IF X?$80F0 = #2E C = 1 630 NEXT X; IF C = 1 GOTO 300 700 CLEAR 0; MOVE 16,40 710 GOSUB 1100; GOSUB 1500; GOSUB 1600 720 GOSUB 1700; GOSUB 1800 730 MOVE 16,32; DRAW 24,40 710 MOVE 0,8; DRAW 63,8 750 !#DE = #80F1; P.$W 760 !#DE = #81C0; P."< ** A REPRIEVE !! ** " 770 ?#E1 = #80.; END 1000 MOVE 0,6; DRAW 0,47; RETURN 1100 MOVE 0,38; DRAW 9,47; RETURN 1200 MOVE 0,47; DRAW 16,47; RETURN 1300 DRAW 16,40; RETURN 1400 DRAW 14,40; DRAW 14,36; DRAW 18,36 1410 DRAW 18,40; DRAW 16,40; RETURN 1500 MOVE 16,36; DRAW 16,24; RETURN 1600 DRAW 8,10; RETURN 1700 MOVE 16,24; DRAW 24,10; RETURN 1800 MOVE 16,32; DRAW 8,40; RETURN 1900 MOVE 3,9; PLOT 7,24,9 1910 MOVE 8,10; PLOT 16,24; PLOT 6,24,10 1920 MOVE 14,8; DRAW 16,24; MOVE 18,8;DRAW 16,24 1930 MOVE 8,40; PLOT 6,16,32; DRAW 13,22 1940 MOVE 16,32; DRAW 19,22; RETURN
The list of words used is stored in lines 50-52, and may be changed as long as each word is preceded by a *, and N (line 10) is made equal to the number of words in the list.
When the program is run, lines 100-120 look through the text area for the * immediately following the label a. Lines 130-160 then search for the start of a randomly chosen word, and lines 170-190 copy it as a string into the byte vector W. Lines 200-220 put a line of dots onto the screen, corresponding to the number of letters in the word, and draw the stage of the gallows.
The body of the program is the loop through lines 300-440, which gets the letter you have chosen, then sees if it is in the word (lines 400-420). If it isn't, then lines 430,440 draw the next stage of your execution and - if you are still alive - go back to line 300 for your next guess. After the ninth mistake, lines 500-530 declare you dead. Note line 300, which sets the text cursor position to the start of the 14th line and turns the cursor off.
If you have guessed a letter correctly, lines 600-630 display it and see if you have completed the word. If so, your reprieve is granted via lines 700-770, if not then back to line 300.
Lines 1000-1940 are a series of subroutines used to draw various parts.