Yahtzee

Developer(s): Arthur Marzano
Date: 1985
Type: Program
Platform(s): TS 1000, TS 2068
Tags: Dice

Rolls five dice for up to four players in turn, drawing each die from block graphics and keeping a full scorecard with aces through sixes, the upper-section total and 35-point bonus at 63, three and four of a kind, full house, small and large straights, Yahtzee and chance. Each player takes three rolls per turn, choosing which dice to reroll by number, and then types the category name and the points earned; the program trusts the player to enter the correct value and calls itself an “honor program”. After 13 turns the grand total is stored, the next player gets a fresh card, and when all four have played a summary shows every player’s score.

Both versions open with a REM credit to Arthur B. Marzano, “YAHTZEE (c)1985”. The TS1000 version, on a Maxell cassette labeled by hand “T/S 1000 Version” and “YAHTZEE”, runs in black and white with inverse-video prompts. The TS2068 version is a color conversion with a green dice table, a scorecard ruled with PLOT and DRAW, and BEEP rattles for each roll. The game was published in SyncWare News, May/June 1987.

Program Analysis

Program Structure

  • Initialization: four two-byte score slots are cleared in memory (30000–30008 on the TS1000, 50000–50008 on the TS2068), and the dice faces are loaded into the array D$(6,5,4), from LET statements on the TS1000 and from DATA on the TS2068.
  • Scorecard: category names are sliced from two strings, A$="ACESTWOSTHREES..." and B$="3 OF A KIND4 OF A KIND...", and scores are kept in A1–A6 and B1–B7.
  • Turn loop: roll all five, keep, second roll, keep, third roll, then score; after 13 turns the total goes to the player’s memory slot.
  • Scoring: the typed category is compared against the same string slices used to print the card, so it has to match exactly; matching calls a routine that asks for the value.

Notable Techniques

  • Each die face is four strings of block graphics, printed down a column at C*5, so all five dice share one drawing loop.
  • Final scores are stored with POKE as low and high bytes and read back with PEEK a+256*PEEK (a+1), which survives starting a new player’s card.
  • The select loops use the same variable for the loop counter and the input (FOR K=1 TO H then INPUT K), so typing the highest die number ends the loop early. The instructions warn players to enter dice in order for this reason.
  • Keeping dice only marks them on screen (an inverse digit on the TS1000, a cyan overlay with OVER 1 on the TS2068); the reroll step asks separately which dice to throw.

Potential Issues

  • Nothing stops a category from being used twice or a wrong score from being entered.
  • On the TS1000 the number of dice to roll or keep is not range-checked, so a value above 5 asks for more dice than exist.

Related Articles

Yahtzee is a poker-style dice game where each player tries to roll combinations to match the categories on the scorecard,...

Image Gallery

Source Code

  10 REM █[Y][A][H][T][Z][E][E]█[C][O][P][Y][R][I][G][H][T]█[1][9][8][5]
  20 REM █[B][Y]█[A][R][T][H][U][R]█[B][.]█[M][A][R][Z][A][N][O]██
  30 RAND 
  40 CLS
  50 LET Z=1
  60 LET Q=30000
  70 FOR F=30000 TO 30008
  80 POKE F,0
  90 NEXT F
 100 PRINT "█████████████████████████████████████[Y][A][H][T][Z][E][E]█[C][O][P][Y][R][I][G][H][T]█[1][9][8][5]███████████[B][Y]█[A][R][T][H][U][R]█[B][.]█[M][A][R][Z][A][N][O]██████████████████████████████████████"
 110 PRINT AT 10,0;" DO YOU NEED INSTRUCTIONS? Y/N "
 120 PAUSE 4E4
 130 IF INKEY$ ="Y" THEN GOSUB 2080
 140 GOSUB 790
 150 GOSUB 400
 160 GOSUB 580
 170 PRINT AT 12,1;A$(1 TO 4);TAB 14;B$(1 TO 11)
 180 PRINT TAB 1;A$(5 TO 8);TAB 14;B$(12 TO 22)
 190 PRINT TAB 1;A$(9 TO 14);TAB 14;B$(23 TO 32)
 200 PRINT TAB 1;A$(15 TO 19);TAB 14;B$(33 TO 40)
 210 PRINT TAB 1;A$(20 TO 24);TAB 14;B$(41 TO 48)
 220 PRINT TAB 1;A$(25 TO 29);TAB 14;B$(49 TO 55)
 230 PRINT TAB 1;"TOTAL: ";TAB 14;"CHANCE: "
 240 PRINT TAB 1;"BONUS: ";TAB 14;"TOTAL: "
 250 PRINT TAB 1;"TOTAL: ";TAB 14;"GRAND TOTAL: "
 260 LET X=0
 270 LET X=X+1
 280 IF X=14 THEN GOTO 2450
 290 GOSUB 1060
 300 GOSUB 1400
 310 GOSUB 1220
 320 GOSUB 1400
 330 PRINT AT 10,0;"████[P][L][A][Y][E][R]█";Z;"█[T][H][I][R][D]█[R][O][L][L][.][.][.]██████"
 340 PAUSE 50
 350 GOSUB 1240
 360 GOSUB 1530
 370 PRINT AT 2,6;"1";AT 2,11;"2";AT 2,16;"3";AT 2,21;"4";AT 2,26;"5"
 380 GOTO 270
 390 STOP
 400 PRINT AT 0,0;"█████████[Y]█[A]█[H]█[T]█[Z]█[E]█[E]██████████"
 410 FOR F=1 TO 10
 420 PRINT "█[▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒][▒]█"
 430 NEXT F
 440 PRINT "▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜"
 450 FOR F=12 TO 20
 460 PRINT AT F,0;"▌"
 470 PRINT AT F,31;"▐"
 480 NEXT F
 490 PRINT "▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟"
 500 LET L=4
 510 LET C=1
 520 FOR F=1 TO 4
 530 PRINT AT L,C*5;D$(1,F);AT L,(C+1)*5;D$(2,F);AT L,(C+2)*5;D$(3,F);AT L,(C+3)*5;D$(4,F);AT L,(C+4)*5;D$(5,F)
 540 LET L=L+1
 550 NEXT F
 560 PRINT AT 2,6;"1";AT 2,11;"2";AT 2,16;"3";AT 2,21;"4";AT 2,26;"5"
 570 RETURN
 580 LET A$="ACESTWOSTHREESFOURSFIVESSIXES"
 590 LET B$="3 OF A KIND4 OF A KINDFULL HOUSESMALL STLARGE STYAHTZEECHANCE"
 600 LET A1=0
 610 LET A2=0
 620 LET A3=0
 630 LET A4=0
 640 LET A5=0
 650 LET A6=0
 660 LET BONUS=0
 670 LET T1=0
 680 LET T2=0
 690 LET T3=0
 700 LET GT=0
 710 LET B1=0
 720 LET B2=0
 730 LET B3=0
 740 LET B4=0
 750 LET B5=0
 760 LET B6=0
 770 LET B7=0
 780 RETURN
 790 DIM D$(6,5,4)
 800 LET D$(1,1)="   ▐"
 810 LET D$(1,3)="   ▐"
 820 LET D$(2,2)="   ▐"
 830 LET D$(4,2)="   ▐"
 840 LET D$(1,2)=" ▗ ▐"
 850 LET D$(3,2)=" ▗ ▐"
 860 LET D$(5,2)=" ▗ ▐"
 870 LET D$(2,1)="  ▗▐"
 880 LET D$(3,1)="  ▗▐"
 890 LET D$(2,3)="▗  ▐"
 900 LET D$(3,3)="▗  ▐"
 910 LET D$(5,3)="▗  ▐"
 920 LET D$(4,1)="▗ ▗▐"
 930 LET D$(4,3)="▗ ▗▐"
 940 LET D$(5,1)="▗ ▗▐"
 950 LET D$(5,3)="▗ ▗▐"
 960 LET D$(6,1)="▗ ▗▐"
 970 LET D$(6,2)="▗ ▗▐"
 980 LET D$(6,3)="▗ ▗▐"
 990 LET D$(1,4)="▄▄▄▟"
1000 LET D$(2,4)="▄▄▄▟"
1010 LET D$(3,4)="▄▄▄▟"
1020 LET D$(4,4)="▄▄▄▟"
1030 LET D$(5,4)="▄▄▄▟"
1040 LET D$(6,4)="▄▄▄▟"
1050 RETURN
1060 PRINT AT 10,0;"████[P][L][A][Y][E][R]█";Z;"█[F][I][R][S][T]█[R][O][L][L][.][.][.]█████"
1070 PAUSE 4E4
1080 LET L=4
1090 LET C=1
1100 FOR F=1 TO 5
1110 LET I=1
1120 LET V=INT (RND*6)+1
1130 FOR J=1 TO 4
1140 PRINT AT L,C*5;D$(V,I)
1150 LET L=L+1
1160 LET I=I+1
1170 NEXT J
1180 LET C=C+1
1190 LET L=4
1200 NEXT F
1210 RETURN
1220 PRINT AT 10,0;"███[P][L][A][Y][E][R]█";Z;"█[S][E][C][O][N][D]█[R][O][L][L][.][.][.]█████"
1230 PAUSE 50
1240 PRINT AT 10,0;"██[U][P]█[T][O]█[W][H][I][C][H]█[N][O][.]█[D][I][E]█[T][O]█[R][O][L][L][?]██"
1250 INPUT H
1260 FOR K=1 TO H
1270 PRINT AT 10,0;"████[W][H][I][C][H]█[D][I][C][E]█[T][O]█[B][E]█[R][O][L][L][E][D]█[?]███"
1280 INPUT K
1290 LET C=K
1300 LET L=4
1310 LET I=1
1320 LET V=INT (RND*6)+1
1330 FOR J=1 TO 4
1340 PRINT AT L,C*5;D$(V,I)
1350 LET L=L+1
1360 LET I=I+1
1370 NEXT J
1380 NEXT K
1390 RETURN
1400 PRINT AT 10,0;"█[U][P]█[T][O]█[W][H][I][C][H]█[N][O][.]█[D][I][E]█[T][O]█[B][E]█[K][E][P][T][?]"
1410 INPUT H
1420 FOR K=1 TO H
1430 PRINT AT 10,0;"███[W][H][I][C][H]█[D][I][C][E]█[A][R][E]█[T][O]█[B][E]█[K][E][P][T]█[?]██"
1440 INPUT K
1450 LET C=K
1460 IF C=1 THEN PRINT AT 2,6;"[1]"
1470 IF C=2 THEN PRINT AT 2,11;"[2]"
1480 IF C=3 THEN PRINT AT 2,16;"[3]"
1490 IF C=4 THEN PRINT AT 2,21;"[4]"
1500 IF C=5 THEN PRINT AT 2,26;"[5]"
1510 NEXT K
1520 RETURN
1530 PRINT AT 10,0;"█████[I][N]█[W][H][I][C][H]█[C][A][T][E][G][O][R][Y]█[?]████████"
1540 INPUT H$
1550 IF H$=B$(23 TO 32) THEN GOSUB 2050
1560 IF H$=B$(23 TO 32) THEN LET B3=H
1570 IF H$=B$(23 TO 32) THEN PRINT AT 14,28;B3
1580 IF H$=B$(33 TO 40) THEN GOSUB 2050
1590 IF H$=B$(33 TO 40) THEN LET B4=H
1600 IF H$=B$(33 TO 40) THEN PRINT AT 15,28;B4
1610 IF H$=B$(41 TO 48) THEN GOSUB 2050
1620 IF H$=B$(41 TO 48) THEN LET B5=H
1630 IF H$=B$(41 TO 48) THEN PRINT AT 16,28;B5
1640 IF H$=B$(49 TO 55) THEN GOSUB 2050
1650 IF H$=B$(49 TO 55) THEN LET B6=H
1660 IF H$=B$(49 TO 55) THEN PRINT AT 17,28;B6
1670 IF H$=A$(1 TO 4) THEN GOSUB 2050
1680 IF H$=A$(1 TO 4) THEN LET A1=H
1690 IF H$=A$(1 TO 4) THEN PRINT AT 12,9;A1
1700 IF H$=A$(5 TO 8) THEN GOSUB 2050
1710 IF H$=A$(5 TO 8) THEN LET A2=H
1720 IF H$=A$(5 TO 8) THEN PRINT AT 13,9;A2
1730 IF H$=A$(9 TO 14) THEN GOSUB 2050
1740 IF H$=A$(9 TO 14) THEN LET A3=H
1750 IF H$=A$(9 TO 14) THEN PRINT AT 14,9;A3
1760 IF H$=A$(15 TO 19) THEN GOSUB 2050
1770 IF H$=A$(15 TO 19) THEN LET A4=H
1780 IF H$=A$(15 TO 19) THEN PRINT AT 15,9;A4
1790 IF H$=A$(20 TO 24) THEN GOSUB 2050
1800 IF H$=A$(20 TO 24) THEN LET A5=H
1810 IF H$=A$(20 TO 24) THEN PRINT AT 16,9;A5
1820 IF H$=A$(25 TO 29) THEN GOSUB 2050
1830 IF H$=A$(25 TO 29) THEN LET A6=H
1840 IF H$=A$(25 TO 29) THEN PRINT AT 17,9;A6
1850 IF H$=B$(1 TO 11) THEN GOSUB 2050
1860 IF H$=B$(1 TO 11) THEN LET B1=H
1870 IF H$=B$(1 TO 11) THEN PRINT AT 12,28;B1
1880 IF H$=B$(12 TO 22) THEN GOSUB 2050
1890 IF H$=B$(12 TO 22) THEN LET B2=H
1900 IF H$=B$(12 TO 22) THEN PRINT AT 13,28;B2
1910 IF H$=B$(56 TO 61) THEN GOSUB 2050
1920 IF H$=B$(56 TO 61) THEN LET B7=H
1930 IF H$=B$(56 TO 61) THEN PRINT AT 18,28;B7
1940 LET T1=A1+A2+A3+A4+A5+A6
1950 IF T1<63 THEN GOTO 1980
1960 IF T1>=63 THEN LET BONUS=35
1970 IF T1>=63 THEN PRINT AT 19,9;BONUS
1980 LET T2=T1+BONUS
1990 PRINT AT 18,9;T1;AT 20,9;T2
2000 LET T3=B1+B2+B3+B4+B5+B6+B7
2010 PRINT AT 19,28;T3
2020 LET GT=T2+T3
2030 PRINT AT 20,28;GT
2040 RETURN
2050 PRINT AT 10,0;"████[P][L][E][A][S][E]█[I][N][P][U][T]█[T][H][E]█[V][A][L][U][E][.]█████"
2060 INPUT H
2070 RETURN
2080 FAST
2090 CLS
2100 GOSUB 2380
2110 PRINT AT 1,1;"[O][N]█[E][A][C][H]█[1][S][T]█[R][O][L][L]█[P][R][E][S][S]█[N][E][W][L][I][N][E]██[T][H][I][S]█[R][O][L][L][S]█[A][L][L]█[T][H][E]█[D][I][C][E][.]█[A][F][T][E][R]██[T][H][E]█[D][I][C][E]██[A][R][E]█[R][O][L][L][E][D][,]█[Y][O][U]█[W][I][L][L]██[B][E]█[A][S][K][E][D]█[U][P]█[T][O]█[W][H][A][T]█[N][U][M][B][E][R]█[D][I][E]██[Y][O][U]██[W][I][S][H]██[T][O]█[K][E][E][P]█[-]█[I][N][P][U][T]█[T][H][E]██[L][A][S][T]█[N][O][.]█[D][I][E]█[T][H][A][T]█[Y][O][U]█[W][A][N][T]██[T][O]██[H][O][L][D]█[O][N]█[T][O][.]"
2120 PRINT 
2130 PRINT "█[T][H][E][N]█[E][N][T][E][R]█[T][H][E]█[D][I][C][E][,]█[I][N]█[O][R][D][E][R][,]██[T][H][A][T]█[Y][O][U]██[W][I][S][H]█[T][O]█[K][E][E][P]█[-]█[E][N][T][E][R]██[T][H][E]█[1][S][T]█[D][I][E]█[T][O]█[K][E][E][P][,]██[T][H][E][N]█[N][/][L]██[T][H][E][N]█[T][H][E]█[N][E][X][T][,]█[A][N][D]█[S][O]█[O][N][.]"
2140 PRINT 
2150 PRINT "█[B][E]█[S][U][R][E]█[T][O]██[E][N][T][E][R]█[T][H][E][S][E]█[I][N]█[T][H][E]██[P][R][O][P][E][R]█[S][E][Q][U][E][N][C][E]█[A][S]█[T][H][E]█[P][R][O][G][R][A][M]██[W][I][L][L]█[T][E][R][M][I][N][A][T][E]██[Y][O][U][R]█[R][O][L][L]█[W][H][E][N]██[T][H][E]█[L][A][S][T]█[N][O][.]█[D][I][E]█[I][S]█[I][N][P][U][T][.]"
2160 PRINT 
2170 PRINT "     ANY KEY TO CONTINUE...     "
2180 PAUSE 4E4
2190 CLS
2200 GOSUB 2380
2210 PRINT AT 1,1;"[W][H][E][N]█[Y][O][U][R]█[3]█[R][O][L][L][S]█[A][R][E]█[D][O][N][E]█[Y][O][U]██[A][R][E]█[A][S][K][E][D]██[W][H][I][C][H]██[C][A][T][E][G][O][R][Y]█[Y][O][U]██[W][A][N][T][.]██[E][N][T][E][R]█[T][H][I][S]██EXACTLY██[A][S]██[S][H][O][W][N]█[O][N]█[T][H][E]█[S][C][O][R][E][C][A][R][D][.][.][.]██[T][H][E]██[S][C][O][R][I][N][G]█[R][U][L][E][S]█[A][R][E][:]"
2220 PRINT 
2230 PRINT "██[A][C][E][S]█[T][O]█[S][I][X][E][S]█[-]█[A][D][D]█[O][N][L][Y]█[T][H][E]████[D][I][C][E]█[F][O][R]█[T][H][A][T]█[C][A][T][E][G][O][R][Y][.]"
2240 PRINT "██[3]█[A][N][D]█[4]█[O][F]█[A]█[K][I][N][D]█[-]█[T][O][T][A][L]█[O][F]████[A][L][L]█[D][I][C][E][.]"
2250 PRINT "██[F][U][L][L]█[H][O][U][S][E]█[-]█[2][5]"
2260 PRINT "██[S][M][A][L][L]█[S][T]█[-]█[3][0]"
2270 PRINT "██[L][A][R][G][E]█[S][T]█[-]█[4][0]"
2280 PRINT "██[Y][A][H][T][Z][E][E]█[-]█[5][0]"
2290 PRINT "██[C][H][A][N][C][E]█[-]█[T][O][T][A][L]█[O][F]█[A][L][L]█[D][I][C][E][.]"
2300 PRINT 
2310 PRINT "█[I][N][C][I][D][E][N][T][L][Y]█[I][F]█[Y][O][U]█[W][A][N][T]█[T][O]█[K][E][E][P]██[N][O]█[D][I][C][E]█[O][R]█[T][H][E]█[S][A][M][E]█[D][I][C][E]█[A][S]█[I][N]██[T][H][E]█[P][R][E][V][I][O][U][S]█[R][O][L][L][,]█[E][N][T][E][R]█[0][.]"
2320 PRINT 
2330 PRINT "      ANY KEY TO START...       "
2340 PAUSE 4E4
2350 SLOW
2360 CLS
2370 RETURN
2380 FOR F=0 TO 21
2390 PRINT "████████████████████████████████"
2400 NEXT F
2410 RETURN
2420 STOP
2430 GOTO 270
2440 GOTO 290
2450 LET PLAYER=GT
2460 POKE (Q+Z),PLAYER-256*INT (PLAYER/256)
2470 POKE (Q+Z+1),INT (PLAYER/256)
2480 PAUSE 100
2490 CLS
2500 PRINT "  PLAYER 1 - ";PEEK 30001+256*PEEK 30002
2510 PRINT "  PLAYER 2 - ";PEEK 30003+256*PEEK 30004
2520 PRINT "  PLAYER 3 - ";PEEK 30005+256*PEEK 30006
2530 PRINT "  PLAYER 4 - ";PEEK 30007+256*PEEK 30008
2540 PAUSE 300
2550 LET Z=Z+1
2560 IF Z>4 THEN GOTO 2590
2570 LET Q=Q+1
2580 GOTO 140
2590 PRINT AT 15,0;"████████[P][L][A][Y]█[A][G][A][I][N][?]█[Y][/][N]█████████"
2600 PAUSE 4E4
2610 IF INKEY$ ="Y" THEN RUN 
2620 CLS
2630 GOSUB 2380
2640 PRINT AT 10,0;"    THANKS FOR PLAYING - BYE    "
2650 STOP
2700 SAVE "YAHTZE[E]"
2710 RUN

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