Dice

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

This program implements a two-player dice game where the user competes against the computer over 10 rolls, with the highest cumulative score winning. The player rolls by pressing ENTER to stop an animated spinning die, while the computer rolls automatically using a random number generator. Die faces are rendered using dot characters printed at fixed screen positions via AT coordinates. The computer’s roll subroutine is selected through a calculated GOSUB using the expression `(200+10*INT(RND*6))`, jumping directly to one of six face-display routines at lines 200–250.


Program Analysis

Program Structure

The program is organised into a main game loop and a set of subroutines. Initialisation occurs at lines 5–11, the game loop runs from lines 25–60, and line 100 halts execution. The subroutine at lines 180–199 handles the player’s roll (animated die with ENTER to stop), and lines 200–255 contain six individual die-face display routines, one per pip value.

LinesPurpose
5–11Title print, initialise scores M (player) and Y (computer) to 0
20Draw static screen layout with column headers
25–60Main FOR loop, 10 iterations
180–199Player roll subroutine — animated spinning die, stopped by ENTER
200–255Six die-face display routines, each setting D and RETURNing
300–310SAVE and RUN (program re-launch)

Calculated GOSUB Technique

Both the player animation loop (line 190) and the computer’s roll (line 50) use a calculated GOSUB expression: GOSUB (200+10*INT(RND*6)). This evaluates to one of 200, 210, 220, 230, 240, or 250, directly calling the appropriate die-face subroutine. This is an efficient idiom that replaces what would otherwise require a multi-branch IF/THEN chain, saving lines and execution time.

Die Face Rendering

Each die face is drawn using two rows of three characters printed with AT coordinates. Pips are represented by the period character (.) and blanks as spaces, within a fixed 3×2 character cell at columns 13–15, rows 10–11. A surrounding box border is drawn at lines 185 once per player turn.

LineDie ValueRow 10 (cols 13–15)Row 11 (cols 13–15)
2001" . "" "
2102" . "" . "
2203".. "" . "
2304".. "".. "
2405"..."".. "
2506"...""..."

Player Input Idiom

The player’s roll animation at lines 190–192 uses a tight loop: GOSUB (200+10*INT(RND*6)) picks and displays a random face, then line 192 checks IF INKEY$="" THEN GOTO 190. This continues cycling through random die faces until any key is held, at which point the loop exits and the displayed face value (stored in D) is used. This is a classic Sinclair BASIC spinning-die idiom without requiring a PAUSE statement.

Score Tracking

Player score is accumulated in M and computer score in Y, both initialised to zero at lines 10–11. After each pair of rolls, both totals are printed at fixed AT positions in line 30 and line 45. No win/loss comparison or message is displayed at line 100 — execution simply stops, leaving the final scores visible on screen for the player to judge.

Bugs and Anomalies

  • The program never compares M and Y at the end, so no winner is announced — the player must read the scores manually after STOP at line 100.
  • The die border drawn at line 185 uses strings of different lengths (" " at row 12 is 8 characters while others are 6), creating a slightly uneven box.
  • Line 300 contains a SAVE followed by RUN at line 310, providing a convenient way to both save and immediately restart the game.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10051 – 10121.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   5 PRINT "   DICE"
  10 LET M=0
  11 LET Y=0
  20 PRINT AT 0,2;"HIGHEST SCORE IN 10 ROLLS WINS";AT 2,5;" YOU         ME "
  25 FOR I=1 TO 10
  30 PRINT AT 3,6;M;AT 3,19;Y;AT 16,11;"YOUR ROLL."
  35 GOSUB 180
  40 LET M=M+D
  45 PRINT AT 3,6;M;AT 16,10;" MY ROLL.     "
  50 GOSUB (200+10*INT (RND*6))
  55 LET Y=Y+D
  60 NEXT I
 100 STOP 
 180 PRINT AT 18,0;"PRESS ENTER TO STOP THE DICE."
 185 PRINT AT 9,12;" DICE ";AT 10,12;"      ";AT 11,12;"      ";AT 12,12;"        "
 190 GOSUB (200+10*INT (RND*6))
 192 IF INKEY$="" THEN GOTO 190
 199 RETURN 
 200 PRINT AT 10,13;" . ";AT 11,13;"   "
 202 LET D=1
 205 RETURN 
 210 PRINT AT 10,13;" . ";AT 11,13;" . "
 212 LET D=2
 215 RETURN 
 220 PRINT AT 10,13;".. ";AT 11,13;" . "
 222 LET D=3
 225 RETURN 
 230 PRINT AT 10,13;".. ";AT 11,13;".. "
 232 LET D=4
 235 RETURN 
 240 PRINT AT 10,13;"...";AT 11,13;".. "
 242 LET D=5
 245 RETURN 
 250 PRINT AT 10,13;"...";AT 11,13;"..."
 252 LET D=6
 255 RETURN 
 300 SAVE "1007%1"
 310 RUN 

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

People

No people associated with this content.

Scroll to Top