Post Reply 
Ok, please look over the HP 41 Yahtzee game here
01-23-2016, 11:06 PM (This post was last modified: 01-24-2016 12:09 AM by Gene.)
Post: #1
Ok, please look over the HP 41 Yahtzee game here
The .raw file linked to here is the current version of my 31 year on/off interest in a game for the HP 41 platform to play the dice game Yahtzee. The .raw file program is 636 bytes long.

Yahztee raw file

Wiki link for basic rules of the game here:

wiki link

The game includes the small straight routine posted here on the forum by Werner as part of the HHC 2015 programming contest. I modified it only to change register references and the labels used. Note: The sorting routine uses the RAD indicator in the display to indicate numbers are being exchanged/sorted. I find this rather cool to see it flashing on and off.

Basically to play:

XEQ YZ
Enter a decimal seed between 0 and 1.
Choose the position of the dice you wish to roll. If you see 23356 ROLL? displayed and want to keep the 3's and roll the 2, 5 and 6 again, key 145 R/S. You get two rolls and then have to score. To score, enter the number of the scorecard row you want to use and press R/S. If you cannot remember which ones are still open, press 0 at this point and press R/S.

By the way, if you get a good roll initially or before prompted for the SCORE? you can enter a 0 instead of the positions of the die and it will skip rolling any dice and immediately go to the SCORE prompt. Why would you want to do this? Suppose you get 22222 ROLL? on the first roll? That's a yahtzee and you should want to score it in row 12. To do that, press 0 R/S and you will see 22222 SCORE? Key 12 R/S and it will score in yahtzee if that row was previously unused. If you skip ahead to SCORE? but then realize you really want to go back and ROLL then you are stuck. No can do.

The scorecard is as follows:
1-6 - score the number of each 1, 2, ... 6 you received.
7 - 3 of a kind
8 - 4 of a kind
9 - full house (3 of a number and then 2 of some other number)
10 - small straight
11 - large straight
12 - yahtzee (5 of a kind)
13 - chance - total of all dice shown

If you get 63 or more points in the rows 1-6 of your scorecard you get a bonus of 35 extra points.

This game does not implement "bonus" yahtzees if you get more than one in a game.



Feel free to :

1) Find bugs :-)
2) Rationalize the labels used. Been a long time and other than labels 1-13 the labels used are not critical.
3) Suggest improvements
4) Add bonus yahtzee scoring
5) Play it and have fun. :-)

I'm hoping some of you can check it out before it gets committed to Angel to update the version used in the FUNSTUFF rom that goes into the HP 41CL. The program in there now has bugs in the LBL 10 small straight section.

Thanks and enjoy.
Find all posts by this user
Quote this message in a reply
01-24-2016, 12:36 AM
Post: #2
RE: Ok, please look over the HP 41 Yahtzee game here
Here's the code for the game. Note that the NOT EQUAL character is shown as != in this listing.

Code:
LBL "YZ"
CLRG
"SEED?"
PROMPT
STO 00
LBL 16
.02
LBL 14
CF IND X
ISG X
GTO 14
14.018
STO 23
FIX 00
CF 29
LBL 15
12345
GTO 71
LBL 17
1
ST+ 19
RCL 19
3
X<=Y?
GTO 22
>" ROLL?"
LBL 27
CLX
PROMPT
INT
X<0?
GTO 27
X=0?
SF 00
X=0?
GTO 61
LBL 71
10
/
ENTER
INT
X<>Y
FRC
10
*
X=0?
GTO 20
5
X<>Y
X>Y?
GTO 72
X<>Y
RDN
13
+
RCL 00
997
*
FRC
STO 00
6
*
1
+
INT
STO IND Y
LBL 72
RCL Z
GTO 71
LBL 20
XEQ 40
LBL 61
CLA
ARCL 14
ARCL 15
ARCL 16
ARCL 17
ARCL 18
FS?C 00
GTO 22
GTO 17
LBL 65
ABS
RCL 12
X=0?
GTO 61
RDN
RCL 14
RCL 18
X=Y?
SF 20
RCL Z
GTO 64
LBL 22
>" SCORE?"
LBL 66
CLX
CF 20
PROMPT
INT
13
X<>Y
X>Y?
GTO 66
X=0?
GTO 25
X<0?
GTO 65
FS? IND X
GTO 66
LBL 64
STO 21
RCL 23
STO 22
CLX
STO 19
STO 20
XEQ IND 21
CF 00
"ROW "
ARCL 21
>"="
ARCL 20
AVIEW
RCL 20
STO IND 21
SF IND 21
X!=0?
FC?C 20
GTO 63
2
10^X
ST+ 12
>" "
ARCL X
PSE
AVIEW
PSE
LBL 63
CLX
STO 20
1.013
LBL 75
FC? IND X
GTO 15
ISG X
GTO 75
"DONE"
AVIEW
RCL 01
RCL 02
RCL 03
RCL 04
+
+
+
RCL 05
+
RCL 06
+
"TOP="
ARCL X
>"+"
63
X<=Y?
35
X>Y?
0
ARCL X
X<>Y
RDN
+
AVIEW
PSE
RCL 07
RCL 08
RCL 09
+
+
RCL 11
+
RCL 12
+
RCL 13
+
"LOWER="
ARCL X
AVIEW
PSE
+
"END="
ARCL X
PROMPT
GTO 16
LBL 25
CLA
1.013
LBL 00
FC? IND X
ARCL X
FC? IND X
>","
ISG X
GTO 00
AVIEW
PSE
GTO 61
LBL 01
LBL 02
LBL 03
LBL 04
LBL 05
LBL 06
RCL IND 22
RCL 21
X=Y?
ST+ 20
ISG 22
GTO 06
RTN
LBL 13
FS?C 14
RTN
RCL 14
RCL 15
RCL 16
RCL 17
+
+
+
RCL 18
+
STO 20
RTN
LBL 12
RCL 18
RCL 14
X!=Y?
RTN
BEEP
50
STO 20
RTN
LBL 07
RCL 14
RCL 16
X=Y?
GTO 13
RCL 18
X=Y?
GTO 13
RCL 17
RCL 15
X=Y?
GTO 13
RTN
LBL 08
RCL 14
RCL 17
X=Y?
GTO 13
RCL 15
RCL 18
X=Y?
GTO 13
RTN
LBL 09
SF 14
XEQ 07
FS?C 14
RTN
RCL 14
RCL 15
X!=Y?
RTN
RCL 17
RCL 18
X!=Y?
RTN
25
STO 20
RTN
LBL 11
RCL 23
+
LBL 35
RCL IND X
ISG Y
RCL IND Y
1
-
-
X!=0?
RTN
RDN
18
X<=Y?
GTO 36
RDN
GTO 35
LBL 36
40
STO 20
RTN
LBL 10
17.013
RCL 18
10^X
LBL 50
RCL IND Y
10^X
+
DSE Y
GTO 50
X<>Y
LBL 51
SIGN
10^X
/
RCL X
1111
X>Y?
GTO 53
-
LOG
FRC
X!=0?
GTO 51
LBL 53
X!=0?
RTN
30
STO 20
RTN
LBL 40
DEG
RCL 17
RCL 16
RCL 15
RCL 14
X>Y?
RAD
X>Y?
X<>Y
STO 14
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 15
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 16
RDN
RCL 18
X<Y?
RAD
X<Y?
X<>Y
STO 18
X<>Y
STO 17
FS? 43
GTO 40
END
Find all posts by this user
Quote this message in a reply
01-24-2016, 03:18 AM
Post: #3
RE: Ok, please look over the HP 41 Yahtzee game here
Hello Gene,

Very nice RPN implementation of one of my favorite game when I was a kid.
I played three games on Genesis-41 OSX simulator and it worked flawlessly.

I have a small suggestion, since you made it for the 41, why not use the auto-assigned labels (A..J,a..e) for actions.
We could then create an overlay for your game!

Thank you for sharing. Smile

Best regards,

Sylvain

Here is my suggestion for the labels ...
Code:
Now  Label  Action
---  -----  --------------------------------------------------------------------
  1  LBL A  Save to 1 
  2  LBL B  Save to 2
  3  LBL C  Save to 3
  4  LBL D  Save to 4
  5  LBL E  Save to 5 
---  -----  --------------------------------------------------------------------
  6  LBL F  Save to 6
  7  LBL G  Save as 3 of a kind
  8  LBL H  Save as 4 of a kind
     LBL I  Show current saved values
     LBL J  Roll dices (identified in X)
---  -----  --------------------------------------------------------------------
  9  LBL a  Save as full house (3 of a number and then 2 of some other number)
 10  LBL b  Save as small straight
 11  LBL c  Save as large straight
 12  LBL d  Save as yahtzee (5 of a kind)
 13  LBL e  Save as chance - total of all dice shown
---  -----  --------------------------------------------------------------------
Find all posts by this user
Quote this message in a reply
01-25-2016, 01:28 PM
Post: #4
RE: Ok, please look over the HP 41 Yahtzee game here
Thanks Sylvain.

I'm particularly interested in:

The scoring routines - especially for cases that should fail. 11235 should not be a small straight - does it score as one? (Answer no, but there are lots of such cases)

and

Places where my routines are byte hungry. The Large Straight routine (LBL 11) for example - can it be done shorter? How?

FYI - Labels 01 through 13 score the corresponding row on the scorecard. LBL 07 is the 3 of a kind label.

Thanks all. Please play the game and help test it before it gets replaced in the FUNSTUFF rom.
Find all posts by this user
Quote this message in a reply
01-26-2016, 08:59 PM (This post was last modified: 01-26-2016 08:59 PM by Guenter Schink.)
Post: #5
RE: Ok, please look over the HP 41 Yahtzee game here
(01-25-2016 01:28 PM)Gene Wrote:  Thanks Sylvain.

I'm particularly interested in:

The scoring routines - especially for cases that should fail. 11235 should not be a small straight - does it score as one? (Answer no, but there are lots of such cases)

and

Places where my routines are byte hungry. The Large Straight routine (LBL 11) for example - can it be done shorter? How?

FYI - Labels 01 through 13 score the corresponding row on the scorecard. LBL 07 is the 3 of a kind label.

Thanks all. Please play the game and help test it before it gets replaced in the FUNSTUFF rom.
Gene,
you haven't recognized my refined and very compact solution that I posted here three weeks after the conference. Based on that approach I offer a combined routine for the small and large straight, which is 39 lines long

Code:
LBL 10        Start for small straight
XEQ 35        do the evaluation for straight
30            possible score
7            to compare with hit-counter
GTO36        goto final evaluation for score
LBL 11        start for large straight
+            No idea what's that for GENE recheck
XEQ 35        do the evaluation for straight
40            possible score
6            to compare with hit-counter
LBL 36        final evaluation for score
RCL Z        get hit-counter
X>Y?        not enough hits? then..
RTN            .. fail
RCL Z        otherwise get score
STO 20        and store
RTN            finished with success
LBL 35        evaluate for straight
RCL 15        If die two is 2
RCL 17        and die four is 5
*            then there is a hole, and no small straight,
10            not relevant for large straight
X=Y?        but handy to have the 10 also available as hit-counter
RTN            .. failed
RCL 23        Get loop counter 14.018
ISG X        Add 1 for retrieval of next number
RCL 14        Get first number
ENTER^        create dumy number for later use
LBL 50        start loop
SIGN        turn previous dummy number into "1"
+            increase first number by one
RCL IND Y    get next number
X=Y?        if they are equal then we have a hit and
DSE T        decrease the hit-counter, it started with 10
X<>Y        save the last retrieved number to Y. X is dummy now
ISG Z        increase loop counter    
GTO 50        if something left to do
R^            lift stack to move hit-counter to X
RTN            go back to score evaluation

In your code you have "+" right after "LBL 11" . As I have no idea what that's for, I left it in, may be it can be deleted.

Hope you can use it,
Günter
Find all posts by this user
Quote this message in a reply
01-26-2016, 09:05 PM
Post: #6
RE: Ok, please look over the HP 41 Yahtzee game here
Thank you Guenter! I must have missed it.

I will look it over and try it out. Thanks for making the adjustments to the registers, etc., used in the program.

Gene
Find all posts by this user
Quote this message in a reply
01-26-2016, 09:18 PM
Post: #7
RE: Ok, please look over the HP 41 Yahtzee game here
About that +

Perfect find. No idea why I had it in there. When the call to LBL 11 is made, the X register has a 0 in it and the program was recalling a value and adding it to that zero. No harm, but totally unnecessary. Oops. Probably got dropped in 25-30 years ago when I was in graduate school and never thought about again.

ty
Find all posts by this user
Quote this message in a reply
01-26-2016, 09:33 PM
Post: #8
New version of Yahztee game
Saved 27 bytes incorporating your combination routine. Many thanks. Now 611 bytes.

Code:

Code:
LBL "YZ"
CLRG
"SEED?"
PROMPT
STO 00
LBL 16
.02
LBL 14
CF IND X
ISG X
GTO 14
14.018
STO 23
FIX 00
CF 29
LBL 15
12345
GTO 71
LBL 17
1
ST+ 19
RCL 19
3
X<=Y?
GTO 22
>" ROLL?"
LBL 27
CLX
PROMPT
INT
X<0?
GTO 27
X=0?
SF 00
X=0?
GTO 61
LBL 71
10
/
ENTER
INT
X<>Y
FRC
10
*
X=0?
GTO 20
5
X<>Y
X>Y?
GTO 72
X<>Y
RDN
13
+
RCL 00
997
*
FRC
STO 00
6
*
1
+
INT
STO IND Y
LBL 72
RCL Z
GTO 71
LBL 20
XEQ 40
LBL 61
CLA
ARCL 14
ARCL 15
ARCL 16
ARCL 17
ARCL 18
FS?C 00
GTO 22
GTO 17
LBL 65
ABS
RCL 12
X=0?
GTO 61
RDN
RCL 14
RCL 18
X=Y?
SF 20
RCL Z
GTO 64
LBL 22
>" SCORE?"
LBL 66
CLX
CF 20
PROMPT
INT
13
X<>Y
X>Y?
GTO 66
X=0?
GTO 25
X<0?
GTO 65
FS? IND X
GTO 66
LBL 64
STO 21
RCL 23
STO 22
CLX
STO 19
STO 20
XEQ IND 21
CF 00
"ROW "
ARCL 21
>"="
ARCL 20
AVIEW
RCL 20
STO IND 21
SF IND 21
X!=0?
FC?C 20
GTO 63
2
10^X
ST+ 12
>" "
ARCL X
PSE
AVIEW
PSE
LBL 63
CLX
STO 20
1.013
LBL 75
FC? IND X
GTO 15
ISG X
GTO 75
"DONE"
AVIEW
RCL 01
RCL 02
RCL 03
RCL 04
+
+
+
RCL 05
+
RCL 06
+
"TOP="
ARCL X
>"+"
63
X<=Y?
35
X>Y?
0
ARCL X
X<>Y
RDN
+
AVIEW
PSE
RCL 07
RCL 08
RCL 09
+
+
RCL 11
+
RCL 12
+
RCL 13
+
"LOWER="
ARCL X
AVIEW
PSE
+
"END="
ARCL X
PROMPT
GTO 16
LBL 25
CLA
1.013
LBL 00
FC? IND X
ARCL X
FC? IND X
>","
ISG X
GTO 00
AVIEW
PSE
GTO 61
LBL 01
LBL 02
LBL 03
LBL 04
LBL 05
LBL 06
RCL IND 22
RCL 21
X=Y?
ST+ 20
ISG 22
GTO 06
RTN
LBL 13
FS?C 14
RTN
RCL 14
RCL 15
RCL 16
RCL 17
+
+
+
RCL 18
+
STO 20
RTN
LBL 12
RCL 18
RCL 14
X!=Y?
RTN
BEEP
50
STO 20
RTN
LBL 07
RCL 14
RCL 16
X=Y?
GTO 13
RCL 18
X=Y?
GTO 13
RCL 17
RCL 15
X=Y?
GTO 13
RTN
LBL 08
RCL 14
RCL 17
X=Y?
GTO 13
RCL 15
RCL 18
X=Y?
GTO 13
RTN
LBL 09
SF 14
XEQ 07
FS?C 14
RTN
RCL 14
RCL 15
X!=Y?
RTN
RCL 17
RCL 18
X!=Y?
RTN
25
STO 20
RTN
LBL 10
XEQ 35
30
ENTER
7
GTO 36
LBL 11
XEQ 35
40
ENTER
6
LBL 36
RCL Z
X>Y?
RTN
RCL Z
STO 20
RTN
LBL 35
RCL 15
RCL 17
*
10
X=Y?
RTN
RCL 23
ISG X
RCL 14
ENTER
LBL 50
SIGN
+
RCL IND Y
X=Y?
DSE T
X<>Y
ISG Z
GTO 50
R^
RTN
LBL 40
DEG
RCL 17
RCL 16
RCL 15
RCL 14
X>Y?
RAD
X>Y?
X<>Y
STO 14
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 15
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 16
RDN
RCL 18
X<Y?
RAD
X<Y?
X<>Y
STO 18
X<>Y
STO 17
FS? 43
GTO 40
END

HP 41 barcode:
YZ Barcode

Raw file:
Yahtzee raw file
Find all posts by this user
Quote this message in a reply
01-26-2016, 09:51 PM
Post: #9
RE: Ok, please look over the HP 41 Yahtzee game here
[quote='Gene' pid='49892' dateline='1453844018']
Saved 27 bytes incorporating your combination routine. Many thanks. Now 611 bytes.

Code:
[snipped]


Nice! However I'd suggest you delete the "ENTER^" after the 2 "XEQ 35" statements. While it doesn't change the byte count, I think it's less clutter.

Günter
Find all posts by this user
Quote this message in a reply
01-26-2016, 10:07 PM
Post: #10
RE: Ok, please look over the HP 41 Yahtzee game here
Funny. :-) I added the ENTER to make sure the code was more readable from the listing. I've seen times when lines without an enter were considered a mistake and the two numbers were joined!
Find all posts by this user
Quote this message in a reply
01-27-2016, 02:48 AM
Post: #11
RE: Ok, please look over the HP 41 Yahtzee game here
Some years ago, I modified the scoring table for Yahtzee (I had learned the game under the name of General; I think the game comes from Cuba.) If I can find them, I'll send you the new scoring rules. There are some bonuses that one can play for (at the risk of losing other scores, of course) and I found the game much more interesting.
Find all posts by this user
Quote this message in a reply
01-28-2016, 12:53 AM
Post: #12
RE: Ok, please look over the HP 41 Yahtzee game here
Hi Gene,

Is there an annotated/commented listing floating about -- at least maybe explaining the purpose of the various sections/subroutines?

stephen
Find all posts by this user
Quote this message in a reply
01-28-2016, 04:24 PM (This post was last modified: 01-28-2016 07:05 PM by Gene.)
Post: #13
RE: Ok, please look over the HP 41 Yahtzee game here
Try this:

Code:
SIZE 024

Register usage:
00 – random number seed
01-13 – the values in each row of the scorecard
14-18 – the individual dice stored 1 per register
19 – the number of rolls made so far.
20 – the score for the current scorecard row
21 – used to store the scorecard row being evaluated
22 – holds the value 1-6 when scoring top of scorecard
23 – holds the 14.018 loop index

This is the initialization section. It clears registers, stores the random numbers seed in memory 00 and clears flags 0-20.

LBL "YZ"
CLRG
"SEED?"
PROMPT
STO 00
LBL 16
.02
LBL 14
CF IND X
ISG X
GTO 14


14.018
STO 23
FIX 00
CF 29
LBL 15
12345
GTO 71

By putting 12345 into X and going to LBL 71, the program will roll all five dice. Since this is the first time, that will initialize registers 14-18 with a die in each register.

LBL 17
1
ST+ 19
RCL 19
3
X<=Y?
GTO 22

This section of code increments the roll counter and checks that it is roll 1 or 2. If so, then the player can roll some or none of the dice again. If the roll counter is 3, then it is time to score. Instead of this code, should I store 2 into register 19 when the first roll is made instead of zero and then replace this code DSE 19 GTO 22?


>" ROLL?"
LBL 27
CLX
PROMPT
INT
X<0?
GTO 27

Less than zero is an invalid entry.

X=0?
SF 00
X=0?
GTO 61

The GTO 61 simply skips ahead redisplays the digits but skips ahead to the SCORE? prompt by setting flag 0 here.

Label 71 takes the user input of which dice to roll and slices a digit at a time from the input, adds 13 to the digit and then rolls a new die for that register. Loops until the digit is a 0 (means it has rolled all digits)

LBL 71
10
/
ENTER
INT
X<>Y
FRC
10
*
X=0?
GTO 20
5
X<>Y
X>Y?
GTO 72

If someone entered 194 at the roll prompt, this will skip over the invalid 9.

X<>Y
RDN
13
+

Below is the tried and true 997 random number generator.

RCL 00
997
*
FRC
STO 00
6
*
1
+
INT
STO IND Y
LBL 72
RCL Z
GTO 71

LBL 20
XEQ 40

Label 40 at the end of the program sorts registers 14.018

LBL 61
CLA
ARCL 14
ARCL 15
ARCL 16
ARCL 17
ARCL 18
FS?C 00
GTO 22
GTO 17

Label 65 checks for a bonus (second, third, etc.) yahtzee during a game. When scoring, if you have a second yahtzee, enter the row to be scored as a negative value. For example, if you have already scored a yahtzee and then get another one, if you wanted to score it as a 3 of a kind, key -7 and R/S at the SCORE? prompt. The program will score it regularly as a 3 of a kind, but will also here give you an extra 100 points 

LBL 65
ABS
RCL 12
X=0?
GTO 61
RDN
RCL 14
RCL 18
X=Y?
SF 20
RCL Z
GTO 64


LBL 22
>" SCORE?"
LBL 66
CLX
CF 20
PROMPT
INT
13
X<>Y
X>Y?
GTO 66

Trying to score in a row > 13 is invalid. Go back to prompt.

X=0?
GTO 25

Entering a zero at the SCORE? prompt displays the available rows in which to score and returns to the SCORE? prompt.

X<0?
GTO 65

A negative value (-7 for example) says to score in row 7 but that a second yahtzee is implied. The program checks if a previous yahtzee has already been scored and if so, scores the roll into the absolute value row indicated and adds a 100 point bonus to row 12. This is checked down in label 65.

FS? IND X
GTO 66

Trying to score in a row that is already used is not allowed. Goes back to SCORE? prompt.

LBL 64
STO 21
RCL 23
STO 22
CLX
STO 19
STO 20
XEQ IND 21

This XEQ IND command goes to the label reflecting the row score to be evaluated. A value of 1 will skip to count the number of 1’s in the five dice, a value of 7 checks for 3-of-a-kind, etc.

CF 00
"ROW "
ARCL 21
>"="
ARCL 20
AVIEW
RCL 20
STO IND 21
SF IND 21

Above, the score determined is saved in the proper row of the scorecard and the corresponding row’s flag is set.

X!=0?
FC?C 20
GTO 63

At this point, two things are indicated. Flag 20 is set indicating a second yahtzee has been achieved but the bonus cannot be paid unless the roll also has a valid score on the row indicated. For example, a second yahztee of 11111 cannot be scored in row 10 small straight. True, you might have a second yahtzee but it has to go into a row where it scores a value.

So, the above code only goes to label 63 if X is equal to zero or if X is not equal to zero and flag 20 is set. That would indicate no second yahtzee so go to label 63.

The code below adds 100 to row 12 of the score card.

2
10^X
ST+ 12
>" "
ARCL X
PSE
AVIEW
PSE

Label 63 checks to see if the scorecard is full – which has happened if all flags 1-13 are set. Any clear flag means to keep playing. 

LBL 63
CLX
STO 20
1.013
LBL 75
FC? IND X
GTO 15
ISG X
GTO 75

The game is over at this point. Time to total up the scores and display the results

"DONE"
AVIEW
RCL 01
RCL 02
RCL 03
RCL 04
+
+
+
RCL 05
+
RCL 06
+
"TOP="
ARCL X
>"+"
63
X<=Y?
35
X>Y?
0
ARCL X

The above steps display a bonus of 35 points if the top six rows of the scorecard total 63 or greater.

X<>Y
RDN
+
AVIEW
PSE
RCL 07
RCL 08
RCL 09
+
+
RCL 11
+
RCL 12
+
RCL 13
+
"LOWER="
ARCL X
AVIEW
PSE
+
"END="
ARCL X
PROMPT
GTO 16

Pressing R/S after the END= score is shown will start a new game.

Label 25 displays the open score rows which will be the unset flags between 01 and 13.

LBL 25
CLA
1.013
LBL 00
FC? IND X
ARCL X
FC? IND X
>","
ISG X
GTO 00
AVIEW
PSE
GTO 61

Labels 01-06 do the scoring by checking for values of 1,2,3,4,5, or 6 in the 14.018 registers. Register 21 contains the value to look for and register 22 is the loop counter 14.018.

LBL 01
LBL 02
LBL 03
LBL 04
LBL 05
LBL 06
RCL IND 22
RCL 21
X=Y?
ST+ 20
ISG 22
GTO 06
RTN

Label 13 is the chance scoring row. It adds up the total of all dice.

LBL 13
FS?C 14
RTN

This flag is checked to indicate the program got here as a result of scoring a full house (LBL 09). A return is performed because even though 3 of a kind is present for a full house, the scoring is not done as 3 of a kind but a flat 25 points. The return goes back to LBL 09.

RCL 14
RCL 15
RCL 16
RCL 17
+
+
+
RCL 18
+
STO 20
RTN

Label 12 checks for a yahtzee, all five dice the same. If sorted, registers 14 and 18 should be equal.

LBL 12
RCL 18
RCL 14
X!=Y?
RTN
BEEP
50
STO 20
RTN

Label 07 checks for 3 of a kind. The first and third second and fourth, or third and fifth dice must be equal. Label 13 scores the total of all dice.

LBL 07
RCL 14
RCL 16
X=Y?
GTO 13
RCL 18
X=Y?
GTO 13
RCL 17
RCL 15
X=Y?
GTO 13
RTN

Label 08 checks for 4 of a kind. The first and fourth, or second and fifth dice must be equal. Label 13 scores the total of all dice.

LBL 08
RCL 14
RCL 17
X=Y?
GTO 13
RCL 15
RCL 18
X=Y?
GTO 13
RTN

Label 9 checks for a full house. By definition, there must be a 3 of a kind, so the routine executes label 07 to check for that first. If that is present, then registers 14/15 or 17/18 must be now be equal to be a full house.

LBL 09
SF 14
XEQ 07
FS?C 14
RTN

If Flag 14 is still set, it means 3 of a kind was not found. Flag 14 is cleared in the LBL 13 scoring routine which is only executed from this XEQ 07 call when 3 of a kind is present.

RCL 14
RCL 15
X!=Y?
RTN
RCL 17
RCL 18
X!=Y?
RTN
25
STO 20
RTN

Labels 10 and 11 check for a small straight and a large straight. Thanks to Guenter for this code!

LBL 10
XEQ 35
30
ENTER
7
GTO 36
LBL 11
XEQ 35
40
ENTER
6
LBL 36
RCL Z
X>Y?
RTN
RCL Z
STO 20
RTN
LBL 35
RCL 15
RCL 17
*
10
X=Y?
RTN
RCL 23
ISG X
RCL 14
ENTER
LBL 50
SIGN
+
RCL IND Y
X=Y?
DSE T
X<>Y
ISG Z
GTO 50
R^
RTN

Label 40 is the sorting routine. It sets degree mode (flag 43) upon entering. It compares adjacent registers and swaps them if out of order. When a swap is made, RAD mode and the RAD annunciator are set, which changes flag 43 status. At the end of a sweep through the registers, if RAD is set, a swap was made and the sort is not over.

I am ok shortening this LBL 40 routine with another sort, but I do find it kind of fun to see the RAD go on and off.

LBL 40
DEG
RCL 17
RCL 16
RCL 15
RCL 14
X>Y?
RAD
X>Y?
X<>Y
STO 14
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 15
RDN
X>Y?
RAD
X>Y?
X<>Y
STO 16
RDN
RCL 18
X<Y?
RAD
X<Y?
X<>Y
STO 18
X<>Y
STO 17

If flag 43 is set, then RAD mode is on and the list needs to be examined again.

FS? 43
GTO 40
END
Find all posts by this user
Quote this message in a reply
01-28-2016, 05:50 PM
Post: #14
RE: Ok, please look over the HP 41 Yahtzee game here
RAW file ready for prime time??

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
01-28-2016, 07:02 PM
Post: #15
RE: Ok, please look over the HP 41 Yahtzee game here
Regarding this section of code and converting it to a DSE 19 approach...

Code:
LBL 17
1
ST+ 19
RCL 19
3
X<=Y?
GTO 22

I have found that it raises my byte count by 4 bytes with changes that have to be made elsewhere. So, I think I will leave it as-is.

I am also changing line 134 which is presently an append blank space to an append + instead.

Angel, the .raw file will be sent by tomorrow if at all possible.
Find all posts by this user
Quote this message in a reply
01-28-2016, 08:18 PM
Post: #16
RE: Ok, please look over the HP 41 Yahtzee game here
20160128

Current .raw file for emulators:

YZ raw file

Current PDF of listing:

Yahztee PDF

Barcode (yes!) of current version:

Yahtzee barcode
Find all posts by this user
Quote this message in a reply
01-28-2016, 08:30 PM
Post: #17
RE: Ok, please look over the HP 41 Yahtzee game here
(01-28-2016 07:02 PM)Gene Wrote:  Angel, the .raw file will be sent by tomorrow if at all possible.

(01-28-2016 08:18 PM)Gene Wrote:  20160128

Current .raw file for emulators:

YZ raw file

Slow day at work? Wink

Oh, wait, what am I doing now?

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
01-28-2016, 08:34 PM
Post: #18
RE: Ok, please look over the HP 41 Yahtzee game here
Quiet lunch time.
Find all posts by this user
Quote this message in a reply
Post Reply 




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