Yahtzee

Drawing of a pair of dice
Drawing of a pair of dice

Yahtzee is a poker-style dice game where each player tries to roll combinations to match the categories on the scorecard. The program is set up for 4 players. There are 5 dice. All are automatically rolled on each first roll. Each player is allowed 3 rolls per category. There are 13 categories.

The object of the game is to fill in all of the categories on the scorecard while accumulating as many points as possible. All categories MUST be filled in even if this means scoring a ZERO. The highest possible score is 375 (I don’t think anyone has ever done that).

The two-section scorecard is set up as:

1-ACES              7-3 OF A KIND
2-TWOS              8-4 OF A KIND
3-THREES            9-FULL HOUSE
4-FOURS            10-SMALL STRAIGHT
5-FIVES            11-LARGE STRAIGHT
6-SIXES            12-YAHTZEE
  TOTAL:           13-CHANCE
  BONUS:                TOTAL:
TOTAL:              GRAND TOTAL:

If you score 63 or more points in section one (the left side), you are awarded a bonus of 35 points.

HOW TO PLAY:

Each player must complete their game before the next one starts (this is done for easier management of the scorecard displays and the actual scoring…and to prevent contestants from playing musical chairs).

The dice are numbered 1 to 5. The first roll is automatic. When the dice change, you are prompted UP TO which number die you want to KEEP. Input the number of the LAST die you wish to keep. For example, if you have rolled:

Example roll: five numbered dice
Example roll: five numbered dice

and you have decided to try for the threes, then you would type: 5 ENTER, because 5 is the number of the LAST die you would want to KEEP. Next you are asked WHICH dice to be kept. For this example you would type: 1 ENTER, 4 ENTER, 5 ENTER. The number 1, 4 and 5 dice change color to remind you which dice you are saving.

Next you are asked UP TO which number die to THROW. In this case you would type: 3 ENTER. Then you are prompted WHICH dice to throw. Here it would be: 2 ENTER, 3 ENTER and the number 2 and 3 dice will roll again.

IT IS MOST IMPORTANT THAT ALL ABOVE INPUTS BE IN THE PROPER SEQUENCE BECAUSE THE PROGRAM WILL TERMINAT[illegible] YOUR ROLL WHEN THE LAST NUMBER DIE IS REACHED.

Follow this procedure for 2 more rolls. You can change your mind and re-roll any dice that you were previously saving. If at any time you wish to keep the same dice as a previous roll, or all 5 dice, just enter a ZERO. After one turn (3 rolls) you are asked which category you wish to use. Enter the number of this category. The computer will first calculate the validity of the combination of dice for the category, then the point value (if any), then place that value in the appropriate box on the scorecard and finally tally the totals.

The CHANCE category is used when you get in a jam and have no better options. CHANCE totals all 5 dice values.

When each player finishes their game (13 turns), they are asked if a printout of their final scorecard is desireable. Although the program provides a tally screen of all 4 scores after each player has completed their game, I felt that a screen dump of each scorecard was a nice feature. This works for the 2040 printer only. You will have to alter the code for your particular printer.

THE PROGRAM:

Let’s run through the program from the begining. Line 40 clears memory (50000 to 50008) for the 4 scores. The 2 POKEs in line 60 toggle the CAPS LOCK and set the system variable PIP to an audible beep. The DATA statements, lines 720 to 820, hold the graphics for the dice. D$ is a 3 dimensional array. The 3rd dimension is used for the shadows on the bottom and right sides of the dice.

The “title & table” routine, lines 500 – 700, draws the playing table, the dice and resets the scorecard variables. We then return to the scorecard routine at line 150 which plots out the actual tally sheet.

Player 1 now starts the game in the main loop at line 400. The dice are rolled and control is routed in and out of the “throw dice” and “keep dice” subroutines for 3 rolls.

After 3 rolls we are directed to the scoring routine which first prompts the player which category is to be used. If this category is within the b1 and b6 variable range (3 OF A KIND to YAHTZEE) program flow is routed to the sorting routine at line 3000. This sorts the values of the dice (first DATA figures in the “dice” statements).

Sorting of this data is necessary to ascertain the validity of the dice thrown and the category chosen. Boolean logic takes over from lines 1117 to 1236. I admit that boolean logic in TS Basic is cumbersome (the ELSE command would be most helpful for this application) but it does work, if somewhat slowly.

Lines 1240 to 1300 perform the tabulations of the scores. When x=14 (line 415), all categories have been used and control goes to the “poke scores” routine at 1380 which displays all 4 scores.

When all 4 games are completed (z>4, line 1420), the “end routine” is accessed where we are given the option of either playing again or quitting.

This is a long listing. If anyone is interested in the program but doesn’t feel like keying it in, I will send copies on tape for $8.oo. Also included on the tape will be 4 type fonts which can be loaded into other programs or used while writing your own programs. Full instructions included. Send to: Arthur Marzano, 1949 Locust St., Phila., PA 19103.

VARIABLES

A1 to A6 = ACES - SIXES    T1 = Subtotal, section 1
B1 = 3 OF A KIND           T2 = Total+Bonus section 1
B2 = 4 OF A KIND           T3 = Total, section 2
B3 = FULL HOUSE            GT = Grand Total
B4 = SMALL STRAIGHT        X = Counter for each turn
B5 = LARGE STRAIGHT        Z = Counter for players
B6 = YAHTZEE               E(1-5) = Dice values
B7 = CHANCE                D$ = The dice
V = Random generator       F, I, G, J = Counters
L = Line co-ord            H = Player input
C = Column co-ord          K = Control for input
M = Control for scores
CC, DD = Control variables for sort routine
  10 REM    YAHTZEE  ©  1986
20 REM by Arthur B. Marzano
40 FOR f=50000 TO 50008: POKE f,0: NEXT f
50 LET q=50000: LET z=1
60 POKE 23658,8: POKE 23609,20
70 BORDER 1: PAPER 1: INK 5: CLS
80 PRINT INK 6; PAPER 0; BRIGHT 0;" Y A H T Z E E © 1 9 8 6 by Arthur B. Marzano "
100 PAUSE 200
110 BORDER 2: INK 0: PAPER 7: OVER 0: CLS
120 LET l=4: LET c=1
130 GO SUB 710: GO SUB 500
150 REM score card
200 INK 1
210 PRINT AT 13,1;1;" ACES";TAB 15;7;" 3 OF KIND"
220 PRINT TAB 1;2;" TWOS";TAB 15;8;" 4 OF KIND"
230 PRINT TAB 1;3;" THREES";TAB 15;9;" FULL HOUSE"
240 PRINT TAB 1;4;" FOURS";TAB 14;10;" SMALL ST"
250 PRINT TAB 1;5;" FIVES";TAB 14;11;" LARGE ST"
260 PRINT TAB 1;6;" SIXES";TAB 14;12;" YAHTZEE"
270 PRINT TAB 3;"TOTAL: ";TAB 14;13;" CHANCE"
280 PRINT TAB 3;"BONUS: ";TAB 17;"TOTAL: "
290 PRINT TAB 1;"TOTAL: ";TAB 14;"GRAND TOTAL: ";
300 FOR n=0 TO 79 STEP 8
310 PLOT 2,n: DRAW 250,0
320 NEXT n
330 INK 0
340 PLOT 2,80: DRAW 250,0: PLOT 2,81: DRAW 250,0: PLOT 2,72: DRAW 250,0: PLOT 0,0: DRAW 0,81: PLOT 1,0: DRAW 0,81
380 PLOT 74,0: DRAW 0,71: PLOT 107,0: DRAW 0,71: PLOT 218,0: DRAW 0,71: PLOT 253,0: DRAW 0,81: PLOT 254,0: DRAW 0,81: PLOT 255,0: DRAW 0,163
390 LET x=0
399 REM main loop
400 LET x=x+1
410 IF x=14 THEN PRINT #1;"PRINT OUT ? Y/N": PAUSE 0: LET i$=INKEY$: IF INKEY$="Y" THEN PRINT PAPER 4;AT 10,1;" PLAYER ";z;" ": COPY : LPRINT : LPRINT
415 IF x=14 THEN PAUSE 300: GO TO 1380
420 GO SUB 830
430 GO SUB 1030
440 GO SUB 950
450 GO SUB 1030
460 FOR f=1 TO 25: BEEP .008,f: BEEP .006,-f: NEXT f: PRINT AT 10,1; PAPER 4;" Player ";z;": 3rd roll... ": PAUSE 50: GO SUB 960
470 GO SUB 1080
480 GO TO 400
500 REM title & table
510 PRINT PAPER 2;" "; PAPER 6; INK 1;" Y A H T Z E E "; PAPER 2;" "
520 PRINT PAPER 4; INK 0;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
530 FOR f=2 TO 11
540 PRINT PAPER 4;" ": NEXT f
550 PRINT PAPER 4;AT 1,0;"▒"
560 FOR f=2 TO 11: PRINT PAPER 4;AT f,0;"▒": NEXT f
570 LET l=4: LET c=1
580 FOR f=2 TO 5
590 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)
600 LET l=l+1
610 NEXT f
620 PRINT AT 2,6; PAPER 4;"1";AT 2,11;"2";AT 2,16;"3";AT 2,21;"4";AT 2,26;"5"
670 LET a1=0: LET a2=0: LET a3=0: LET a4=0: LET a5=0: LET a6=0
680 LET bonus=0: LET t1=0: LET t2=0: LET t3=0: LET gt=0
690 LET b1=0: LET b2=0: LET b3=0: LET b4=0: LET b5=0: LET b6=0: LET b7=0
695 DIM e(5): LET e=5: LET c=1
700 RETURN
710 REM dice
720 RESTORE 770
730 DIM d$(6,5,4)
740 FOR f=1 TO 6: FOR i=1 TO 5
750 READ d$(f,i)
760 NEXT i: NEXT f: RETURN
770 DATA "1"," ▒"," ▒ ▒"," ▒","▒▒▒▒"
780 DATA "2"," ▒▒"," ▒","▒ ▒","▒▒▒▒"
790 DATA "3"," ▒▒"," ▒ ▒","▒ ▒","▒▒▒▒"
800 DATA "4","▒ ▒▒"," ▒","▒ ▒▒","▒▒▒▒"
810 DATA "5","▒ ▒▒"," ▒ ▒","▒ ▒▒","▒▒▒▒"
820 DATA "6","▒ ▒▒","▒ ▒▒","▒ ▒▒","▒▒▒▒"
830 REM throw dice
840 INK 0: PAPER 7: PRINT AT 10,1; PAPER 4;" Player ";z;": 1st roll... "
860 FOR f=1 TO 40: BEEP .009,f: BEEP .007,-f: NEXT f
870 LET l=4: LET c=1
880 FOR f=1 TO 5
890 LET i=2
900 LET v=INT (RND*6)+1
910 FOR j=1 TO 4: PRINT AT l,c*5;d$(v,i): LET e(c)=VAL d$(v,1): LET l=l+1: LET i=i+1: NEXT j
920 LET c=c+1: LET l=4
930 NEXT f
940 RETURN
950 FOR f=1 TO 20: BEEP .007,f: BEEP .005,-f: NEXT f: PRINT AT 10,1; PAPER 4;" Player ";z;": 2nd roll... ": PAUSE 50
960 PRINT PAPER 4;AT 10,1;"Up to which # die to be thrown": INPUT h
965 IF h>=6 THEN GO TO 960
970 FOR k=1 TO h: PRINT AT 10,1; PAPER 4;"Which dice to be thrown ? ": INPUT k
975 IF k>=6 THEN GO TO 970
976 LET c=k: LET l=4: LET i=2
1000 LET v=INT (RND*6)+1
1010 FOR j=1 TO 4: PRINT AT l,c*5;d$(v,i): LET E(C)=VAL D$(V,1): LET l=l+1: LET i=i+1: NEXT j: NEXT k
1020 RETURN
1030 REM keep dice
1040 PRINT PAPER 4;AT 10,1;"Up to which # die to be kept? ": INPUT h
1045 IF h>=6 THEN GO TO 1040
1050 FOR k=1 TO h: PRINT AT 10,1; PAPER 4;" Which dice to be kept ? ": INPUT k
1055 IF k>=6 THEN GO TO 1050
1056 GO SUB 1070: LET c=k: NEXT k
1060 RETURN
1070 FOR f=2 TO 5: PRINT OVER 1; PAPER 5;AT f+2,k*5;" ": NEXT f: RETURN
1080 REM scoring
1090 FOR f=30 TO 50: BEEP .009,f: BEEP .005,-f: NEXT f: PRINT AT 10,1; PAPER 4; INK 7;" In which category ? ": INPUT h
1095 IF h>=14 THEN GO TO 1090
1100 INK 1
1102 GO SUB 1330
1103 FOR f=1 TO e
1104 IF h=e(c) THEN LET m=m+e(c)
1108 IF h<7 THEN GO TO 1150
1109 IF h=13 THEN GO TO 1230
1110 IF h=7 OR h=8 OR h=9 OR h=10 OR h=11 OR h=12 THEN LET e(f)=e(c): GO SUB 3000
1111 IF h=11 THEN GO TO 1130
1112 IF h=12 THEN GO TO 1140
1113 IF h=7 THEN GO TO 1210
1114 IF h=8 THEN GO TO 1220
1115 IF h=10 THEN GO TO 1120
1117 IF h=9 AND NOT (e(1)=e(2) AND e(4)=e(5) AND (e(3)=e(1) OR e(3)=e(4))) THEN LET b3=0: PRINT AT 15,28;b3: GO TO 1232
1118 IF h=9 THEN LET b3=25: PRINT AT 15,28;b3: GO TO 1232
1120 IF e(1)=e(2) AND e(2)+1=e(3) AND e(3)+1=e(4) AND e(4)+1=e(5) THEN LET b4=30
1122 IF e(1)+1=e(2) AND e(2)+1=e(3) AND e(3)+1=e(4) THEN LET b4=30
1124 IF e(1)+1=e(2) AND e(2)=e(3) AND e(3)+1=e(4) AND e(4)+1=e(5) THEN LET b4=30
1126 IF e(1)+1=e(2) AND e(2)+1=e(3) AND e(3)=e(4) AND e(4)+1=e(5) THEN LET b4=30
1128 IF e(1)+1<e(2) AND e(2)+1=e(3) AND e(3)+1=e(4) AND e(4)+1=e(5) THEN LET b4=30
1129 PRINT AT 16,28;b4: GO TO 1232
1130 IF (e(1)<e(2) AND e(2)<e(3) AND e(3)<e(4) AND e(4)<e(5)) THEN LET b5=40
1135 PRINT AT 17,28;b5: GO TO 1232
1140 LET m=m+e(c): IF (e(1)*5=m) THEN LET b6=50: PRINT AT 18,28;b6: GO TO 1232
1145 IF NOT ((e(1)=e(2) AND e(2)=e(3) AND e(3)=e(4) AND e(4)=e(5))) THEN LET b6=0: PRINT AT 18,28;b6: GO TO 1232
1146 GO TO 1232
1150 IF h=1 THEN LET a1=m: PRINT AT 13,10;a1: GO TO 1232
1160 IF h=2 THEN LET a2=m: PRINT AT 14,10;a2: GO TO 1232
1170 IF h=3 THEN LET a3=m: PRINT AT 15,10;a3: GO TO 1232
1180 IF h=4 THEN LET a4=m: PRINT AT 16,10;a4: GO TO 1232
1190 IF h=5 THEN LET a5=m: PRINT AT 17,10;a5: GO TO 1232
1200 IF h=6 THEN LET a6=m: PRINT AT 18,10;a6: GO TO 1232
1210 IF (e(1)=e(2) AND e(2)=e(3)) OR (e(2)=e(3) AND e(3)=e(4)) OR (e(3)=e(4) AND e(4)=e(5)) THEN LET m=m+e(c): LET b1=m: PRINT AT 13,28;b1: GO TO 1232
1212 IF NOT b1 THEN PRINT AT 13,28;b1: GO TO 1232
1220 IF (e(1)=e(2) AND e(2)=e(3) AND e(3)=e(4)) OR (e(2)=e(3) AND e(3)=e(4) AND e(4)=e(5)) THEN LET m=m+e(c): LET b2=m: PRINT AT 14,28;b2: GO TO 1232
1225 IF NOT b2 THEN PRINT AT 14,28;b2: GO TO 1232
1230 LET m=m+e(c): LET b7=m: PRINT AT 19,28;b7: GO TO 1232
1235 LET c=c+1
1236 NEXT f
1240 LET t1=a1+a2+a3+a4+a5+a6
1250 IF t1<63 THEN GO TO 1270
1260 IF t1>=63 THEN LET bonus=35: PRINT AT 20,10;bonus
1270 LET t2=t1+bonus
1280 PRINT AT 19,10;t1: PRINT AT 21,10;t2
1290 LET t3=b1+b2+b3+b4+b5+b6+b7: PRINT AT 20,28;t3
1300 LET gt=t2+t3: PRINT AT 21,28;gt
1320 RETURN
1330 LET c=1
1340 LET m=0
1370 RETURN
1375 REM poke scores 1 - 4
1380 INK 0: PAPER 7: POKE (q+z),gt-256*INT (gt/256): POKE (q+z+1),INT (gt/256): CLS
1390 INK 0: OVER 0
1395 PRINT : PRINT
1400 PRINT ''TAB 9;"Player 1 - ";: PRINT PEEK 50001+256*PEEK 50002: PRINT ,''TAB 9;"Player 2 - ";: PRINT PEEK 50003+256*PEEK 50004: PRINT ,''TAB 9;"Player 3 - ";: PRINT PEEK 50005+256*PEEK 50006: PRINT ,''TAB 9;"Player 4 - ";: PRINT PEEK 50007+256*PEEK 50008
1410 LET q=q+1
1420 PAUSE 300: LET z=z+1: IF z>4 THEN GO TO 4000
1430 CLS : GO TO 110
2999 REM sort routine
3000 FOR i=1 TO e-1
3010 FOR g=1 TO e-i
3020 LET cc=e(g)
3030 LET dd=e(g+1)
3040 IF cc<=dd THEN GO TO 3070
3050 LET e(g)=dd
3060 LET e(g+1)=cc
3070 NEXT g
3080 NEXT i
3090 RETURN
3999 REM end routine
4000 PRINT AT 20,0; INK 1; FLASH 1;" P L A Y A G A I N Y/N? "
4010 PAUSE 0
4020 IF INKEY$="Y" THEN RUN
4030 BORDER 1: PAPER 1: INK 5: CLS : PRINT AT 10,0; FLASH 1; BRIGHT 1;" THANKS FOR PLAYING -BYE "
9997 STOP
9998 SAVE "YAHTZEE" LINE 10
"Hit any key to continue" cartoon
"Hit any key to continue" cartoon

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