Casio Calculator Program Library

Program name: Yahtzee!  --(Back to Index)--

CTF file name: yahtzee.ctf
Author: Tom Lynn
Date: 1995-8
Models: 9700

Screenshots:

[screenshot] [screenshot]


Description:

   This is an implementation of the popular dice game, Yahtzee! with two
   highly detailed graphics screens (look out for the hand top-left...).
              

* The Rules of Yahtzee! *

   Five dice are rolled three times.  Between rolls, dice may be "held" by
   clicking on them (An arrow will appear under the die).  "Clicking" is done
   by moving the pointer over the die and pressing EXE.  If a die has been
   held it will not be rolled.  To roll the dice, click above the dice-box.
   After the dice have been rolled three times, the score on the dice can be
   placed in the relevant row of the score table by clicking on it. The order
   of the dice is not important.  The game ends when all thirteen rows have
   been filled.  The aim of the game is to get the highest possible score.
   
   Points are scored as follows:
   
   1-6   [1][2][3][4][5][6]
   Only the dice showing this value are counted.  If when all six rows are
   filled, the score in this part of the table is 63 or more, a bonus of 35
   is awarded (A score of 63 can be achieved with three of each value), e.g.
   45441 scores 12 when put in fours, as it contains three fours.
   
   3 of a Kind   [3K]
   This scores the total on all five dice if at least three dice show the
   same value, e.g. 65455 scores 6+5+4+5+5 = 25 as it contains three fives.
   
   4 of a Kind   [4K]
   This scores the total on all five dice if at least four dice show the
   same value, e.g. 36333 scores 3+6+3+3+3 = 18 as it contains four threes.
   
   Full House   [FH]
   This scores twenty-five points if three dice show one value and two show
   another (can be the same), e.g. 14144 scores 25 as it contains two ones
   and three fours.
   
   Low Straight   [LS]
   This scores thirty points for a run of four, i.e. 1234, 2345 or 3456, e.g.
   32543 scores 30 as it contains the run 2345.
   
   High Straight   [HS]
   This scores forty points for a run of five, i.e. 12345 or 23456, e.g.
   41532 scores 40 as it contains the run 12345.
   
   Yahtzee!   [Y]
   This scores fifty points if all five dice show the same value, e.g. 22222
   scores 50 as it contains five twos.
   
   Chance   [C]
   This scores the total of all five dice, no matter what they are, e.g.
   11225 scores 1+1+2+2+5 = 11.
              

* How to Play *

   To play Yahtzee!, run the program "~YAHTZEE".  You can stop a game at any
   time by pressing [AC], and as long as you do not change any of the
   variable memories you should be able to continue from where you left off
   by running the program "~YAHTZEE" again.
              
Global subroutines:

   Uses these subroutines from tlglobal.ctf:
   
     "+NUMB35"       Draws numbers of up to three digits, using "+TEXT35".
     "+TEXT35"       Draws ASCII characters.
     "+BOX"          Draws a shadowed box, using "+RECT".
     "+RECT"         Draws a rectangular frame one pixel wide.
     "+RECTFILLED"   Draws a filled rectangle.
     "+THKRECT"      Draws a rectangular frame two pixels wide.
   
   It is recommended that you also use these subroutines from tlglobal.ctf
   which are part of "+TEXT35" but which are not used by Yahtzee!, as you may
   wish to use them in your own programs:
   
     "35SMALL"       Draws small letters.
     "35SYMBOLS"     Draws symbols.
   
   To display a test of all characters which can be used with "+TEXT35", you
   should use "~TEXTTEST" from ttest35.ctf.
              

Program source code:
Program "~YAHTZEE" [Main routine]

   "   ~~~ YAHTZEE! ~~~"
   'The first game with 2 screens of graphix
   Defm 13
   0->Y
   1->N~O
   "Continue game [Y\/N]"?->X
   X<>Y=>Mcl
   Lbl 0
   Prog "YAROLL'EM"
   Prog "YAPICKONE"
   1->X
   Lbl 1
   Z[X]=0=>Goto 0
   Isz X
   X<=13=>Goto 1
   Lbl 2
   Plot 0,0_
   Plot 0,0_
              
Program "YADICE" [Draws large dice]

   'Dice in G~K
   1->E~F
   Lbl 0
   L=0=>F[F]>=0=>1+Int 6Ran#->F[F]
   L=\pi=>?->F[F]
   L=2=>Goto 3
   1->E
   Lbl 1
   E=1=>Abs F[F]=1=>Goto 2
   E=1=>Plot 24F-14,45
   E=2=>Abs F[F]<=3=>Goto 2
   E=2=>Plot 24F-4,45
   E=3=>Abs F[F]<>6=>Goto 2
   E=3=>Plot 24F-14,41
   E=4=>Frac (.5Abs F[F]<>.5=>Goto 2
   E=4=>Plot 24F-9,41
   E=5=>Abs F[F]<>6=>Goto 2
   E=5=>Plot 24F-4,41
   E=6=>Abs F[F]<=3=>Goto 2
   E=6=>Plot 24F-14,37
   E=7=>Abs F[F]=1=>Goto 2
   E=7=>Plot 24F-4,37
   Plot X+2,Y
   Line
   Plot X,Y-2
   Line
   Plot X-2,Y
   Line
   Plot X,Y+1
   Plot X+1,Y
   Plot X-1,Y+1
   Lbl 2
   Isz E
   E<=7=>Goto 1
   Lbl 3
   F[F]>=0=>C<>1=>Goto 4
   Plot 24F-10,18
   Plot X+4,Y
   Line
   Plot X,19
   Plot X-4,Y
   Line
   Plot X,22
   Line
   Plot X-2,Y
   Line
   Plot X+4,26
   Line
   Plot X+4,22
   Line
   Plot X-2,Y
   Line
   Plot X,20
   Plot X,21
   Plot X+1,Y
   Plot X+1,Y
   Plot X-7,Y
   Plot X-1,Y
   Lbl 4
   Isz F
   F<=5=>Goto 0
              
Program "YADRAWDIE" [Draws small dice]

   X->L
   Y->M
   \r>=4=>Plot T+2,U-2
   \r=6=>Plot .5(T+L,U-2
   \r>=2=>Plot L-2,U-2
   Frac .5\r<>0=>Plot .5(T+L,.5(U+M
   \r>=2=>Plot T+2,M+2
   \r=6=>Plot .5(T+L,M+2
   \r>=4=>Plot L-2,M+2
              
Program "YAFILLROW" [Draws a row of dice in the score-table]

   Z[F]=0=>Goto Z
   12->T
   F>=7=>68->T
   68-7F->U
   F>=7=>U+42->U
   1->A
   Lbl 0
   Z[F]->\r
   (10^)AFrac (\r/(10^)A->\r
   Dsz A
   Int (\r/(10^)A->\r
   Isz A
   Plot T+8,U-6
   F<=6=>\r<>F=>Goto 1
   Prog "YADRAWDIE"
   T+8->T
   Lbl 1
   Isz A
   A<=5=>Goto 0
   Lbl Z
              
Program "YAHOLD" [Gets input of which dice to hold]

   Lbl 0
   C=1=>Plot 0,0_
   C=1=>Goto Z
   Plot
   Plot X,Y_
   Y>53=>Goto Z
   Y<17=>Goto Z
   Int ((X+19)/24->F
   F>5=>5->F
   (-)F[F]->F[F]
   1->L
   F[F]<0=>2->L
   Prog "YAROLLSCREEN"
   Goto 0
   Lbl Z
              
Program "YANAMES" [Stores the symbols for the possible scores 3K, 4K, etc.]

   51->L
   75->M~O
   52->N
   70->P
   72->Q
   76->R
   83->S~U
   72->T
   89->V
   67->W
              
Program "YAPICKONE" [Gets and processes input for scoring]

   Prog "YAPICKSCREEN"
   Plot
   Lbl 0
   Plot X,Y_
   X<=3=>Goto 0
   X>=54=>X<=55=>Goto 0
   X>=110=>Goto 0
   X<=54=>Y<=19=>Goto 0
   Y<=9=>Goto 0
   Y=63=>Goto 0
   12+52Int ((X-5)/52->T
   5+7Int ((Y+1)/7->U
   T=64=>4+T->T
   (68-U)/7->F
   T=68=>F+6->F
   Prog "YASORT"
   1->A~B
   Z[F]<>0=>Goto 0
   Lbl 1
   BF[A]+Z[F]->Z[F]
   10B->B
   Isz A
   A<=5=>Goto 1
   Prog "YAFILLROW"
   Prog "YASCORE"
   \th->\r
   40->T
   17->U
   Prog "+NUMB35"
   35->\r
   \th<63=>0->\r
   40->T
   7->U
   Prog "+NUMB35"
   Z->\r
   99->T
   7->U
   Prog "+NUMB35"
   Z+\th->\r
   114->T
   7->U
   Prog "+NUMB35"
   Plot 0,0_
              
Program "YAPICKSCREEN" [Draws scoring screen]

   Cls
   4->T:63->U:Plot 53,10
   Prog "+THKRECT"
   56->T
   Plot 109,10
   Prog "+THKRECT"
   113->T:63->U:1->A
   Lbl 0
   Plot 121,U-8
   Prog "+BOX"
   Abs F[A]->\r
   Plot 121,U-8
   Prog "YADRAWDIE"
   U-11->U
   Isz A
   A<=5=>Goto 0
   49->\r
   60->U
   Lbl 1
   Plot 7,U
   Prog "+TEXT35"
   U-7->U
   Isz \r
   \r<=54=>Goto 1
   Plot 11,20
   Plot X,62
   Line
   Plot 67,12
   Plot X,62
   Line
   Plot 6,19
   Plot 51,Y
   Line
   12->A
   Lbl 2
   Plot A,61
   Plot A,20
   Line
   Plot A+56,61
   Plot X,12
   Line
   A+8->A
   A<=50=>Goto 2
   62->A:2->B
   Lbl 6
   A<=19=>Goto 7
   Plot 11,A
   Plot 52,A
   Line
   Lbl 7
   Plot 68,A
   Plot 108,A
   Line
   Dsz A
   Dsz B
   Goto 6
   2->B
   A-5->A
   A>=13=>Goto 6
   7->A
   1->B
   Lbl 3
   B=6=>A-23->A
   B<6=>Plot A,17
   B>=6=>Plot A,7
   B=1=>21->\r
   B>=2=>B<=3=>16->\r
   B=4=>5->\r
   B=5=>18->\r
   B=6=>2->\r
   B=7=>15->\r
   B=8=>14->\r
   B=9=>21->\r
   B=10=>19->\r
   \r+64->\r
   Prog "+TEXT35"
   A+4->A
   Isz B
   B<=10=>Goto 3
   Prog "YANAMES"
   1->B:60->C
   Lbl 5
   59->A
   K[B]->\r
   B=12=>C-7->C
   Frac .5B=0=>63->A
   B>=11=>61->A
   Plot A,C
   Prog "+TEXT35"
   Isz B
   C-14Frac .5B->C
   B<=12=>Goto 5
   1->B
   56->A
   76->S
   79->T
   87->U
   69->V
   82->W
   Lbl 8
   Plot A,7
   R[B]->\r
   Prog "+TEXT35"
   A+4->A
   Isz B
   B<=5=>Goto 8
   1->F
   Lbl 9
   Prog "YAFILLROW"
   Isz F
   F<=13=>Goto 9
              
Program "YAROLL'EM" [Main playing screen loop]

   3->C
   0->G~K
   Lbl 0
   0->L                            ; Change this to \pi->L for debugging.
   Prog "YAROLLSCREEN"
   Prog "YAHOLD"
   G<0=>H<0=>I<0=>J<0=>K<0=>1->C
   Dsz C
   Goto 0
              
Program "YAROLLSCREEN" [Draws playing screen]

   L=2=>Goto 1
   Range 1,127,0,1,63,0
   1->T
   60->U
   Plot 14,58
   Prog "+RECT"
   Plot 19,54
   Plot 18,55
   Plot X,60
   Line
   Plot 20,Y
   Line
   Plot X,58
   Line
   Plot 19,57
   Plot 24,56
   Plot 21,Y
   Line
   Plot 20,57
   Plot X,58
   Plot 26,Y
   Line
   Plot 27,57
   Plot X,55
   Line
   Plot 26,54
   Plot 20,61
   C=1=>Plot X,63
   C=1=>Line
   Plot 22,Y
   Line
   Plot X,59
   Line
   Plot X,61
   C<>3=>Plot X,63
   C<>3=>Line
   Plot 24,Y
   Line
   Plot X,59
   Line
   Plot X,63
   Line
   Plot 26,Y
   Line
   Plot X,59
   Line
   31->T
   Plot 44,58
   Prog "+RECT"
   48->T
   61->U
   25->M
   1->N
   8->O
   20->P
   26->Q
   5->R~S
   1->A
   Lbl W
   Plot T,U
   L[A]+64->\r
   A=8=>33->\r
   Prog "+TEXT35"
   T+5->T
   Isz A
   A<=8=>Goto W
   87->T:60->U
   Plot 100,58
   Prog "+RECT"
   103->T
   61->U
   Z+\th->\r
   \r<=99=>101->T
   Prog "+NUMB35"
   116->T
   60->U
   Plot 127,58
   Prog "+RECT"
   1->T
   53->U
   Plot 127,27
   Prog "+THKRECT"
   1->T:16->U
   Plot 127,8
   Prog "+RECT"
   (-)17->T
   48->U
   5->A
   Lbl 0
   T+24->T
   Plot T+18,U-16
   Prog "+RECT"
   Dsz A
   Goto 0
   Lbl 1
   Prog "YADICE"
   L=2=>Goto Z
   Plot 9,31
   Plot 26,Y
   Line
   Plot X,46
   Line
   Plot 33,31
   Plot 50,Y
   Line
   Plot X,46
   Line
   Plot 56,31
   Plot 72,Y
   Line
   Plot 78,46
   Plot X,31
   Line
   Plot 95,Y
   Line
   Plot 102,46
   Plot X,31
   Line
   Plot 119,Y
   Line
   1->A
   6->B
   0->D~E
   Prog "YANAMES"
   Lbl F
   Plot A,15
   Plot A,9
   Line
   A=37=>Goto H
   A>=100=>Goto H
   Isz E
   Lbl I
   Isz D
   Z[E]<>0=>Goto G
   D<=6=>48+D->\r
   72->T
   83->U
   D>=7=>E[D]->\r
   Plot A+2,14
   Prog "+TEXT35"
   D>=7=>D<=15=>Frac .5D=.5=>Goto J
   D>=7=>A-4->A
   Goto H
   Lbl J
   A+4->A
   Goto I
   Lbl G
   A+2->T
   14->U
   Plot A+4,10
   D>=7=>D<=15=>Plot A+8,Y
   D>=7=>D<=15=>Isz D
   Prog "+RECTFILLED"
   D>16=>A-4->A
   Lbl H
   A=37=>1->B
   A=38=>10->B
   A=88=>6->B
   A=100=>1->B
   A>100=>30->B
   A+B->A
   A<127=>Goto F
   18->L
   15->M
   12->N~O
   (-)C-12->Q
   103->T
   1->U
   Lbl N
   Plot T,14
   K[U]+64->\r
   Prog "+TEXT35"
   Lbl M
   T+4->T
   Isz U
   U=5=>Goto M
   U<=6=>Goto N
   Lbl Z
              
Program "YASCORE" [Calculates score]

   0->\r                   ; \r holds score for this round
   F<=6=>Goto 6
   G+H+I+J+K->B            ; B holds the total score on dice
   F=7=>Goto 7
   F=8=>Goto 8
   F=9=>Goto 9
   F=10=>Goto A
   F=11=>Goto B
   F=12=>Goto C
   F=13=>Goto D
   
   Lbl 6                   ; [1] Ones - [6] Sixes -> Total on all dice
   5->A
   Lbl E
   F[A]=F=>F+\r->\r
   Dsz A
   Goto E
   Goto Z
   
   Lbl 7                   ; [3K] 3 of a kind -> Total on all dice
   G=H=>H=I=>B->\r
   H=I=>I=J=>B->\r
   I=J=>J=K=>B->\r
   Goto Z
   
   Lbl 8                   ; [4K] 4 of a kind -> Total on all dice
   G=H=>H=I=>I=J=>B->\r
   H=I=>I=J=>J=K=>B->\r
   Goto Z
   
   Lbl 9                   ; [FH] Full House -> 25
   G<>H=>Goto Z
   J<>K=>Goto Z
   G<>I=>J<>I=>Goto Z
   25->\r
   Goto Z
   
   Lbl A                   ; [LS] Low Straight -> 30
   2->A:5->\r
   Lbl 0
   F[A]-E[A]<>1=>Dsz \r
   Isz A
   A<=5=>Goto 0
   \r>3=>30->\r
   \r<=3=>0->\r
   I-H>1=>0->\r            ; These two lines were missing from the pre-release
   J-I>1=>0->\r            ; version, so 12356 and 12456 were allowed.
   Goto Z
   Lbl B                   ; [HS] High Straight -> 40
   H=G+1=>I=H+1=>J=I+1=>K=J+1=>40->\r
   Goto Z
   Lbl C                   ; [Y] Yahtzee! -> 50
   G=K=>H=K=>I=K=>J=K=>50->\r
                           ; (This should really have a special routine added.)
   \r=50=>"      Yahtzee!"_
   Goto Z
   Lbl D
   B->\r
   Lbl Z
   \r=0=>"      No points!"_
   \r<>0=>"Score:"
   \r<>0=>\r_
   F<=6=>\r+\th->\th
   F>=7=>\r+Z->Z
              
Program "YASORT" [Sorts the dice into ascending order]

   Abs G->G
   2->A
   Lbl 0
   Abs F[A]->F[A]
   F[A]>=F[A-1]=>Goto 1
   F[A]->B
   F[A-1]->F[A]
   B->F[A-1]
   2->A
   Goto 0
   Lbl 1
   Isz A
   A<=5=>Goto 0
              


This page was created by Tom Lynn (tom-calcs@mythic-beasts.com).
This page last updated: Friday, 30 April, 1999

Written in notepad and compiled with WTA, for clean, consistent HTML.
Part of the Casio Graphical Calculator Encyclopaedia.

Best Viewed With Any Browser