Resolves battles for the Risk board game. The players enter the number of attacking and defending armies; the program sets the attacker’s dice at three and the defender’s at two, fewer if there are fewer armies left, and then fights the whole battle in FAST mode. It rolls, sorts each side’s dice from high to low, compares the pairs with ties going to the defender, and removes armies until one side has none. It then reports who won, the armies left on each side and the last roll. The listing also holds two features this version never reaches: urgent messages from the capitol and mercenaries offered for sale.
The tape was provided by Alexander Bailess. According to him, his grandfather, wrote the program in the early 1980s to speed up the games of Risk they played every day after work. The full program added random events, announced as an urgent message from the capitol, such as caught spies, reinforcements and armies gained or lost. It also let players buy mercenaries at a price the computer set, paying real money into a pot that the winner took, usually about $20. This tape holds an abridged version; Bailess said the full version and tapes of poker and probability programs might follow.
Program Analysis
Program Structure
- 1–27: clear the counters, then go to the army entry at 8200.
- 8200–9570: enter army counts, set the dice (
NOfor offense,NDfor defense) and set the flagE=9, which selects automatic play. - 1000–1099: roll and sort up to three offense dice (
A,B,C) and two defense dice (Y,Z), compare them, and subtract losses fromAOandAD. WithE=9, display is skipped through line 1200 and the routine at 1300 reduces the dice as armies run low, looping until one side is gone. - 9600–9651: result screen; pressing ENTER alone starts a new battle setup.
- 200–252: the capitol message table, ten outcomes picked with
RND: a caught spy, stolen data, fresh reinforcements (three of the ten), an extra card, disease in the ranks, reinforcements for the opponent, a routine message, and an enemy spy caught. - 4000–4160: the mercenary market. One to five mercenaries are offered at
$MA, starting at $2; buying tells the player to pay the central bank and raises the price by half, while declining drops it by a random amount.
Notable Techniques
- Sorting is done with explicit swaps, which is simple for three dice and avoids an array.
- The same dice routine serves single, displayed rolls and the silent whole-battle mode, switched by the flag
E. - Line 9999 prints the program’s size from the
D_FILEsystem variable (PEEK 16396+256*PEEK 16397-16509).
Potential Issues
- Several jump targets are missing from this abridged copy (lines 500, 8000, 8105 and 9622); the ZX81 continues at the next existing line in each case, so 8105 lands on 8115 and restarts the program. Nothing jumps to line 79, so the message and mercenary routines are never called.
- The attacker can roll as many dice as it has armies, so all of its armies can attack, unlike the board game’s rule that one army stays behind.
Source Code
1 LET MA=2
2 SLOW
10 LET E=0
11 LET NO=0
12 LET ND=0
13 LET DL=0
14 LET AO=0
15 LET AD=0
16 LET A=0
17 LET B=0
18 LET C=0
19 LET DY=0
20 LET DZ=0
21 LET Y=0
22 LET Z=0
23 LET EE=0
25 LET OO=0
26 LET DD=0
27 GOTO 8200
79 GOSUB 4001
80 LET L=INT (RND*2)+1
81 IF L=1 THEN GOTO 90
82 IF L=2 THEN GOTO 96
90 PRINT "AN URGENT MESSAGE FROM THE CAPITOL DO YOU WANT TO READ IT?"
91 INPUT Y$
92 CLS
94 LET TTT=0
95 IF Y$="Y" THEN GOTO 200
96 LET TTT=1
99 CLS
100 IF TTT=0 THEN PRINT "FOR YOUR NEW BATTLE:"
101 IF TTT=0 THEN GOTO 8200
103 GOTO 8200
104 INPUT Y$
105 CLS
110 IF Y$="Y" THEN GOTO 8200
120 GOTO 8105
190 GOTO 8000
200 LET K=INT (RND*10)+1
202 IF K=1 THEN PRINT "ONE OF YOUR SPIES HAVE BEEN CAUGHT REMOVE(1) OF YOUR ARMYS"
203 IF K=2 THEN PRINT "YOUR SPY OBTAINED VALUABLE DATA REMOVE ANY(1)ARMY FROM THE BOARDTHAT HAS TWO OR MORE"
204 IF K=3 THEN PRINT "FRESH REINFORCMENT ADD(1)ARMY"
205 IF K=4 THEN PRINT "TAKE A CARD(DO NOT USE UNTIL YOUR NEXT TURN)PROCEED AS PLANNED"
206 IF K=5 THEN PRINT "YOUR TROOPS HAVE CONTRACTED VD REMOVE(1)ARMY"
207 IF K=6 THEN PRINT "REINFORCMENTS FOR YOUR OPPONENT HAVE ARRIVED YOU MAY ONLY ATTACKWITH 2 DICE"
208 IF K=7 THEN PRINT "FRESH REINFORCMENT ADD(1)ARMY"
209 IF K=8 THEN PRINT "FRESH REINFORCMENT ADD(1)ARMY"
210 IF K=9 THEN PRINT "ROUTINE MESSAGE NO ACTION"
211 IF K=10 THEN PRINT "ENEMY SPY HAS BEEN CAUGHT REMOVE ANY (1) ARMY FROM ANY COUNTRY THAT HAS 2 OR MORE ARMYS"
250 PRINT AT 10,2;"PRESS ENTER WHEN READY TO GO"
251 INPUT Q$
252 GOTO 99
1000 LET A=INT (RND*6)+1
1004 IF NO<=1 THEN GOTO 1050
1010 LET B=INT (RND*6)+1
1011 IF A>B THEN GOTO 1022
1012 IF A=B THEN GOTO 1022
1013 LET L=A
1014 LET A=B
1015 LET B=L
1016 LET L=0
1022 IF NO<=2 THEN GOTO 1050
1030 LET C=INT (RND*6)+1
1031 IF A>=C THEN GOTO 1039
1033 LET H=A
1034 LET L=B
1035 LET A=C
1036 LET B=H
1037 LET C=L
1038 GOTO 1050
1039 IF C<=B THEN GOTO 1050
1042 LET L=B
1043 LET B=C
1044 LET C=L
1045 LET L=0
1050 IF E=9 THEN GOTO 1054
1052 PRINT "OFFENSE DICE ROLL; ";A;"-";B;"-";C
1054 LET Y=INT (RND*6)+1
1055 IF ND=1 THEN GOTO 1061
1056 LET Z=INT (RND*6)+1
1057 IF Y>=Z THEN GOTO 1061
1058 LET L=Y
1059 LET Y=Z
1060 LET Z=L
1061 IF E=9 THEN GOTO 1200
1062 PRINT "DEFENSE DICE ROLL; ";Y;"-";Z
1064 GOSUB 1070
1065 RETURN
1070 IF A>Y THEN LET DD=1
1071 IF A<=Y THEN LET OO=1
1072 IF NO=1 THEN GOTO 1080
1073 IF ND=1 THEN GOTO 1080
1077 IF B>Z THEN LET DD=DD+1
1078 IF B<=Z THEN LET OO=OO+1
1080 PRINT ""
1081 IF DD>0 THEN PRINT "DEFENSE REMOVE ";DD
1082 IF OO>0 THEN PRINT "OFFENSE REMOVE ";OO
1083 PRINT ""
1084 LET AO=AO-OO
1086 PRINT "OFFENSE TOTAL =";AO
1087 LET AD=AD-DD
1088 PRINT "DEFENSE TOTAL =";AD
1090 LET OO=0
1091 LET DD=0
1092 IF AD<=0 THEN GOTO 9600
1093 IF AO<=0 THEN GOTO 9600
1094 LET B=0
1095 LET C=0
1096 LET Z=0
1097 IF E=9 THEN GOSUB 1300
1098 IF E=9 THEN GOTO 1000
1099 GOTO 8000
1200 IF A>Y THEN LET DD=1
1205 IF A<=Y THEN LET OO=1
1210 IF NO=1 THEN GOTO 1226
1215 IF ND=1 THEN GOTO 1226
1220 IF B>Z THEN LET DD=DD+1
1225 IF B<=Z THEN LET OO=OO+1
1226 LET AO=AO-OO
1227 LET AD=AD-DD
1230 GOTO 1090
1300 IF NO>AO THEN LET NO=AO
1301 IF ND>AD THEN LET ND=AD
1302 RETURN
4000 LET MA=2
4001 IF MA<=1 THEN LET MA=2
4006 CLS
4010 LET P=INT (RND*5)+1
4100 PRINT P;" MERCENARY ARMYS AVAILABLE FOR $";MA
4110 PRINT AT 16,1;"DO YOU WANT TO BUY?"
4115 INPUT Y$
4116 LET R=INT (RND*MA)+1
4117 CLS
4120 IF Y$="N" THEN LET MA=MA-R
4125 IF Y$="N" THEN GOTO 80
4130 CLS
4139 PRINT " ";P;" MERCENARIES"
4140 PRINT "$";MA
4141 PRINT "TRANSFER GOLD OR CURRENCY TO THECENTRAL BANK-PLACE YOUR MERCENARIES WHERE YOU WANT THEM"
4142 PRINT ""
4143 PRINT "PRESS ENTER WHEN READY TO BEGIN"
4144 INPUT Q$
4150 LET MA=INT (MA*1.5+.6)
4151 CLS
4160 RETURN
5000 CLS
5002 FAST
5004 GOTO 9570
5005 INPUT Y$
5010 IF Y$="N" THEN GOTO 5012
5011 GOTO 5020
5012 LET Y$="Y"
5013 GOTO 5080
5020 LET AOO=AO
5021 LET ADD=AD
5022 LET NOO=NO
5023 LET NDD=ND
5030 LET E=9
5035 LET EE=9
5040 GOSUB 1000
5050 LET AO=AOO
5051 LET AD=ADD
5052 LET NO=NOO
5053 LET ND=NDD
5054 LET EE=0
5055 LET E=0
5060 PRINT "THIS BATTLE HAS NOT BEEN FOUGHT ------DO YOU WISH TO ENGAGE?----"
5070 INPUT Y$
5072 CLS
5073 IF Y$="N" THEN SLOW
5074 IF Y$="N" THEN GOTO 9622
5080 IF Y$="Y" THEN LET E=9
5081 IF E=9 THEN FAST
5090 IF Y$="Y" THEN GOTO 9570
5094 CLS
5095 GOTO 2
8001 PRINT "DO YOU WISH TO REENGAGE THE ENEMY?"
8002 INPUT Y$
8003 CLS
8004 LET DY=0
8005 LET DZ=0
8006 IF Y$="N" THEN GOTO 9622
8007 IF E>=8 THEN GOTO 8261
8008 IF Y$="Y" THEN LET E=8
8009 IF E=8 THEN GOTO 8261
8015 GOTO 9622
8115 CLS
8116 GOTO 2
8200 PRINT "HOW MANY ARMYS FOR THE OFFENSE?"
8201 FAST
8204 LET DY=0
8205 LET DZ=0
8210 INPUT AO
8215 PRINT AO
8250 PRINT "HOW MANY ARMYS FOR THE DEFENSE?"
8257 INPUT AD
8260 PRINT AD
8261 IF AD=1 THEN LET ND=1
8262 IF NO>AO THEN LET NO=AO
8263 PAUSE 50
8265 FAST
9000 PRINT "HOW MANY DICE FOR THE OFFENSE?"
9001 LET NO=3
9005 IF NO>AO THEN LET NO=AO
9010 PRINT NO
9500 PRINT "HOW MANY DICE FOR THE DEFENSE?"
9503 IF AD<=1 THEN LET ND=1
9504 IF AD<=1 THEN GOTO 9511
9510 LET ND=2
9511 IF ND>2 THEN LET ND=2
9512 IF ND<1 THEN GOTO 9500
9515 PRINT ND
9564 LET E=9
9570 GOTO 1000
9600 IF AO<0 THEN LET AO=0
9601 IF AD<0 THEN LET AD=0
9602 CLS
9603 IF AO<=0 THEN PRINT "DEFENSE WINS WITH ";AD;" ARMYS LEFT OFFENSE ";AO
9605 IF AD<=0 THEN PRINT "OFFENSE WINS WITH ";AO;" ARMYS LEFT DEFENSE ";AD
9606 PRINT "LAST ROLL WAS OFFENSE ";A;"-";B;"-";C;" DEFENSE ";Y;"-";Z
9607 LET B=0
9608 LET C=0
9609 LET Z=0
9610 IF AO<=0 THEN GOTO 9620
9611 IF AD<=0 THEN GOTO 9620
9612 GOTO 500
9620 IF EE=9 THEN RETURN
9623 LET E=0
9627 LET DY=0
9628 LET DZ=0
9629 PRINT AT 13,0;"PRESS ENTER TO CONTINUE"
9630 INPUT Y$
9631 CLS
9638 IF Y$="" THEN GOTO 9650
9639 LET E=0
9640 GOTO 8200
9650 CLS
9651 GOTO 8105
9999 PRINT PEEK 16396+256*PEEK 16397-16509Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.