This program simulates rolling one to five dice, displaying each die face using inverse-video characters stored in a two-dimensional string array. The array D$(6,9) holds six 9-character strings, each representing a 3×3 dot pattern for die faces one through six; the program slices each string into three 3-character rows using a FOR loop with STEP 3 to print the face grid. Random die values are generated with INT(1+6*RND). Input validation caps the number of dice at five, citing display width limitations, and entering zero exits the program gracefully.
Program Analysis
Program Structure
The program divides into four logical phases:
- Initialisation (lines 1–60): Clears the screen, dimensions the die-face array, and populates all six entries.
- Introduction (lines 62–70): Prints instructions and prompts for the number of dice.
- Rolling loop (lines 100–700): Accepts input, validates it, rolls the requested dice, and loops back to the prompt.
- Exit / error handlers (lines 1000–2050): Handles the >5 error message, the farewell screen, and housekeeping.
Die-Face Representation
Each die face is stored as a 9-character string in the array D$(6,9). The characters are arranged as three rows of three, where %O represents an inverse “O” (a pip) and % represents an inverse space (blank). This gives a visually clean 3×3 grid when printed.
| D$ index | Face value | Pattern (3×3) |
|---|---|---|
| 1 | 1 | · · · / · ● · / · · · |
| 2 | 2 | ● · · / · · · / · · ● |
| 3 | 3 | ● · · / · ● · / · · ● |
| 4 | 4 | ● · ● / · · · / ● · ● |
| 5 | 5 | ● · ● / · ● · / ● · ● |
| 6 | 6 | ● · ● / ● · ● / ● · ● |
String-Slicing Technique
The rendering loop at lines 510–530 is the key idiom. Rather than storing three separate strings per face, the entire 9-character face is stored in one string and sliced into rows using FOR Y=1 TO 9 STEP 3, printing D$(B,Y TO Y+2) each iteration. This is an efficient use of the ZX81 substring notation and keeps array dimensioning simple.
Random Number Generation
Line 500 uses INT(1+6*RND) to produce an integer in the range 1–6 inclusive. This is the standard ZX81 BASIC idiom for a fair die roll; RND returns a value in [0,1) so the expression maps correctly onto {1,2,3,4,5,6}.
Input Validation
Validation is minimal but functional. Line 300 checks for zero to exit, and line 310 catches values greater than five and redirects to an explanatory message at line 1000 before looping back. There is no guard against negative numbers or non-integer input; entering a negative value would pass both checks and cause FOR X=1 TO A to execute zero iterations (the ZX81 executes a FOR…NEXT loop at least once only when the limit is already exceeded before entry — actually on the ZX81 a FOR loop with limit less than start does not execute the body), silently producing no output before returning to the prompt.
Notable Anomalies
- Line 310 uses
IF A>5but the instructions say “less than 5”; entering exactly 5 is valid and works, but the error message at line 1010 says “choose numbers less than 5” — this is contradictory and should read “5 or less”. - Line 750 (
STOP) is unreachable; the flow from line 700 (GOTO 70) never falls through to it. - Lines 2030–2050 (
CLEAR,SAVE,RUN) follow aSTOPat line 2020 and are therefore only reachable by directGO TOor by the user continuing after the STOP — they appear to be developer/distribution utilities left in the listing. - The farewell signature at line 2010 prints
1/83/%A%W, encoding a date (January 1983) and the author’s initials in inverse video.
Content
Source Code
1 REM "DICE PROGRAM" BY ANTHONY WILLING
3 CLS
5 DIM D$(6,9)
10 LET D$(1)="% % % % %O% % % % "
20 LET D$(2)="%O% % % % % % % %O"
30 LET D$(3)="%O% % % %O% % % %O"
40 LET D$(4)="%O% %O% % % %O% %O"
50 LET D$(5)="%O% %O% %O% %O% %O"
60 LET D$(6)="%O% %O%O% %O%O% %O"
62 REM "DICE PROGRAM"
64 PRINT "I AM A DICE ROLLING PROGRAM"
65 PRINT
66 PRINT "I WILL ROLL FROM 1-5 DICE FOR YOU, AT RANDOM"
67 PRINT
68 PRINT "IF YOU ENTER A <0> AS THE CHOICEI WILL STOP ROLLING DICE"
69 PRINT
70 PRINT "HOW MANY DICE DO YOU WISH TO ROLL?"
100 INPUT A
200 CLS
300 IF A=0 THEN GOTO 2000
310 IF A>5 THEN GOTO 1000
400 FOR X=1 TO A
500 LET B=INT (1+6*RND)
510 FOR Y=1 TO 9 STEP 3
520 PRINT D$(B,Y TO Y+2)
530 NEXT Y
540 PRINT
600 NEXT X
700 GOTO 70
750 STOP
\n1000 PRINT "SORRY, MY DISPLAY CAN ONLY SHOW 5 DICE AT A TIME"
\n1005 PRINT
\n1010 PRINT "PLEASE CHOOSE NUMBERS LESS THAN 5, DOING SO UNTIL YOUR DESIRED TOTAL IS REACHED"
\n1015 PRINT
\n1020 GOTO 70
\n2000 PRINT AT 11,9;"<THANK YOU>"
\n2010 PRINT AT 20,18;"1/83/%A%W"
\n2020 STOP
\n2030 CLEAR
\n2040 SAVE "1020%2"
\n2050 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

