Poker7

# Poker7 for the HP-41

Overview

0°)  Sorting the cards

a)  Focal Program
b)  M-Code Routine
c)  Sorting 7 cards

a)  Program#1
b)  Values of the Combinations ( Focal program & M-Code Routine )
c)  Program#2: N-card Poker ( N < 11 )

2°)  Playing against ( or with ) your HP-41

a)  Values of the Combinations ( Focal program & M-Code Routine )
b)  Program #3  ( N < 10 )

-The programs listed in paragraph 1-a) & 1-c) are quite similar to "POKER1" that is listed in "Poker for the HP-41" paragraph 2°):
-You play with your calculator but you receive 7 cards with"POK7" or N cards with "POKN" ( N < 11 ) instead of 5.
-There are also 2 discards ( if N > 6 ) instead of 1.

-In paragraph 1°) , your HP-41 is like a one-arm bandit.
-In paragraph 2°) you play against your HP-41 if F07 is clear, with your HP-41 if F07 is set.

0°)  Sorting the cards

a)  Focal Program

-This program is just a variant of one of the programs listed in "Sorting Numbers for the HP-41"
-Here, the numbers are sorted in decreasing order.

Data Registers:   R00-R01- ..... -Rnn  ( R00 is actually unused )
Flags: /
Subroutines: /

-Lines 08 to 13 may be replaced by

RCL IND Y
X>Y?
GTO 03
X<>Y
LASTX
+
LBL 03
RDN

 01  LBL "SRT"   02  SIGN 03  LBL 01 04  LASTX 05  LASTX 06  RCL IND L  07  LBL 02  08  X<=NN? 09  GTO 03  10  X<>Y  11  STO Y  12  RCL IND X 13  LBL 03  14  DSE Y  15  GTO 02  16  X<> IND L 17  STO IND Z  18  DSE L 19  GTO 01 20  END

( 39 bytes )

 STACK INPUT OUTPUT X N /

where  N  is the number of registers

Example:

-To sort registers  R01 thru R07:

7  XEQ "SRT"

Notes:

-Execution time = 6.5 seconds ( for 7 cards )
-More than 12 seconds are required to sort 10 cards, so an M-code routine is quite useful !

b)  M-Code Routine

-We can use the M-Code routine that is listed in "Sorting Numbers for the HP-41"
-But the "cards" are stored in registers R01 thru Rnn under the form of integers between 10 and 99
-So, the M-Code instruction ?A<C ALL may be employed for even faster results !

094     "T"
012     "R"
013     "S"
0F8     READ 3(X)                  The first executable word
38D     ?NCXQ                       Change the integer in C
008      02E3                            into an hexadecimal in C: S&X
2E6     ?C#0 S&X
3A0     ?NC RTN                    The routine stops here if this integer = 0
05A     C=0 M
23A     C=C+1 M
10E     A=C ALL
03C     RCR 3
0E6     B<>C S&X
0E6     B<>C S&X
20E     C=A+C S&X
070     N=C ALL
106     A=C S&X
130      LDI S&X                  200 hexadecimal = 512 decimal is the correct value if you have an HP-41CV/CX or an HP-41C with a quad memory module.
200      CON: 512                 Replace this line by 100h = 256d if you have an HP-41C without any memory module.
306      ?A<C S&X
381      ?NCGO                   -If register RNN doesn't exist,
00A      02E0                         you'll get a "NON EXISTENT" message and the routine stops
0B0      C=N ALL
033      JNC +06
270      RAMSLCT                     loop1
0EE     C<>B ALL
2F0      WRIT DATA
198      C=M ALL
266      C=C-1 S&X
158      M=C ALL
106      A=C S&X
03C     RCR 3
070      N=C ALL
366      ?A#C S&X
3A0     ?NC RTN
270      RAMSLCT
0EE     C<>B ALL
198      C=M ALL                       loop2
106      A=C S&X
0B0      C=N ALL
366      ?A#C S&X
373      JNC -18d                       goto loop1
226      C=C+1 S&X
070      N=C ALL
270      RAMSLCT
06E      A<>B ALL
30E      ?A<C ALL
013      JNC+02
0AE     A<>C ALL
0EE     C<>B ALL
0B0     C=N ALL
266      C=C-1 S&X
270      RAMSLCT
0AE     A<>C ALL
2F0      WRIT DATA
36B      JNC-19d                        goto  loop2

( 60 word )

 STACK INPUT OUTPUT X N N

Where  N  is the number of registers = the number of cards in R01 thru RNN
The stack is actually unchanged.

-Execution time = 0.2 second to sort 7 cards
-Execution time = 0.3 second to sort 10 cards.

c)  Sorting 7 cards

-If you have the possibility to use M-Code routines,  SRT  is of course very fast.
-Otherwise, the following focal program may be used to sort 7-card hands.
-Though much slower than the M-Code routine, it is however much faster than the program listed in paragraph 0°)a) above

Data Registers:   R00-R01- ..... -Rnn
Flags: /
Subroutines: /

 01  LBL "SRT7"  02  RCL 01   03  RCL 02        04  X>Y?  05  X<>Y  06  RCL 03  07  X>Y?  08  X<>Y  09  RCL 04   10  XY  12  X<> 05 13  XY  15  X<> 06   16  XY  18  X<> 07        19  X>Y?  20  X<>Y  21  X<> 07   22  X>Y?  23  X<>Y  24  R^ 25  X>Y?  26  X<>Y  27  R^  28  XY  30  X<> 05   31  XY  33  X<> 06        34  X>Y?  35  X<>Y  36  X<> 06 37  X>Y?  38  X<>Y  39  R^  40  X>Y?  41  X<>Y  42  R^  43  XY  45  X<> 05        46  X>Y?  47  X<>Y  48  X<> 05 49  X>Y?  50  X<>Y  51  R^  52  X>Y?  53  X<>Y  54  RDN  55  X>Y?  56  X<>Y  57  RDN  58  XY  60  STO 01 61  RDN  62  X>Y?  63  X<>Y  64  STO 04  65  RDN  66  X>Y?  67  X<>Y  68  STO 03        69  X<>Y  70  STO 02   71  END

( 89 bytes / SIZE 008 )

 STACK INPUT OUTPUT X / /

-Execution time = 1.4 second
-Register R00 is unused.

a)  Program#1

-The following values are returned by XEQ 10 ( line 114 )

 combinations value high card 0 1 pair 1 2 pairs 2 3 pairs 3 3 of a kind 4 3 of a kind + 1 pair 5 3 of a kind + 2 pairs 6 Two "3 of a kind" 7 4 of a kind 8 4 of a kind + 1 pair 9 4 of a kind + 3 of a kind 10 a straight 11 5 of a kind 12 5 of a kind + 1 pair 13 6 of a kind 14 7 of a kind 15

-They don't always correspond to the probabilities of the combinations, especially after 2 discards.
-Of course, you can change the corresponding lines to use different values if you prefer...

Data Registers:           •  R00 = random numbers           ( Registers R00 & R23 are to be initialized before executing "POK7" )

R01 to R07 = your 7 cards   ;   R08 thru R22: temp
Flag:   F10
Subroutines:   "SRT" or "SRT7"  listed above

-The append character is denoted  ~  ( lines 93 & 95 )
-Lines 100-118-121-330  are three-byte GTO's

-Line 67  SRT  is the M-Code routine listed in paragraph 0°)b)
-If you employ the focal program "SRT", replace line 67 by  XEQ "SRT"  7

-Lines 66-67 may also be replaced with  XEQ "SRT7"  7   where "SRT7"  is listed just above.

 01  LBL "POK7"   02  "A"   03  ASTO 22   04  "K"   05  ASTO 21   06  "Q"   07  ASTO 20   08  "J"   09  ASTO 19   10  17   11  "T"   12  ASTO 18   13  9   14  LBL 00   15  STO IND Y   16  DSE Y   17  DSE X   18  GTO 00   19  13   20  STO 08   21  10   22  STO 09   23  LBL 01   24  SF 10   25  FIX 0   26  CF 29   27  " "   28  7   29  LBL 02    30  ENTER^   31  XEQ 07   32  ARCL IND X   33  AVIEW   34  X<>Y   35  DSE X   36  GTO 02   37  LBL 03   38  56   39  GETKEYX   40  X=0?   41  GTO 08   42  LASTX   43  -   44  CLRGX   45  GTO 03   46  LBL 08   47  " "   48  7   49  LBL 04   50  RCL IND X   51  X#0?   52  ARCL IND X   53  X<>Y   54  DSE X   55  GTO 04   56  AVIEW   57  7   58  LBL 05   59  RCL IND X   60  X=0?   61  XEQ 07   62  X<>Y   63  DSE X   64  GTO 05   65  " "   66  7   67  SRT   68  LBL 06   69  RCL IND X   70  ARCL IND X   71  LN   72  AVIEW   73  X<>Y   74  DSE X   75  GTO 06   76  FS?C 10   77  GTO 03   78  XEQ 10   79  3   80  -   81  RCL 00   82  FRC   83  4   84  /   85  8    86  + 87  E^X   88  *   89  ST+ 23   90  RCL 23   91  "  "   92  X>0?   93  "~+"   94  ARCL 23   95  "~ \$"   96  AVIEW   97  FIX 4   98  SF 29   99  RTN 100  GTO 01 101  LBL 07 102  CLX 103  RCL 00 104  R-D 105  FRC 106  STO 00 107  RCL 08 108  * 109  INT 110  RCL 09 111  + 112  STO IND Y  113  RTN 114  LBL 10  115  RCL 07  116  RCL 06 117  X=Y? 118  GTO 07 119  RCL 05 120  X=Y? 121  GTO 08 122  RCL 04 123  X=Y? 124  GTO 09 125  RCL 03 126  X=Y? 127  GTO 10 128  RCL 02 129  X=Y? 130  GTO 11 131  RCL 01 132  X=Y? 133  GTO 12 134  RCL 07 135  - 136  6 137  X=Y? 138  GTO 13 139  RCL 02         140  LASTX 141  - 142  5 143  X#Y? 144  GTO 14 145  R^ 146  12 147  X=Y? 148  GTO 13 149  LBL 14 150  4 151  CHS 152  RTN 153  LBL 13 154  11 155  RTN 156  LBL 12 157  SIGN 158  RTN 159  LBL 11 160  RCL 01 161  X=Y? 162  GTO 11 163  SIGN 164  RTN 165  LBL 11 166  4 167  RTN 168  LBL 10 169  RCL 02 170  X=Y? 171  GTO 10 172  RCL 01 173  X=Y? 174  GTO 11 175  SIGN 176  RTN 177  LBL 11 178  2 179  RTN 180  LBL 10 181  RCL 01 182  X=Y? 183  GTO 10 184  4 185  RTN 186  LBL 10 187  8 188  RTN 189  LBL 09 190  RCL 03 191  X=Y? 192  GTO 09 193  RCL 02  194  X=Y? 195  GTO 10  196  RCL 01  197  X=Y? 198  GTO 11  199  SIGN 200  RTN 201  LBL 10 202  RCL 01 203  X=Y? 204  GTO 10 205  2 206  RTN 207  LBL 10 208  5 209  RTN 210  LBL 11 211  2 212  RTN 213  LBL 09 214  RCL 02 215  X=Y? 216  GTO 09 217  RCL 01 218  X=Y? 219  GTO 10 220  4 221  RTN 222  LBL 10 223  5 224  RTN 225  LBL 09          226  RCL 01  227  X=Y? 228  GTO 09 229  8 230  RTN 231  LBL 09 232  12 233  RTN 234  LBL 08 235  RCL 04 236  X=Y? 237  GTO 08 238  RCL 03 239  X=Y? 240  GTO 09 241  RCL 02 242  X=Y? 243  GTO 10 244  RCL 01 245  X=Y? 246  GTO 11 247  SIGN 248  RTN 249  LBL 11 250  2 251  RTN 252  LBL 10 253  RCL 01 254  X=Y? 255  GTO 10 256  2 257  RTN 258  LBL 10 259  5 260  RTN 261  LBL 09 262  RCL 02 263  X=Y? 264  GTO 09 265  RCL 01 266  X=Y? 267  GTO 10 268  2 269  RTN 270  LBL 10 271  3 272  RTN 273  LBL 09 274  RCL 01 275  X=Y? 276  GTO 09 277  5 278  RTN 279  LBL 09  280  9 281  RTN 282  LBL 08 283  RCL 03  284  X=Y? 285  GTO 08 286  RCL 02  287  X=Y? 288  GTO 09 289  RCL 01 290  X=Y? 291  GTO 10 292  4 293  RTN 294  LBL 10 295  5 296  RTN 297  LBL 09 298  RCL 01 299  X=Y? 300  GTO 09 301  5 302  RTN 303  LBL 09 304  7 305  RTN 306  LBL 08 307  RCL 02 308  X=Y? 309  GTO 08 310  RCL 01  311  X=Y? 312  GTO 09         313  8 314  RTN 315  LBL 09 316  9 317  RTN 318  LBL 08 319  RCL 01 320  X=Y? 321  GTO 08 322  12 323  RTN 324  LBL 08 325  14 326  RTN 327  LBL 07 328  RCL 05 329  X=Y? 330  GTO 07 331  RCL 04 332  X=Y? 333  GTO 08 334  RCL 03 335  X=Y? 336  GTO 09 337  RCL 02 338  X=Y? 339  GTO 10 340  RCL 01 341  X=Y? 342  GTO 11 343  SIGN 344  RTN 345  LBL 11 346  2 347  RTN 348  LBL 10 349  RCL 01 350  X=Y? 351  GTO 10 352  2 353  RTN 354  LBL 10 355  5 356  RTN 357  LBL 09 358  RCL 02 359  X=Y? 360  GTO 09 361  RCL 01 362  X=Y? 363  GTO 10 364  2 365  RTN 366  LBL 10  367  3 368  RTN 369  LBL 09  370  RCL 01  371  X=Y? 372  GTO 09  373  5 374  RTN 375  LBL 09 376  9 377  RTN 378  LBL 08 379  RCL 03 380  X=Y? 381  GTO 08 382  RCL 02 383  X=Y? 384  GTO 09 385  RCL 01 386  X=Y? 387  GTO 10 388  2 389  RTN 390  LBL 10  391  3 392  RTN 393  LBL 09 394  RCL 01 395  X=Y? 396  GTO 09 397  3 398  RTN 399  LBL 09         400  6 401  RTN 402  LBL 08 403  RCL 02  404  X=Y? 405  GTO 08 406  RCL 01 407  X=Y? 408  GTO 09 409  5 410  RTN 411  LBL 09 412  6 413  RTN 414  LBL 08 415  RCL 01 416  X=Y? 417  GTO 08 418  9 419  RTN 420  LBL 08 421  13 422  RTN 423  LBL 07 424  RCL 04 425  X=Y? 426  GTO 07 427  RCL 03 428  X=Y? 429  GTO 08 430  RCL 02 431  X=Y? 432  GTO 09 433  RCL 01 434  X=Y? 435  GTO 10 436  4 437  RTN 438  LBL 10 439  5 440  RTN 441  LBL 09 442  RCL 01 443  X=Y? 444  GTO 09 445  5 446  RTN 447  LBL 09 448  7 449  RTN 450  LBL 08 451  RCL 02  452  X=Y? 453  GTO 08  454  RCL 01  455  X=Y? 456  GTO 09  457  5 458  RTN 459  LBL 09 460  6 461  RTN 462  LBL 08 463  RCL 01 464  X=Y? 465  GTO 08 466  7 467  RTN 468  LBL 08 469  10 470  RTN 471  LBL 07 472  RCL 03 473  X=Y? 474  GTO 07 475  RCL 02 476  X=Y? 477  GTO 08 478  RCL 01 479  X=Y? 480  GTO 09 481  8 482  RTN 483  LBL 09         484  9 485  RTN 486  LBL 08 487  RCL 01  488  X=Y? 489  GTO 08 490  9 491  RTN 492  LBL 08 493  10 494  RTN 495  LBL 07 496  RCL 02 497  X=Y? 498  GTO 07 499  RCL 01 500  X=Y? 501  GTO 08 502  12 503  RTN 504  LBL 08 505  13 506  RTN 507  LBL 07 508  RCL 01 509  X=Y? 510  GTO 07 511  14 512  RTN 513  LBL 07 514  15 515  END

( 671 bytes / SIZE 024 )

 STACK INPUTS OUTPUTS X / /

Example:      With the random seed 1 in R00 and 0 in R23

>>>>  Compile the GTO 03 lines 45 & 77 before the 1st execution:  In RUN mode,  GTO .045  SST  and  GTO .077  SST

-Anyway  0  STO 23  1  STO 00   XEQ "POK7"  the HP-41 displays gradually the 7 cards  5A59A37      you have 2 pairs
-If you want to discard the cards n°4-6-7 ( seen from the left )

Press   4   6   7    ENTER^   you get      5A5A    the 4 remainig cards, then HP-41 displays  gradually    559JKAA

-If you want to discard the cards n°3-4-5

Pres     3   4   5    ENTER^    you get     55AA    and then are displayed gradually    5568JAA    followed by your cash   -3226 \$

-You lost 3226 \$

•  To continue the game, press R/S you'll see ( one card after the other )   3JT3A38              you already have a 3 of a kind

-If you discard the cards n°2-3-5-7 press   2  3  5  7  ENTER^    you see    333    followed by   333566T
-You discard the"5" & the 'T"          press     4  7    ENTER^        -------   33366  ------------   233366A  and then  +2738 \$

-You had a "3 of a kind" + 1 pair

•  One more time  R/S  >>>>  32J8QT3    a pair of "3"

-You discard all the cards execpt the 3's     2  3  4  5  6   ENTER^    it yields    33    followed by    33337JK
-To discard the last 3 cards, you press            5  6  7       ENTER^    -------   3333 ------------     333335T   then   +34380 \$

-You had a "5 of a kind"

•  and so on  R/S  ......

Notes:

-"POK7" subtracts 3 ( lines 79-80 ) to the values given by XEQ 10
-Even then, you will probably win more often than you will lose !
-Change these lines according to your preferences...

-The unit bet is randomly computed ( approximately between 3000\$ and 3800\$ - lines 81 to 87 )
but if you want to place your own bets:

-Replace lines 81 to 87 by  RCL 24
-Replace line 23  by  R^  LBL 01  FS?C 22  STO 24

-Place your bet in X-register before XEQ "POK7"  or  R/S
-If you want to use the same bet, simply press R/S without any digit entry

-You can press other keys ( instead of ENTER^ )
provided it's neither a numeric key nor CHS nor the decimal point.

b)  Values of the Combinations  ( Focal program & M-Code Routine )

-This program calculates the value of a combination as follows:
-One pair = 1 point , one "three of a kind" = 4 points , one "four of a kind" = 9 points , .... , one "k of a kind" = (k-1)2

-For 7-card hands, we get:

 combinations value high card 0 1 pair 1 2 pairs 2 3 pairs 3 3 of a kind 4 3 of a kind + 1 pair 5 3 of a kind + 2 pairs 6 Two "3 of a kind" 8 4 of a kind 9 4 of a kind + 1 pair 10 4 of a kind + 3 of a kind 13 a straight* 0 5 of a kind 16 5 of a kind + 1 pair 17 6 of a kind 25 7 of a kind 36

*The "straights" must be evaluated  differently.

-These values are not exactly the same as those used in "POK7"

 01  LBL "VAL"   02  CLA  03  LBL 01   04  ENTER^  05  ENTER^  06  SIGN  07  ST- Y 08  CLX  09  X<> IND Z  10  LBL 02  11  RCL IND Y  12  X=Y?  13  X=0?  14  GTO 03 15  SIGN  16  ST+ N  17  CLX  18  STO IND Z  19  LBL 03  20  RDN  21  DSE Y 22  GTO 02       23  CLX  24  X<> N  25  X^2  26  ST+ M  27  SIGN  28  RCL Z 29  RCL Y         30  -  31  X>Y?  32  GTO 01   33  CLX  34  X<> M  35  END

( 57 bytes / SIZE NNN+1 )

 STACK INPUTS OUTPUTS X N value

Where N = number of cards ( in R01 thru RNN )

Examples:

-If  R01 = R02 = R03 = R04 = 20 & R05 = R06 = R07 = 18  ( a "4 of a kind" + a "3 of a kind"  in a 7-card hand ):

7  XEQ "VAL"  >>>>  13                                               ---Execution time = 6.8s---

-If  R01 = R02 = R03 = R04 = 20 ,  R05 = R06 = R07 = 18 , R08 = R09 = 16 , R10 = 15

( a "4 of a kind" + a "3 of a kind" + a pair  in a 10-card hand ):

10   XEQ "VAL"  >>>>  14                                             ---Execution time = 12.7s---

Notes:

-Registers R01 to Rnn are modified.
-This program is slow with 7 cards and very slow with 10 cards
-So, an M-code routine is preferable...

-The same results are obtained more quickly by VAL

08C  "L"
001   "A"
016   "V"
0F8   C=X
38D   ?NCXQ
008    C->S&X
2E6   ?C#0 S&X
3A0   ?NC RTN                  The routine stops here if N = 0
106  A=C S&X
130  LDI S&X
00B  11d
306  ?A<C S&X
0B5   ?NCGO
0A2   DATAERROR          The routine stops here and the HP-41 displays "DATA ERROR"  if  N > 10
04E   C=0 ALL
0E8   X=C
0A8   Y=C
378   C=c
03C   RCR 3
146   A=A+C S&X
130   LDI S&X
200   200h
306   ?A<C S&X
381   ?NCGO                    If register RNN doesn't exist,
00A   NONEXISTENT     you'll get a "NON EXISTENT" message and the routine stops
378   C=c
0A6  A<>C S&X
070   N=C ALL
0B0   C=N ALL
106   A=C S&X               Loop1
266   C=C-1 S&X
1BC  RCR 11
0A6  A<>C S&X
070   N=C ALL
03C  RCR 3
106  A=C S&X
03C  RCR 3
366   ?A#C S&X
3A0  ?NC RTN
0B0  C=N ALL
270   RAMSLCT
0EE  B<>C ALL
04E  C=0 ALL
2F0  WRITDATA
06E  A<>B ALL              Loop2
08E  B=A ALL
0B0  C=N ALL
03C  RCR 3
270  RAMSLCT
36E  ?A#C ALL
077   JC+14d
2EE  ?C#0 ALL
063   JNC+12d
046   C=0 S&X
270   RAMSLCT
0B8  C=Y
35C  PT=12
222   C=C+1@PT
0A8  Y=C
0B0  C=N ALL
03C  RCR 3
270   RAMSLCT
04E   C=0 ALL
2F0   WRITDATA
0B0  C=N ALL
27A  C=C-1 M
070   N=C ALL
03C  RCR 3
106  A=C S&X
03C  RCR 3
366  ?A#C S&X
327   JC-28d                     GOTO Loop2
04E  C= 0 ALL
270   RAMSLCT
0B8  C=Y
10E  A=C ALL
2A0  SETDEC
135   C=
060  A*C
04E  C=0 ALL
0A8  Y=C
0F8   C=X
025   C=
060  AB+C
0E8  X=C
260  SETHEX
0B0  C=N ALL
266  C=C-1 S&X
21B  JNC-61d                 GOTO Loop1

( 91 words / SIZE NNN+1 )

 STACK INPUTS OUTPUTS X N value

Where N = number of cards ( in R01 thru RNN )

Example:

-If  R01 = R02 = R03 = R04 = 20 & R05 = R06 = R07 = 18  ( a "4 of a kind" + a "3 of a kind"  in a 7-card hand ):

7  XEQ "VAL"  >>>>  13                                               ---Execution time = 0.4s---

-If  R01 = R02 = R03 = R04 = 20 ,  R05 = R06 = R07 = 18 , R08 = R09 = 16 , R10 = 15

( a "4 of a kind" + a "3 of a kind" + a pair  in a 10-card hand ):

10   XEQ "VAL"  >>>>  14                                             ---Execution time = 0.6s---

Notes:

-Registers R01 thru RNN are modified too.
-Y-register is cleared
-Registers X & Y are overwritten.

c)  Program#2: N-card Poker  ( N < 11 )

-A single program may be written to deal with N cards, provided N < 11.

Data Registers:           •  R00 = random numbers           ( Registers R00 & R23 are to be initialized before executing "POKN" )

R01 to R10 = your cards   ;   R11 thru R26: temp
Flag:   F10
Subroutines:   2 M-Code routines:  SRT ( line 79 ) cf paragraph 0°)b)
VAL ( line 149 ) cf paragraph 1°)b)

-If you employ the focal program "SRT" , replace line  79 with  XEQ "SRT"  RCL 11
--------------------------------- "VAL" , ----------- 149  by   XEQ "VAL"

-The append character is denoted  ~  ( lines 107 & 109 )
-Line 114 is a three-byte GTO 01

 01  LBL "POKN"   02  "A"   03  ASTO 26   04  "K"   05  ASTO 25   06  "Q"   07  ASTO 24   08  "J"   09  ASTO 23   10  21   11  "T"   12  ASTO 22   13  9   14  LBL 00   15  STO IND Y    16  DSE Y   17  DSE X   18  GTO 00   19  X<> Z   20  STO 11   21  13   22  STO 12   23  14   24  STO 13   25  LBL 01   26  SF 10   27  FIX 0   28  CF 29 29  " "   30  7   31  RCL 11   32  XY   40  DSE X   41  GTO 02   42  LBL 03   43  49   44  RCL 11   45  +   46  GETKEYX   47  X=0?   48  GTO 08   49  RCL 11   50  CHS   51  X<>Y   52  LASTX   53  -   54  XY   66  DSE X   67  GTO 04   68  AVIEW   69  RCL 11   70  LBL 05   71  RCL IND X   72  X=0?   73  XEQ 07   74  X<>Y   75  DSE X   76  GTO 05   77  " "   78  RCL 11   79  SRT   80  LBL 06   81  RCL IND X   82  ARCL IND X   83  LN   84  AVIEW 85  X<>Y   86  DSE X   87  GTO 06   88  FS?C 10   89  GTO 03   90  XEQ 10   91  4   92  +   93  RCL 11    94  -   95  RCL 00   96  FRC   97  4   98  /   99  8 100  + 101  E^X 102  * 103  ST+ 27 104  RCL 27 105  "  " 106  X>0? 107  "~+" 108  ARCL 27       109  "~ \$" 110  AVIEW 111  FIX 4 112  SF 29 113  RTN 114  GTO 01 115  LBL 07 116  CLX 117  RCL 00 118  R-D 119  FRC 120  STO 00 121  RCL 12  122  * 123  INT 124  RCL 13 125  + 126  STO IND Y   127  RTN 128  LBL 10 129  RCL 11 130  2 131  - 132  RCL 02 133  RCL IND 11 134  - 135  X#Y? 136  GTO 09 137  12 138  RCL 01 139  LASTX 140  - 141  X=Y? 142  SF 10 143  RCL 11 144  DSE X 145  X=Y? 146  SF 10 147  LBL 09 148  RCL 11  149  VAL 150  FS?C 10 151  X#0? 152  GTO 08         153  RCL 11  154  ST+ X 155  3 156  - 157  RTN 158  LBL 08  159  X#0? 160  RTN 161  RCL 11 162  CHS 163  END

( 250 bytes / SIZE 028 )

 STACK INPUTS OUTPUTS X N /

Where N is the number of cards ( not exceeding 10 ) in one hand.

Notes:

-With N = 7 & 1 STO 00 ,    1  STO 00   7   XEQ "POKN"

you will get the same hands as above but your last cash will be  +48443 \$  instead of +34380 \$

-With N = 10, simply press 0  to discard the 10th card.
-If you never want to use N = 10, delete lines 55-54-51-50-49

-If  N < 7 , there is only one discard ( lines 30-31-32-33 ).

-The value of a high card is -N ( lines 158-159 )
-The value of a straight is  2N - 3 ( lines 150 to 153 )

>>>>  ( N - 4 ) is subtracred to all these values ( lines 91 to 94 )  to get a more equitable game

-You can of course change these numbers according to your preferences...

-After discarding all the cards you want to you exchange, you can press other keys ( instead of ENTER^ )
provided it's neither a numeric key nor CHS nor the decimal point.

2°)  Playing against or with your HP-41

a)  Values of the Combinations  ( Focal program & M-Code Routine )

-This variant of "VAL"  returns the same value of the combination in X-register as above,
but it also returns the cards to be discarded in Y-register.
-The cards are supposed to be in register  R01 thru RNN ( N < 10 )

-Line 02 may be replaced by  ENTER^  CLX  ( faster )
-Registers R12-R13-R14 could be replaced by synthetic registers M , N , O
but that would change the alpha register and the display too.

 01  LBL "VAL"   02  0  03  STO 12  04  STO 13  05  STO 14  06  X<>Y  07  LBL 01  08  ENTER^  09  ENTER^  10  SIGN  11  ST- Y  12  CLX 13  X<> IND Z  14  X=0?  15  GTO 04  16  LBL 02  17  RCL IND Y  18  X#Y?  19  GTO 03  20  SIGN  21  ST+ 13  22  CLX  23  STO IND Z  24  LBL 03 25  RDN  26  DSE Y  27  GTO 02        28  X<>Y  29  X<> 13  30  X^2  31  ST+ 12  32  X#0?  33  GTO 04  34  X<>Y  35  X=0?  36  GTO 04 37  SIGN  38  10^X  39  ST* 14  40  X<> Z  41  ST+ 14  42  X<> Z  43  LBL 04         44  SIGN  45  RCL Z  46  DSE X  47  X>Y?  48  GTO 01 49  RCL 01  50  X=0?  51  GTO 03         52  SIGN  53  10^X  54  ST* 14  55  SIGN  56  ST+ 14  57  LBL 03  58  X<> 14  59  RCL 12  60  END

( 92 bytes )

 STACK INPUTS OUTPUTS Y / cards to exchange X N < 9 value

Where N = number of cards ( in R01 thru RNN )

Examples:

-If  R01 = R02 = R03 = R04 = 20 & R05 = R06 = R07 = 18

( a "4 of a kind" + a "3 of a kind"  in a 7-card hand ):

7  XEQ "VAL"  >>>>  13                                               ---Execution time = 4.5s---
X<>Y  0

>>>  The value = 13 and no card must be exchanged.

-If  R01 = R02 = R03 = R04 = 20 ,  R05 = R06 = R07 = 18 , R08 = 16 ,  R09 = 15

( a "4 of a kind" + a "3 of a kind"  in a 9-card hand ):

9   XEQ "VAL"  >>>>  13                                             ---Execution time = 8.8s---
X<>Y   98

>>>  The value = 13 and the cards n°8 & n°9 must be discarded.

Notes:

-Registers R01 to Rnn are modified.
-With N = 9, the execution time is between 5 seconds and 12.6 seconds
-So, the following M-Code routine is much better:

08C  "L"
001   "A"
016   "V"
0F8   C=X
38D   ?NCXQ
008    C->S&X
2E6   ?C#0 S&X
3A0   ?NC RTN                  The routine stops here if N = 0
106  A=C S&X
130  LDI S&X
00A  10d
306  ?A<C S&X
0B5   ?NCGO
0A2   DATAERROR          The routine stops here and the HP-41 displays "DATA ERROR"  if  N > 9
04E   C=0 ALL
0E8   X=C
0A8   Y=C
068   Z=C
378   C=c
03C   RCR 3
146   A=A+C S&X
130   LDI S&X
200   200h
306   ?A<C S&X
381   ?NCGO                    If register RNN doesn't exist,
00A   NONEXISTENT     you'll get a "NON EXISTENT" message and the routine stops
378   C=c
0A6  A<>C S&X
070   N=C ALL
106   A=C S&X               Loop1
266   C=C-1 S&X
1BC  RCR 11
0A6  A<>C S&X
070   N=C ALL
03C  RCR 3
106  A=C S&X
03C  RCR 3
366   ?A#C S&X
0A7  JC+20d
0B0  C=N ALL
270   RAMSLCT
2EE  ?C#0 ALL
043   JNC+08
04E  C=0 ALL
270  RAMSLCT
0B8  C=Y
3DA RSHFC M
35C  PT=12
222  C=C+1 @PT
033  JNC+06
270  RAMSLCT
0B8  C=Y
2EE  ?C#0 ALL
013  JNC+02
266  C=C-1 S&X
0A8  Y=C
3E0  RTN                                               The routine stops here
0B0  C=N ALL
270  RAMSLCT
0EE  B<>C ALL
04E  C=0 ALL
2F0  WRITDATA
013  JNC+02
2E3  JNC-36d
06E  A<>B ALL              Loop2
08E  B=A ALL
0B0  C=N ALL
03C  RCR 3
270  RAMSLCT
36E  ?A#C ALL
077   JC+14d
2EE  ?C#0 ALL
063   JNC+12d
046   C=0 S&X
270   RAMSLCT
078  C=Z
35C  PT=12
222   C=C+1@PT
068  Z=C
0B0  C=N ALL
03C  RCR 3
270   RAMSLCT
04E   C=0 ALL
2F0   WRITDATA
0B0  C=N ALL
27A  C=C-1 M
070   N=C ALL
03C  RCR 3
106  A=C S&X
03C  RCR 3
366  ?A#C S&X
327   JC-28d                     GOTO Loop2
04E  C= 0 ALL
270   RAMSLCT
078  C=Z
2EE  ?C#0 ALL
08F  JC+17d
0CE C=B ALL
2EE  ?C#0 ALL
073  JC+14d
0B0  C=N ALL
106  A=C S&X
17C  RCR 6
246  C=A-C S&X
23C RCR 2
35C PT=12
102  A=C @PT
0B8  C=Y
3DA RSHFC M
0A2  A<>C @PT
226  C=C+1 S&X
0A8 Y=C
05B  JNC+11d
10E  A=C ALL
2A0  SETDEC
135   C=
060  A*C
04E  C=0 ALL
068  Z=C
0F8   C=X
025   C=
060  AB+C
0E8  X=C
260  SETHEX
0B0  C=N ALL
266  C=C-1 S&X
203  JNC-64d                 GOTO Loop1

( 130 words / SIZE NNN+1 )

 STACK INPUTS OUTPUTS Y / cards to exchange X N < 9 value

Where N = number of cards ( in R01 thru RNN )

Examples:

-If  R01 = R02 = R03 = R04 = 20 & R05 = R06 = R07 = 18

( a "4 of a kind" + a "3 of a kind"  in a 7-card hand ):

7  XEQ "VAL"  >>>>  13                                               ---Execution time = 0.4s---
X<>Y  0

>>>  The value = 13 and no card must be exchanged.

-If  R01 = R02 = R03 = R04 = 20 ,  R05 = R06 = R07 = 18 , R08 = 16 ,  R09 = 15

( a "4 of a kind" + a "3 of a kind"  in a 9-card hand ):

9   XEQ "VAL"  >>>>  13                                             ---Execution time = 0.5s---
X<>Y  89

>>>  The value = 13 and the cards n°8 & n°9 must be discarded.

b)  Program #3  ( N < 10 )

-If flag F07 is set, this program works like "POKN" listed in paragraph 1°)c)
-If flag F07 is clear, you play against your HP-41:

•  You receive N cards and the HP-41 also receives N cards ( 2000\$ are automatically placed on the table - line 32 )
•  After displaying your cards twice, GETKEY is used to place your bet:

SIGMA+  corresponds to a bet of about   1668 \$   ..................     LN   corresponds to a bet of about   3103 \$
X<>Y      corresponds to a bet of about   6081 \$   ..................   TAN  corresponds to a bet of about   8619 \$
SHIFT     corresponds to a bet of about  13253 \$  ..................    SST  corresponds to a bet of about  16894 \$

.....................................................................................................................................................................

. / .          corresponds to a bet of about   90480 \$  .................    R/S   corresponds to a bet of about   97307 \$

>>> More exactly, the formula is    Bet = [ ( keycode ) Ln(41) ]2

-There are, however, 2 exceptions:  press ENTER^  to accept the HP41's  raise  and press  the backarrow key if you want to fold.

•  Then, if you want to discard some cards, say the cards n° 1 3 5 ( seen from the left ),
simply press  1  3  5  ENTER^  ( not too quickly ) - the program doesn't stop.
•  Place your bet as before and - if N > 6 - discard other cards if need be
•  Bets again and, if none has folded, the HP41 shows its cards
•  Finally, your cash is displayed.

•  Press R/S to continue the game...

Data Registers:           •  R00 = random numbers              ( Registers R00 & R41 are to be initialized before executing "POKN" )

R01 to R09 = your cards   ;   R10 thru R44+N: temp

Flags:  F07-F08-F09-F10

CF 07 if you want to play against your HP-41
SF 07 if you want to play with your HP-41

Subroutines:   3 M-Code routines:   SRT  cf paragraph 0-b)
VAL  cf paragraph 2-b)
CARD  cf "Poker for the HP-41"

-If you use the focal program "SRT" , replace line 213 by  XEQ "SRT"  RCL 11
-The M-Code routine CARD may be replaced by  XEQ 16 ( lines 54-58-171-192 )
-Simply add  LBL 16  RCL 00  R-D  FRC  STO 00  13  *  INT  28  +  after line 325

-Lines 96-111-201-256  are three-byte GTO's
-Line 249 = append +

 01  LBL "POKN"   02  "A"   03  ASTO 40   04  "K"   05  ASTO 39   06  "Q"   07  ASTO 38   08  "J"   09  ASTO 37   10  35   11  "T"   12  ASTO 36   13  9   14  LBL 00   15  STO IND Y    16  DSE Y   17  DSE X   18  GTO 00   19  1.045   20  R^   21  STO 11   22   E6   23  /   24  +   25  STO 26   26  .03   27  -   28  STO 27   29  LBL 01   30  FIX 0   31  CF 29   32  2 E3   33  STO 42   34  3   35  STO 43   36  SIGN   37  RCL 00   38  R-D   39  FRC   40  STO 00   41  X^2    42  -   43  STO 44   44  RCL 11   45  STO 13   46  7   47  X>Y?   48  DSE 43   49  ST+ X   50  +   51  STO 12   52  " "   53  LBL 02   54  CARD   55  STO IND 13 56  ARCL IND X   57  FC? 07   58  CARD   59  STO IND 12   60  AVIEW   61  DSE 12   62  DSE 13   63  GTO 02   64  LBL 14   65  FS? 07   66  GTO 09   67  RCL 27   68  REGSWAP   69  RCL 11   70  SRT   71  RCL 26   72  REGMOVE   73  XEQ 10   74  STO 12   75  2   76  +   77  4 E3   78  *   79  RCL 44   80  /   81  STO 14   82  X<>Y   83  STO 13   84  RCL 26   85  REGSWAP   86  RCL 27   87  REGSWAP   88  RCL 11   89  SRT   90  CLX   91  LBL 03   92  AVIEW   93  GETKEY   94  44   95  X=Y?   96  GTO 08   97  X<> Z   98  ST+ 42   99  X<>Y 100  41 101  X=Y? 102  GTO 09 103  LN 104  * 105  X^2 106  RCL 42 107  + 108  RCL 14 109  X<>Y 110  X>Y? 111  GTO 08 112  STO 42 113  X<>Y 114  .4 115  * 116  XY 140  DSE X 141  GTO 04 142  AVIEW 143  LBL 05 144  49 145  RCL 11 146  + 147  GETKEYX 148  X=0? 149  GTO 09 150  LASTX 151  - 152  CLRGX 153  GTO 05 154  LBL 09 155  " " 156  RCL 11 157  LBL 06 158  RCL IND X 159  X#0? 160  ARCL IND X 161  X<>Y 162  DSE X 163  GTO 06 164  AVIEW 165  RCL 11 166  LBL07 167  RCL IND X 168  X#0? 169  GTO 07 170  RDN 171  CARD 172  STO IND Y 173  LBL 07 174  X<>Y 175  DSE X 176  GTO 07 177  " " 178  RCL 11 179  SRT 180  FS? 07 181  GTO 01 182  RCL 27 183  REGSWAP   184  LBL 12 185  RCL 13 186  INT 187  X=0? 188  GTO 09 189  10 190  ST/ 13 191  MOD 192  CARD 193  STO IND Y 194  GTO 12 195  LBL 09 196  RCL 27 197  REGSWAP 198  LBL 01 199  RCL 11 200  XEQ 13 201  GTO 14 202  LBL 08 203  - 204  SIGN 205  CHS 206  GTO 09 207  LBL 11 208  FS? 07 209  GTO 01 210  RCL 27 211  REGSWAP 212  RCL 11 213  SRT 214  " /" 215  XEQ 13 216  LBL 01 217  XEQ 10 218  FC? 07 219  GTO 01 220  4 221  + 222  RCL 11 223  - 224  RCL 00 225  FRC 226  4 227  / 228  8 229  + 230  E^X 231  GTO 08 232  LBL 01 233  STO 10 234  RCL 27 235  REGSWAP   236  XEQ 10 237  RCL 10 238  - 239  X#0? 240  SIGN 241  LBL 09 242  RCL 42 243  LBL 08 244  * 245  ST+ 41 246  RCL 41 247  "  " 248  X>0? 249  "~+" 250  ARCL 41 251  "~ \$" 252  AVIEW 253  FIX 4 254  SF 29 255  RTN 256  GTO 01 257  LBL 13 258  RCL IND X 259  ARCL IND X 260  LN 261  AVIEW 262  X<>Y 263  DSE X 264  GTO 13 265  RTN 266  LBL 10 267  CF 08 268  CF 09 269  CF 10 270  RCL 02 271  RCL IND 11 272  - 273  STO 12 274  RCL 11 275  2 276  - 277  STO 13 278  X=Y? 279  SF 08 280  1 281  + 282  STO 14 283  RCL 01 284  RCL IND Y  285  - 286  RCL 13 287  X=Y? 288  SF 09 289  RCL 12 290  X#Y? 291  GTO 09 292  12 293  RCL 01 294  RCL IND 11 295  - 296  X=Y? 297  SF 10 298  RCL 14 299  X=Y? 300  SF 10 301  LBL 09 302  RCL 11 303  VAL 304  X<>Y 305  STO 14 306  X<>Y 307  FS?C 10 308  X#0? 309  GTO 08 310  CLST 311  RCL 11 312  ST+ X 313  3 314  - 315  RTN 316  LBL 08 317  X#0? 318  RTN 319  CLST 320  FS?C 09 321  RCL 11 322  FS?C 08 323  SIGN 324  X<>Y 325  RTN 326  END

( 515 bytes / SIZE 44+NNN )

 STACK INPUTS OUTPUTS X N /

Where N is the number of cards ( not exceeding 9 ) in one hand.

Example:           We assume that   R41 = 0  and that  CARD  has been replaced with  XEQ 16  ( lines 54-58-171-192 )

>>>  With  SF 07  1  STO 00   7  XEQ "POKN" will give the same game as paragraph  1°)c)

>>>  With  CF 07   let's try   2  STO 00    8  XEQ "POKN"         i-e  8-card hands

•  The HP-41 displays gradually                              K4A9TQ69    you have one pair
•  Your hand is displayed again                                K4A9TQ69    press, for example,  SIGMA+ ( about 1668\$ )
•  The calculator makes a higher bid and displays     +4520
•  If you match the HP-41's bet press  ENTER^
( press the backarrow-key if you fold - or another key if you want to make a higher bid )

•  You discards all the cards except 99, key in:         1 2 5 6 7 8   ENTER^  ( or TAN or ... )
•  The remaining cards are displayed                         99
•  Then the HP-41 gradually displays                        33699JAA     you have 3 pairs
•  Your hand is displayed again                                33699JAA      press, say 1/X   ( about 1986\$ )
•  The calculator makes a higher bid and displays     +5074
•  If you match the HP-41's bet press  ENTER^
( press the backarrow-key if you fold - or another key if you want to make a higher bid )

•  Your cards are displayed again                            33699JAA
•  If you exchange the 6 and the J , press                 3  6  ENTER^
•  The remaining cards are displayed                        3399AA
•  Then the HP-41 gradually displays                        3399JAAA     you have a "3-of-a-kind" and 2 pairs
•  Your hand is displayed again                                3399JAAA      press, say the SQRT key ( about 2331\$ )
•  Your HP-41 makes a higher bid and displays     +10355
•  Press  ENTER^ if you accept the bet
( press the backarrow-key if you fold - or another key if you want to make a higher bid )

•  The HP-41 gradually displays its own cards:          / 4777JAAA     it has 2 "three of a kind"  ( so the HP-41 wins )
•  Your cash is displayed                                          -27934 \$

-So, you've lost 27934 \$.
-Press  R/S  to continue the game...

Notes:

-The game is very slow without M-Code routines, but the program is enough fast otherwise.
-If you have kept the CARD instructions, the cards are different.

-The HP-41 accept a total amount of raises that is stored in R14 ( this register is also used for temporary data storage )
-This value is calculated lines 73 to 81
-Register R44 contains a random number that allows the calculator to bluff ! ( lines 79-80 )

-In this game, a pair of aces is equivalent to any other pair: the height of the cards are not taken into account.
-Of course, it would be better otherwise, but also much longer and slower...