Dice and Train

See all articles from SYNC v2 n1

[Figure: Drawing of a pair of dice]

I recently got a copy of Creative Computing’s Basic Computer Games and of More Basic Computer Games to find more challenge for my 8K ROM and 16K RAM ZX80, but before turning to the really long programs I could not resist trying to squeeze two of the smaller ones into 1K for the 8K ROM. The results are given below. In both cases the screen prompts will ask for INPUT which should be followed by NEWLINE.

Dice strictly speaking is not a game. By simulating the throw of a pair of dice, the computer calculates the distribution of the number of throws entered according to the number of spots the dice show. Be prepared for a wait if you enter a number like 5000.

Train likewise is not exactly a game, but rather a challenge to balance time, speed, and distance factors. You have a chance to do some mental calculation and then have the computer tell you how close you came to being right.

Listing 1. Dice

   5 RAND
10 DIM F(12)
80 FOR Q=1 TO 12
90 LET F(Q)=0
100 NEXT Q
105 CLS
110 PRINT "HOW MANY ROLLS?"
120 INPUT X
125 PRINT X
130 FOR S=1 TO X
140 LET R=INT (6*RND+1)+INT (6*
RND+1)
170 LET F(R)=F(R)+1
180 NEXT S
190 PRINT "TOTAL SPOTS","NO. OF
TIMES"
200 FOR V=2 TO 12
210 PRINT V,F(V)
220 NEXT V
222 PRINT "TRY AGAIN?"
223 INPUT Z$
224 IF Z$="YES" THEN GOTO 80

Sample Run

HOW MANY ROLLS?
100
TOTAL SPOTS     NO. OF TIMES
2               1
3               8
4               12
5               11
6               11
7               11
8               14
9               10
10              8
11              10
12              4
TRY AGAIN?

Listing 2. Train

   5 CLS
10 LET C=INT (25*RND)+40
15 LET D=INT (15*RND)+5
20 LET T=INT (19*RND)+20
25 PRINT AT 6,2;"A CAR TRAVELI
NG ";C;" MPH CAN","MAKE A TRIP I
N ";D;" HR LESS THAN"
30 PRINT "A TRAIN TRAVELING AT
";T;" MPH."
35 PRINT " HOW LONG WOULD IT T
AKE BY CAR?"
40 INPUT A
45 LET V=D*T/(C-T)
50 LET E=INT (ABS ((V-A)*100/A
)+.5)
55 IF E>5 THEN GOTO 70
60 PRINT "GOOD ANSWER WITHIN "
;E;" PERCENT."
65 GOTO 80
70 PRINT "SORRY. OFF BY ";E;"
PERCENT"
80 PRINT "ANSWER IS ";V;" HR."
85 PRINT "AGAIN? (Y OR N)"
90 INPUT A$
95 IF A$="Y" THEN RUN

Sample Run

 A CAR TRAVELING 41 MPH CAN
MAKE A TRIP IN 14 HR LESS THAN
A TRAIN TRAVELING AT 37 MPH.
 HOW LONG WOULD IT TAKE BY CAR?
GOOD ANSWER WITHIN 2 PERCENT.
ANSWER IS 129.5 HR.
AGAIN? (Y OR N)

(INPUT YOUR GUESS: 120)

[Figure: Drawing of a steam locomotive]

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