Post Reply 
(71B) YATZEE 71 1.2 For HP-71B
12-24-2013, 04:53 PM (This post was last modified: 06-15-2017 01:28 PM by Gene.)
Post: #1
(71B) YATZEE 71 1.2 For HP-71B
Namir's Battleship game inspired me to dust off two HP71B dice games I wrote some years ago, YATZ71 and ROLLERS. Both programs rely on subroutines contained in a file called DICESUBS, which I will include with both programs in seperate postings.

YATZ71:
Code:

10 ! *****************************************************
20 ! *   YATZ71
30 ! *   Loosely based on 'YZ' (http://www.rskey.org/gene/hpgene/yz.htm)
40 ! *
50 ! *   Copyright (C) Howard Owen 2005
60 ! *   This program is free software; you can redistribute it and/or modify
70 ! *   it under the terms of the GNU General Public License as published by
80 ! *   the Free Software Foundation; either version 2 of the License, or
90 ! *   (at your option) any later version.
100 ! *
110 RANDOMIZE 
120 DESTROY ALL 
130 D1=6 ! Range(D)=1..D1
140 DEF FNR(N)=INT(RND*D1+1) ! Roll 1
150 N=5 ! # Dice 
160 OPTION BASE 1
170 DIM D$[84] ! String with dice images
180 DIM D1$[70] ! Display string (five dice)
190 DIM D(N) ! Dice values
200 DIM F(D1) ! Dice frequency table
210 DIM S(13) ! Score card
220 DIM X(N),C2(N) ! Dice display state variables
230 FOR I=1 TO 13 @ S(I)=-1 @ NEXT I ! Zero the scorecard
240 DIM S$(13) ! Score card labels
250 FOR I=1 TO 6 @ S$(I)=STR$(I)&"s" @ NEXT I
260 S$(7)="3/K" @ S$(8)="4/K" @ S$(9)="FH" @ S$(10)="SmSt" @ S$(11)="LgSt" @ S$(12)="Ytz" @ S$(13)="??"
270 CALL DICE(D$) IN DICESUBS ! Initialize dice images
280 B2=FLAG(-2) ! Save initial state of the beeper flag
290 ! 
300 ! Main loop
310 ! 
320 'NEWTURN': ! Start with fresh dice
330 FOR I=1 TO N @ D(I)=FNR(0) @ NEXT I ! roll 'em
340 R=1 ! Roll counter
350 ! 
360 ! Roll 'em
370 ! 
380 FOR I=1 TO 5 @ X(I)=1 @ C2(I)=1 @ NEXT I
390 ! 
400 'NEXTROLL': ! Next within a turn
410 WINDOW 1
420 CALL DRAW(D$,D(),X(),N) IN DICESUBS
430 WINDOW 13
440 IF R=3 THEN GOTO 'SCORE'
450 K$=KEY$ @ IF K$='' THEN 450
460 IF K$="Q" THEN GOSUB "BToggle" @ GOTO 450
470 IF K$="B" THEN GOSUB 'Bonus' @ GOTO 530
480 P=NUM(K$)-48
490 IF P>0 AND P<=5 THEN X(P)=NOT X(P) @ C2(P)=1 @ GOTO 530
500 IF K$='S' OR K$='?' OR K$="+" THEN GOSUB "ShowSco" @ GOTO 530
510 IF K$='#38' THEN BEEP 1760,.1 @ GOTO 570
520 BEEP 440,.1 @ BEEP 220,.2 @ GOTO 'NextRoll'
530 BEEP 1760,.1 @ GOTO 'NextRoll'
540 ! 
550 ! Re-roll selected dice
560 ! 
570 Y=1
580 FOR I=1 TO N
590 IF NOT X(I) THEN D(I)=FNR(0) @ C2(I)=1 @ X(I)=1 @ Y=0
600 NEXT I
610 IF Y THEN GOTO 'SCORE'
620 R=R+1
630 GOTO 'NEXTROLL'
640 ! 
650 ! *********************************** Scoring
660 ! 
670 'SCORE':
680 ! Input: choose slot to place score
690 INPUT 'S?>';S1
700 IF S1>13 OR S1<1 THEN BEEP 220,.1 @ GOTO 'Score'
710 IF S1#12 AND S(S1)#-1 THEN BEEP 220,.1 @ GOTO 'Score'
720 IF S1=12 AND S(S1)=0 THEN BEEP 220,.1 @ GOTO 'Score'
730 S2=0
740 ! 
750 !                          score calculations
760 ! 
770 IF S1<7 THEN GOSUB 'Lower' @ GOTO 'Sum'
780 ! sumall sums the dice and counts frequencies
790 GOSUB 'SUMALL'
800 IF S1>8 THEN GOTO 'nineup'
810 ! 
820 !                                7 == 3 of a kind
830 !                                8 == 4 of a kind
840 ! 
850 S4=0 @ FOR I=1 TO N
860 IF F(D(I))>=S1-4 THEN S4=1
870 NEXT I
880 IF NOT S4 THEN S2=0
890 GOTO 'Sum'
900 'NINEUP':
910 IF S1>9 THEN GOTO 'tenup'
920 ! 
930 !                                9 == full house
940 ! 
950 G3=0 @ G2=0 @ FOR I=1 TO D1
960 IF F(I)=3 THEN G3=1
970 IF F(I)=2 THEN G2=1
980 NEXT I
990 IF G2 AND G3 THEN S2=25 ELSE S2=0
1000 GOTO 'SUM'
1010 'TENUP':
1020 IF S1>11 THEN GOTO 'TWELVEUP'
1030 ! 
1040 !                               10 == small straight
1050 !                               11 == large straight
1060 ! 
1070 C=0 @ C1=0
1080 FOR I=1 TO D1
1090 IF F(I) THEN C=C+1 ELSE C1=MAX(C,C1) @ C=0
1100 NEXT I
1110 C=MAX(C,C1)
1120 IF S1=11 THEN GOTO 'SK2'
1130 IF C>=4 THEN S2=30 ELSE S2=0
1140 GOTO 'SUM'
1150 'SK2': IF C=5 THEN S2=40 ELSE S2=0
1160 GOTO 'SUM'
1170 'TWELVEUP':
1180 IF S1=13 THEN GOTO 'THIRTEEN'
1190 ! 
1200 !                              12 == yatz!
1210 ! 
1220 N1=D(1)
1230 Y=1
1240 FOR I=2 TO N
1250 IF D(I)#N1 THEN Y=0
1260 NEXT I
1270 IF Y THEN S2=50 @ CALL BEEP41 IN DICESUBS @ GOTO 'SUM'
1280 S2=0
1290 ! Can't zero Yatz unless it hasn't scored yet.
1300 ! Couldn't catch this before because we could have had Yatz..
1310 IF S(12)#-1 THEN BEEP 220,.1 @ GOTO 'SCORE'
1320 CALL RASPB IN DICESUBS
1330 GOTO 'SUM'
1340 'THIRTEEN':
1350 !                             13 == chance
1360 ! 
1370 ! do nothing, since s2= sum of all dice
1380 'SUM':
1390 IF S1#12 THEN S(S1)=S2 @ GOTO 'SK1'
1400 IF S(12)=-1 THEN S(12)=0
1410 S(12)=S(12)+S2
1420 'SK1': DISP STR$(S1)&"="&STR$(S(S1))
1430 IF S(S1) THEN BEEP 1760,.1 @ BEEP 2640,.1
1440 IF NOT S(S1) THEN BEEP 440,.1 @ BEEP 220,.2
1450 WAIT 2
1460 ! 
1470 !                            check for filled score card
1480 ! 
1490 F1=1
1500 FOR I=1 TO 13
1510 IF S(I)=-1 THEN F1=0
1520 NEXT I
1530 IF NOT F1 THEN GOTO 'NEWTURN'
1540 ! 
1550 ! ****************************************  Exit Routine
1560 ! 
1570 DESTROY S3
1580 DISP 'Done' @ WAIT 1
1590 S1=0 @ FOR I=1 TO 6 @ S1=S1+S(I) @ NEXT I
1600 IF S1>=63 THEN S2=35 ELSE S2=0
1610 WINDOW 1
1620 DISP "Top = "&STR$(S1)&" + "&STR$(S2) @ WAIT 1
1630 S3=0 @ FOR I=7 TO 13 @ S3=S3+S(I) @ NEXT I
1640 DISP 'Bottom = '&STR$(S3) @ WAIT 1
1650 T=S1+S2+S3
1660 DISP "Total = "&STR$(T)
1670 B2=FLAG(-2,B2)
1680 ! 
1690 ! ************************** End of main program
1700 ! 
1710 END 
1720 ! 
1730 ! ************************** Subroutines
1740 ! 
1750 !                            Sum all dice and count frequencies
1760 'SUMALL':
1770 S2=0
1780 FOR I=1 TO D1 @ F(I)=0 @ NEXT I
1790 FOR I=1 TO N @ S2=S2+D(I) @ F(D(I))=F(D(I))+1 @ NEXT I
1800 RETURN 
1810 !                            Lower half of yatz scorecard
1820 'LOWER':
1830 ! 
1840 ! lower half, 1-6
1850 ! sum dice that match s1 == the current slot
1860 ! 
1870 S2=0
1880 FOR I=1 TO N
1890 IF D(I)=S1 THEN S2=S2+S1
1900 NEXT I
1910 IF S2<3*S1 THEN BEEP 1440 @ BEEP 1000 @ WAIT 1
1920 RETURN 
1930 !                           Display the scorecard
1940 'SHOWSCO':
1950 I=1
1960 BEEP 1760,.1 @ BEEP 440,.1 @ BEEP 220,.2 @ BEEP 1760,.1
1970 ! 
1980 'DISPSCO':
1990 DISP S$(I)&":"&STR$(S(I))
2000 K$=KEY$ @ IF K$='' THEN 2000
2010 IF K$="Q" THEN GOSUB "BToggle" @ GOTO 2000
2020 IF K$='#47' OR K$='#50' THEN I=I-1 @ GOTO 'WrapSco'
2030 IF K$='#48' OR K$='#51' THEN I=I+1 @ GOTO 'WrapSco'
2040 IF K$="#38" THEN 'ExitSco'
2050 BEEP 440,.1
2060 GOTO 'DispSco'
2070 ! 
2080 'WRAPSCO':
2090 IF I=0 THEN I=13
2100 IF I=14 THEN I=1
2110 BEEP 1760,.1
2120 GOTO 'DispSco'
2130 ! 
2140 'EXITSCO':
2150 BEEP 440,.1 @ BEEP 220,.1
2160 RETURN 
2170 !                            Toggle the beeper
2180 'BTOGGLE':
2190 Z=FLAG(-2,NOT FLAG(-2))
2200 BEEP 1760,.2
2210 RETURN 
2220 ! 
2230 ! Display status of upper half bonus
2240 'BONUS':
2250 B9=0 @ D9=0
2260 FOR I=1 TO 6 @ IF S(I)#-1 THEN B9=B9+S(I)
2270 NEXT I
2280 IF B9<63 THEN D9=B9-63 ELSE D9=B9
2290 DISP "bonus: "&STR$(D9)
2300 K$=KEY$ @ IF K$='' THEN 2300
2310 IF K$#"#38" THEN BEEP 440,.1 @ GOTO 2300
2320 RETURN

And DICESUBS:

Code:

0001 ! $Id: DICESUBS.txt,v 1.3 2011/04/13 01:21:34 hbo Exp $
0010 ! **********************************    Subprograms
0020 ! 
0030 !                                       Draw dice images in a GDISP ready string
0040 SUB DICE(D$)
0050 V$=CHR$(255)
0060 B$=CHR$(129) ! Dot at top and bottom
0070 T1$=CHR$(225)
0080 T2$=CHR$(135)
0090 T3$=CHR$(231)
0100 O$=CHR$(153)
0110 Z$=CHR$(0)
0120 D$=''
0130 GOSUB 'SPACE'
0140 GOSUB 'Ace'
0150 GOSUB 'SPACE'
0160 GOSUB 'Deuce'
0170 GOSUB 'SPACE'
0180 GOSUB 'Trey'
0190 GOSUB 'SPACE'
0200 GOSUB 'Four'
0210 GOSUB 'SPACE'
0220 GOSUB 'Five'
0230 GOSUB 'SPACE'
0240 GOSUB 'Six'
0250 GOTO 470
0260 'SPACE':
0270 D$=D$&Z$&Z$&Z$
0280 RETURN 
0290 'ACE':
0300 D$=D$&V$&B$&B$&B$&O$&O$&B$&B$&B$&V$
0310 RETURN 
0320 'DEUCE':
0330 D$=D$&V$&T1$&T1$&B$&B$&B$&B$&T2$&T2$&V$
0340 RETURN 
0350 'TREY':
0360 D$=D$&V$&T1$&T1$&B$&O$&O$&B$&T2$&T2$&V$
0370 RETURN 
0380 'FOUR':
0390 D$=D$&V$&T3$&T3$&B$&B$&B$&B$&T3$&T3$&V$
0400 RETURN 
0410 'FIVE':
0420 D$=D$&V$&T3$&T3$&B$&O$&O$&B$&T3$&T3$&V$
0430 RETURN 
0440 'SIX':
0450 D$=D$&V$&T3$&T3$&B$&T3$&T3$&B$&T3$&T3$&V$
0460 RETURN 
0470 END SUB 
0480 !                                       Beep (sort of) like an HP-41
0490 SUB BEEP41
0500 BEEP 608,.25
0510 BEEP 440,.25
0520 BEEP 750,.25
0530 BEEP 608,.5
0540 END SUB 
0550 !                                       Give 'em a raspberry
0560 SUB RASPB
0570 FOR I=1 TO 14 @ BEEP 110,.05 @ BEEP 70,.01 @ NEXT I
0580 END SUB 
0590 !                                       
0600 SUB DRAW(I$,D(),V(),N) !                 Draw the current dice on the screen
0610 ! I$ is the dice images 1-6 in a string, 13 characters each
0620 ! D() is the array of dice values
0630 ! V() is the array of dice visibilities
0640 ! N is the number of dice to display
0650 DIM D$[13],O$[70]
0660 B$=CHR$(0)
0670 B1$=B$&B$&B$&B$&B$&B$&B$&B$&B$&B$&B$&B$&B$
0680 FOR I=1 TO N
0690 B=13*(D(I)-1)+1
0700 IF V(I) THEN D$=I$[B,B+12] ELSE D$=B1$
0710 O$=O$&D$
0720 NEXT I
0730 GDISP O$
0740 END SUB 
0750 ! 
0760 DESTROY D
0770 SUB TRILL(C)
0780 D=.05
0790 DIM N(8)
0800 FOR I=1 TO 8 @ READ N(I) @ NEXT I
0810 FOR R=1 TO C
0820 FOR I=1 TO 8 @ BEEP N(I),D @ NEXT I
0830 NEXT R
0840 DATA 220,330,440,660,880,1320,1760,220
0850 END SUB

YATZ71 documentation:

$Id: Y71DOC.txt,v 1.2 2011/04/12 02:34:09 hbo Exp $

YATZ71

Table of Contents

I How to Play
II Scoring
a The Upper Half
b The Lower Half
c Zeroing and Such
d Viewing the Score Card

III Miscellany
a Shutting up the Beeps
b Ending the Game Normally
c Ending the Game Abnormally
d Battery Hog

VI License



Yatz is a well known game that involves 5 dice and scoring similar to
poker. You roll five dice to start, then "draw" by rolling the ones
you don't like again to try and improve your hand. A more detailed
description of the game follows in section IV.

III How to Play

To start the program, type "run yatz71". (I will assume you have
loaded the program, by hook or by crook, so that command will work.)
After a moment, you will see five dice. press the number keys 1
through five to toggle the corresponding die off and on. The first
press turns a die "off" so that its image disappears from the
screen. A second press of the same number will turn the die back "on"
and its image will reappear on the screen. When you have selected
which dice you want to throw away in this manner, press the END-LINE
key. Yatz71 will roll the dice you threw away and present you with the
result. You can then repeat the process once more before yatz will
demand that you select a score for your hand. If you want to score the
hand you have at any point before you have rolled three times, just
press END-LINE without turning off any dice. Yatz will take you right
to the scoring prompt.

IV Scoring

When your three turns are up (or earlier than that if you choose) Yatz
will display a prompt to the right of the dice images that looks like
"S?> " This is the scoring prompt. Yatz's score card has thirteen
entries, or "slots," numbered one through thirteen. You are expected
to enter a number in this range to select which slot you want your
dice score to be entered in.

IV.a The Upper Half

The first six slots are the "upper half" of the score card. They
represent each of the dice, numbered one through six. You have to try
to fill each of the "slots" in the upper half with dice of the
corresponding value. So if you end up rolling three fours, for
example, you could select "4" when prompted, and your three fours will
be scored as 3 x 4 = 12 points. If you had four fours, that would be
16 points. two fours would be eight and so forth. (You could even have
zero fours, which would score zero points.) You want to try to average
at least three of each of the six die values in the corresponding
upper half slot. That's because you get a bonus of thirty five points
if your upper half score is sixty three or above. That happens to be
exactly what you will score if you get three of each number in the
upper half. You can also get the bonus by scoring four of something
and less of something else. For example, if you scored four sixes,
you would have six extra points to play with. You could then get by with
only two fours and only two twos. Or you could score two fives and two ones.
It's a "mix and match" kind of thing.

Yatz gets worried if it sees that you are scoring less than par on any
slot in the upper half. It will issue an "uh-oh" kind of sound in that
case. It won't matter if you already have four sixes, for example, the
program isn't smart enough to look for that.


IV.b The Lower Half

The other seven slots in the thirteen slot score card are the "lower
half." They have various values and scoring rules given below:

Code:

Slot  Name    Scoring
7     3/K     Three of a kind. Sum of all dice in the hand
8     4/K     Four of a kind. Sum of all dice in the hand
9     FH      Full house. 3/K plus a pair. 25 points
10    SmSt    Small Straight. Run of four dice in sequence. 30 points.
11    LgSt    Large Straight. Run of five dice in sequence. 40 points.
12    YATZ!   Five of a kind. 50 points, repeatable!
13    ??      Chance. Any old dice. Sum of all the dice.
IV.c Zeroing and Such

You can only fill most of these slots once. You can put zero in any of
the slots if you have nothing better to play, but then that is it for
the particular slot for the rest of the game. Yatz is an exception to
the first rule, but not to the second. That is, if you put a zero in
the Yatz slot, number twelve, you can't score yatz anymore for the
rest of the game. However, if you do get a yatz, then later get
another one, you can score it all over again. You would have 100
points in your yatz slot after the second yatz, then 150 and
so on. Five of a kind is hard to get, so its an exceptional game when
you can take advantage of this rule.

IV.d Viewing the Scorecard

When you are rolling the dice, you can view the status of your score
card by pressing the "S" key (or the "+" key, or "g +" which is the
question mark). the status of slot one, the one's place in the upper
half, will be shown. Pressing the down or right arrows will walk down
the slots (toward higher numbers.) Pressing the left or up arrows will
walk up the slots toward lower numbers. The slot numbers will "wrap"
at the ends. So pressing the up arrow in slot one will show slot
thirteen, and the down arrow in slot thirteen will show slot one. Each
slot will show its name, "1" through "6" for the upper half, and the
labels shown above for the lower half. Opposite the names will be the
values stored in the slots. A -1 in the slot means that it is
unused. Any other value means the slot has already been scored with
that value. Pressing the END-LINE key will return to the dice
selection and rolling mode.

V Miscellany

V.a Shutting up the Beeps

This program beeps a lot. If this annoys you, you can execute BEEP OFF
before starting it up. Also, pressing "Q" when in the dice rolling
mode will toggle the beeper on and off. Yatz will remember whether the
beeper was on or off when it first started up, and will restore the
beeper to that state when the program exits normally.

Ending the Game Normally

If all thirteen slots in the score card are filled, yatz will print
the totals of the upper and lower halves together with the bonus, if
any. It will then print the grand total and exit. Before doing so, the
program will restore the beeper as mentioned above, and set WINDOW 1
to return the display to its normal mode.

Ending the Game Abnormally

If you get sick of the game while playing it, you may want to end it
early. You can do this by pressing the ATTN (ON) button. (Throwing the
machine against the wall is not recommended.) If you do this, the
display will not be restored to its normal mode. You will have to type
"WINDOW 1" yourself to get the display back to normal. Also, if you
changed the beeper setting in the program, and that setting was
different from your normal beeper setting, interrupting the program
will leave the beeper ON or OFF as the case may be. You will have to
manually set the beeper yourself to change this, by typing "BEEPER ON"
or "BEEPER OFF" as appropriate.

Battery Hog

Besides beeping a lot, Yatz71 uses the system KEY$ routine to poll for
input. That means that it won't go to sleep if you leave the machine
on like it normally would. (There are better keyboard entry routines
in various LEX files, but I wanted this program to run on a stock
HP-71B.) The moral is: don't do that. Turn off the calculator, or exit
YATZ71 by pressing the ON button before you go off and leave it alone.

License

Copyright (C) Howard Owen 2005,2011

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

The author may be contacted by electronic mail at hbo@egbok.com.


Regards,
Howard
Find all posts by this user
Quote this message in a reply
03-12-2017, 03:43 PM
Post: #2
RE: YATZ71 1.2 For HP-71B
Like Battleship, very cool!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)