hp41programs

poker

Poker for the HP-41


Overview
 

 1°)  Playing against your HP-41
 2°)  Playing with your HP-41
 3°)  Texas Hold'em Poker
 4°)  Synthesis of the 3 programs ( HP-41CX )

   a)  3 M-Code Routines:   TRI   MV   CARD
   b)  "POKER+"
   c)  1 M-Code Routine:  $
   d)  "POKER"
 

-To simplify the programs, we use a deck of an infinite number of one-suit cards.
-In other words, the probability of each card is 1/13,
  and therefore, the order of the combinations is modified like this:
 
 

     combinations       probability  ranking
       high card           41%      0
         1 pair           46%      1
         2 pairs            7%      2
     3 of a kind           4.6%      3
       full house           0.4%      4
         straight*           0.3%      5
      4 of a kind           0.2%      6
      5 of a kind         0.004%      7

 
*Here, a straight is always a straight-flush!
  The lowest one is 2345A and the highest one is TJQKA
 

1°) Playing against your HP-41
 

-The HP-41 is always the dealer.

 0- A bet of 1000$ is placed automatically ( line 38 )
 1- The calculator deals 5 cards one by one to the player and to itself,
      the player's cards are gradually shown and the HP-41's cards are displayed as starbursts,
      then the cards are sorted out in increasing order, displayed again, and the program stops.
 2- At this step, key in a stake ( of about 1000$ or 2000$ for instance ) and press  R/S
    ( if the player simply presses R/S the HP-41 wins )
 3- Then, the HP-41 can:

            a)  fold ( the player wins and the new bank of the player is displayed )
            b)  match the player's bet.
            c)  make a higher bid ( which is displayed as "  + .... $" )

         In this case, the player can, in his turn:

                          a) fold  (  press     0   R/S  )
                          b) match the HP-41's bet   (  press  ENTER  R/S )
                          c) make a higher bid  ( key in a number greater than the HP-41's bid and R/S )  ... etc ...

 4- At the end of the stakes, the player's cards are displayed again and the program stops.

          -To exchange the cards number 1, 2, 5 ( if your hand is 45QQA for example )  press  125   R/S
          -If you have a complete hand, simply press  R/S

 5-The HP-41 displays the remaining cards of the player and as many starbursts as its own remaining cards.
 6-About 12 seconds later, the new hand of the player is displayed ( followed by / and 5 starbursts ) and the program stops.
 7-The second round of betting takes place here just like in steps 2 and 3
   ( To fold immediately, simply press R/S ).
 8-If the final bet or raise is not called, the new bank of the player is displayed, but the calculator's cards remain unknown.
    Otherwise, the HP-41 displayed its own cards one by one and then it displays the new bank of the player.
 9-Press R/S to continue the game.
 

Remarks:

  1-If the player exchanges 3; 2; 1; 0 cards, the HP-41 will fold unless it has ( at least )
     one pair; three of a kind; two pairs; a full house ( respectively ).     ( lines 183 to 191 )
  2-This strategy is very simple, so don't play too aggressively against your HP-41 ...
      ( but remember that the HP-41 can bluff in the second round of betting ( lines 177 to 182 ) ).
  3-Don't disturb rashly the stack during the raises.
  4-Digit entry lines are very slow. Therefore, execution time can be saved by storing these numbers in data registers:
       for instance replace line 211 by RCL 41 and key in 1.015008 STO 41 just after line 27 ... etc ...

Data Registers:

  R00 thru R40 are used.  R00 and R12 must be initialized before executing "POKER"

    R00 = random numbers
    R12 = the bank of the player ( the cash )

  R01 thru R05 are the HP-41's cards  R06 thru R11 are used for temporary data storage
  R15 thru R19 are the player's cards   R20 thru R22 ------------------------------------
  R10 is also used for the HP-41's raises.
  R08 and R22 are also used to store the values of both hands.
  R21 is also used to store the player's hand.
  R23 = /¤¤¤¤¤
  R24 = /¤¤¤¤
  R25 = /¤¤¤       ( ¤ symbolizes the starburst, the hidden cards of the HP-41 )
  R26 = /¤¤
  R27 = /¤
  R28 = the "2s"
  R29 = the "3s"
  ....................
  R39 = the "Ks"
  R40 = the "As"

Flags:   F06

Subroutines:  none.
 

Analysis of the program:

-Lines 02 to 27 initialize the registers containing the cards ( 2 , 3 , ... , 9 , T , J , Q , K , A )
      and the hidden cards of the calculator ( displayed as starbursts )
      They are executed only once.
-Lines 28 to 59 place the initial bet ( 1000$  line 38 ) and deal the cards one by one
-Line 60 ( XEQ 09 ) sorts the cards, calculates the value of the HP-41's hand and stores in R10
      the maximum amount of money that the HP-41 will accept.
-Lines 61 to 68 modify this sum when the calculator has 4 cards in sequence ( like 6789K ) which can lead to a straight.
      In such a case, the HP-41 will raise the bets just as if it had two pairs.
-Lines 70 to 94 concern the bettings:
       if the player keys in 0 R/S ( or simply R/S at the first time ) the HP-41 wins the pot.
       if the player keys in  ENTER^  R/S  the raises are called.
       if the player keys in  a bet and R/S there are 3 possibilities:
               If the total amount of the raises is higher than the number in R10 the player wins the pot.
               If the total amount of the raises is smaller than R10 but greater than 0.4*R10, the HP-41 is in.
               If the total amount of the raises is smaller than 0.4*R10, the HP-41 makes a higher raise ... etc ...
                   ( This raise is choosen randomly but the total amount of the previous bets is also taken into account )
-Lines 104 to 112 are the showdown: the calculator displays its cards one by one.
-Lines 113 to 137 display the player's bank.
-Line  138 returns to line 28
-Lines 139 to 175 display the remaining cards of the player ( and as many starbursts as the remaining cards of the HP-41 ) after discarding.
-Line  176 executes the LBL 09 ( see below )
-Lines 177 to 182 are the calculator's bluff ( only in the second round of betting ):
       The number in R10 is divided by a random real number r ( 0 < r < 1 ).
-Lines 183 to 191 are the HP-41's strategy ( as explained in the 1st remark above )
-Lines 192 to 193 return to line 70 ( the betting )
-Lines 194 to 209 calculate and store in R10 the maximum amount of money that the HP-41 will accept.
      This number suits to bets of  a few thousand ( or ten thousand ) dollars.
-Lines 210 to 222 replace the discarded cards by new ones.
-Lines 223 to 263 sort out the cards in increasing order ( in R01 to R05 )
-Lines 269 to 288 calculate the value of the hand in R08
      The result is also used to obtain the number in R10 which is proportional to the square of R08.
      The number 37 ( line 271 ) can be changed but must not be too small ( not smaller than 16 ).
      Otherwise, the order of the different hands could become wrong.
-Lines 289 to 300 deal the cards. The random number generator used by this LBL 08
      is quite simple:   R-D  FRC
      It's perhaps not a perfect one but it's good enough for a game.
-Lines 301 to 454 concern the evaluation of the hand, the cards to be exchaned ...etc...
      The details are somewhat complex, but it works well!

  For instance, if the HP-41's hand is  3377K we have: R01 = R02 = 29 (the "3s") ; R03 = R04 = 33 (the"7s") ; R05 = 39 (the "K").
     R06 = 5 because the HP-41 will exchange its 5th card ( the King ) after the first round of betting.
     R07 = 2 = the ranking of the hand: two pairs.
     R08 = 33 ; R09 = 29 ; R10 = 39 ; R11 = 29
  Then, the value of the hand is obtained by   375*R07+374*R08+373*R09+372*R10+37*R11+R01 = 202058657 and stored in R08 ( line 287 ).
   ( In this example, R11 and R01 could be replaced by zero in the above formula, but it's not necessary ).
  This number characterizes the hand and allows to compare the HP-41's hand with the player's hand.
   (R08/E6)2 = 40827.7 $ is then stored in register R10 ( line 210 ).
 

Program Listing:
 

- In this listing, the "append" character is replaced by "~"
- The functions XTOA  ATOX  REGSWAP of the X-Functions module are used.
- CLRGX is also used, but if you don't have an HP-41 CX, replace lines 154 to 157 by

     X<=0?
     GTO 07
     0
     STO IND Y
     RDN
     GTO 03
     LBL 07

-Lines 138-193 are three-byte  GTOs
 
 

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

 
      ( 629 bytes / SIZE 041 )
 
 

      STACK        INPUTS      OUTPUTS
           X             /             /

 
An example of game:
 

N.B: The first execution of the program is very slow because the XEQs and GTOs are not yet compiled.

0-Registers R00 and R12 are to be initialized, for instance:

            9 STO 00  ( avoid a seed like PI which would be converted into an integer by the R-D function )
    40000 STO 12
 

                                                                                         THE DISPLAY         COMMENTS

1- XEQ "POKER"
                                                                                         T/¤                           ( ¤ symbolizes the starburst )
                                                                                         T6/¤¤
                                                                                         T64/¤¤¤
                                                                                         T64T/¤¤¤¤
                                                                                         T64T4/¤¤¤¤¤
             the player has two pairs                                        446TT/¤¤¤¤¤           the cards are sorted.

2-The 1st round of betting:                2000  R/S                    +1460                    the HP-41 makes a higher bid
              a new raise                         4000  R/S                    +2557                    idem
                 we are in                  ENTER^   R/S                  446TT/¤¤¤¤¤

3-We exchange the "6" ( the 3rd card )    3 R/S                  44TT/¤¤¤¤               the HP-41 has 2 pairs or a sequence of 4 cards.
    and ( 10 seconds later )                                                  44TTK/¤¤¤¤¤

4-The second round of betting:         3000  R/S                    +22441                   a raise
      to match the HP-41's raise:  ENTER^  R/S                   44TTK/2
                                                                                          44TTK/22
                                                                                          44TTK/22K
                                                                                          44TTK/22KA
                                                                                          44TTK/22KAA        The HP-41 wins!

                and the cash is displayed:                                      C = +5002 $

----------------------------------------------------------------------------------------------------------------------------------

1'-Let's continue,   R/S
                                                                                           J/¤
                                                                                           J3/¤¤
                                                                                           J33/¤¤¤
                                                                                           J339/¤¤¤¤
                                                                                           J3395/¤¤¤¤¤
            the player has one pair                                             3359J/¤¤¤¤¤

2'-1st round of betting                2000    R/S                        3359J/¤¤¤¤¤             the HP-41 is in

3'-We exchange the last 3 cards:   345   R/S                        33/¤                           the HP-41 has only a high card.
     and, (13 seconds later ),   three of a kind:                        3335K/¤¤¤¤¤

4'-2nd round of betting                 3000  R/S                         +4783                      a raise
                                                    6000  R/S                       3335K/5                    the HP-41 matches the bet
                                                                                           3335K/57
                                                                                           3335K/579
                                                                                           3335K/579K
                                                                                           3335K/579KK         the player wins the pot.

                    and the cash is                                                  C = +17002 $

----------------------------------------------------------------------------------------------------------------------------------

1"-One more time:          R/S
                                                                                            K/¤
                                                                                            K6/¤¤
                                                                                            K65/¤¤¤
                                                                                            K656/¤¤¤¤
                                                                                            K6567/¤¤¤¤¤
            one pair:                                                                   5667K/¤¤¤¤¤

2"-1st round of betting                  2000  R/S                        5667K/¤¤¤¤¤           the HP-41 is in

3"-We exchange the 1st, 4th and 5th cards:
                                                     145   R/S                        66/¤                          theHP-41 has a high card
              ( 13 seconds later )                                                 668TA/¤¤¤¤¤

4"-2nd round of betting                2000   R/S                         +12131                    the HP-41 makes a higher bid!

             a) if we fold:                      0       R/S    the cash:       C = +12003 $
             b) if we want to see    ENTER^  R/S                       668TA/3
                                                                                            668TA/3J
                                                                                            668TA/3JJ
                                                                                            668TA/3JJJ
                                                                                            668TA/3JJJA            three of a kind ( it was not a bluff! )

                     and the cash:                                                      C = -128 $             the player is in debt ...
 

2°) Playing with your HP-41
 

-The program may be simplified if your HP-41 becomes a one-arm bandit:

-Your calculator deals 5 cards,
  then you discard from 0 to 5 cards
  the HP-41 replaces these cards and
  -If you have 5 of a kind , you win 21 times your bet  ( line 256 )
  -If you have 4 of a kind , you win 13 times your bet  ( line 263 )
  -If you have a straight    , you win  8  times your bet  ( line 175 )
  -If you have a full-house , you win 5  times your bet  ( line 158 )
  -If you have 3 of a kind  , you win 3  times your bet  ( line 244 )
  -If you have two pairs    , you win 2  times your bet  ( line 252 )

  -If you have 1 pair of Jacks ( or higher )  you win 1 time your bet         ( lines 198 & 228
  -If you have 1 pair of 7s to 1 pair of 10s  your cash is unchanged                  and
  -If you have 1 pair of 2s to 1 pair of 6s   you lose 1 time your bet         lines 68 thru 79 )

  -If you have a high card you lose 5 times your bet  ( line 192 )

-All these values are quite arbitrary and may be modified as you like.
 

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

                                      •  R06 = your cash

                                         R01 to R05 = your 5 cards   ;   R07 thru R21: temp
Flags: /
Subroutines: /
 

-2 CX-functions are used ( GETKEYX and CLRGX ) but if you don't have an HP-41CX, replace lines 36 thru 45 by

     STOP           10                    -                        /
     LBL 03         MOD              0                        GTO 03                    Press  123  R/S  if, for instance, you want to discard the cards n°1-2-3 ( from the left )
     ENTER^       ST- Y             STO IND Y       LBL 10                     Simply press R/S if you have already a complete hand
     X=0?            6                     X<> Z                CF 22
     GTO 10        X<>Y             10

-Line 101 is a three-byte  GTO 12
 
 

 01  LBL "POKER1"
  02  "A"
  03  ASTO 21 
  04  "K"
  05  ASTO 20 
  06  "Q"
  07  ASTO 19
  08  "J"
  09  ASTO 18
  10  16
  11  "T"
  12  ASTO 17
  13  9
  14  LBL 01
  15  STO IND Y    
  16  DSE Y
  17  DSE X
  18  GTO 01
  19  LBL 12 
  20  FIX 0
  21  CF 29
  22  " " 
  23  ASTO 08
  24  5
  25  LBL 02
  26  CLA
  27  ARCL 08
  28  ENTER^
  29  XEQ 14
  30  ARCL IND X
  31  ASTO 08
  32  X<>Y
  33  AVIEW
  34  DSE X
  35  GTO 02
  36  LBL 03
  37  54
  38  GETKEYX
  39  X=0?
  40  GTO 10
  41  LASTX
  42  -
  43  CLRGX
  44  GTO 03 
  45  LBL 10
  46  " " 
  47  5
  48  LBL 13 
  49  RCL IND X
  50  X#0?
  51  ARCL IND X
  52  X<>Y
  53  DSE X
  54  GTO 13
  55  AVIEW
  56  5
  57  XEQ 05
  58  " " 
  59  5
  60  LBL 04
  61  RCL IND X
  62  ARCL IND X 
  63  COS
  64  AVIEW
  65  X<>Y
  66  DSE X
  67  GTO 04
  68  RCL 07 
  69  X#0?
  70  GTO 09
  71  17
  72  RCL 08
  73  X>Y?
  74  ISG 07
  75  INT
  76  14
  77  X>Y?
  78  DSE 07
  79  LBL09
  80  RCL 00
  81  FRC
  82  4
  83  /
  84  8
  85  +
  86  E^X
  87  RCL 07
  88  *
  89  ST+ 06
  90  RCL 06
  91  "  " 
  92  X>0?
  93  "~+" 
  94  ARCL 06 
  95  "~ $" 
  96  FIX 4
  97  SF 29
  98  AVIEW
  99  CLA
100  STOP
101  GTO 12 
102  LBL 14
103  CLX
104  RCL 00
105  R-D
106  13
107  MOD
108  STO 00 
109  9
110  +
111  INT
112  STO IND Y 
113  RTN
114  LBL 05
115  RCL IND X  
116  X=0?
117  XEQ 14
118  X<>Y
119  DSE X
120  GTO 05
121  RCL 01
122  RCL 02
123  X>Y?
124  X<>Y
125  RCL 03
126  X>Y?
127  X<>Y
128  RCL 04
129  X<Y?
130  X<>Y
131  X<> 05
132  X>Y?
133  X<>Y
134  X<> 05
135  X>Y?
136  X<>Y
137  R^
138  X>Y?
139  X<>Y
140  RDN 
141  X>Y?
142  X<>Y
143  RDN
144  X<Y?
145  X<>Y
146  STO 01
147  STO 08          
148  RDN
149  X>Y?
150  X<>Y
151  STO 04 
152  RDN
153  X>Y?
154  X<>Y
155  STO 03
156  X<>Y
157  STO 02
158  5
159  STO 07
160  RCL 05 
161  RCL 04
162  X=Y?
163  GTO 08
164  RCL 03
165  X=Y?
166  GTO 06
167  RCL 02
168  X=Y?
169  GTO 07
170  RCL 01
171  X=Y?
172  GTO 11
173  RCL 05
174  -
175  8
176  STO 07
177  CLX
178  5
179  X>Y?
180  RTN
181  RCL 02 
182  LASTX
183  -
184  PI
185  X<Y?
186  GTO 10
187  R^
188  12
189  X=Y?
190  RTN
191  LBL 10           
192  5
193  CHS
194  STO 07
195  RTN
196  LBL 11
197  STO 08 
198  CLX
199  STO 07
200  RTN
201  LBL 06
202  RCL 02
203  X=Y?
204  GTO 10
205  RCL 01 
206  X=Y?
207  GTO 11
208  GTO 09
209  LBL 07
210  RCL 01
211  X=Y?
212  GTO 07
213  GTO 09
214  LBL 08
215  RCL 03
216  X=Y?
217  GTO 06
218  RCL 02
219  X=Y?
220  GTO 08
221  RCL 01
222  X=Y?
223  GTO 11
224  RDN
225  LBL 09
226  X<> Z
227  STO 08 
228  CLX
229  STO 07
230  RTN
231  LBL 10
232  RCL 01
233  X=Y?
234  GTO 09          
235  GTO 07
236  LBL 06
237  RCL 02
238  X=Y?
239  GTO 10
240  RCL 01 
241  X=Y?
242  RTN
243  LBL 07
244  3
245  STO 07
246  RTN
247  LBL 08
248  RCL 01 
249  X=Y?
250  RTN
251  LBL 11
252  2
253  STO 07
254  RTN
255  LBL 10
256  21
257  STO 07
258  CLX
259  RCL 01
260  X=Y?
261  RTN
262  LBL 09
263  13
264  STO 07
265  END

 
    ( 366 bytes / SIZE 022 )
 
 

      STACK        INPUTS      OUTPUTS
           X             /             /

 
Example:     3  STO 00   CLX   STO 06
 

 XEQ "POKER1"        the HP-41 displays successively:

                                                                     " 4"
                                                                     " 4J"
                                                                     " 4J9"
                                                                     " 4J9J"
                                                                     " 4J9J4"            you have 2 pairs
-If you want to discard the "9"
 ( the 3rd card ) press   3  ENTER^               " 4JJ4"              the remaining cards

-The HP-41 replaces this card, sorts the 5 cards and displays

                                                                    " 4"
                                                                    " 44"
                                                                    " 445"
                                                                    " 445J"
                                                                    " 445JJ"             still 2 pairs

                  followed by                                "  +6509 $"        you have  6509$
----------------------------------------------------------------------------------------------
-                     R/S                                        " Q"
                                                                    " Q4"
                                                                    " Q4T"
                                                                    " Q4TA"
                                                                    " Q4TA5"           only a high card

-You press   1 2 3 5   ENTER^
  in order to keep the ace                             " A"

-A few seconds later:                                   " 2"
                                                                   " 23"
                                                                   " 23K"
                                                                   " 23KA"
                                                                   " 23KAA"           one pair

                  followed by                               "  +10108 $"
-----------------------------------------------------------------------------------------------
-                     R/S                                        " Q"
                                                                    " QQ"
                                                                    " QQ4"
                                                                    " QQ4K"
                                                                    " QQ4K7"           one pair

-Press   3  4  5   ENTER^
 to discard the last 3 cards                            " QQ"

-Then                                                           " 2"
                                                                    " 26"
                                                                    " 268"
                                                                    " 268Q"
                                                                    " 268QQ"            the same pair

                  followed by                                "  +13859 $"
-----------------------------------------------------------------------------------------------
-                     R/S                                        " T"
                                                                    " T2"
                                                                    " T26"
                                                                    " T26Q"
                                                                    " T26Q3"           only a high card

-If you want to keep the Queen
  press  1  2  3  5   ENTER^                         " Q"

-And                                                            " 6"
                                                                    " 66"
                                                                    " 667"
                                                                    " 667Q"
                                                                    " 667QA"           one small pair  ( not enough to win )

                  followed by                                "  +10747 $"       and so forth ...
 

Notes:

-Simply press ENTER^ if you do not want to discard any card ( if you have a complete hand! )
-You can press other keys ( instead of ENTER^ )
  provided it's neither a numeric key nor CHS nor the decimal point.

-In this program, the bets are randomly computed ( approximately between 3000$ and 3800$ - lines 80 to 86 )
  but if you want to place your own bets:

    -Replace lines 80 to 86 by  RCL 22
    -Replace line 19 ( LBL 12 ) by  X<> Z  LBL 12  FS?C 22  STO 22

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

-The cards are sorted out only after discarding,
-Otherwise, it would needlessly increase execution time.
 

3°)  Texas Hold'em Poker
 

-In order to simplify the program, there is no blind and no round of bettings before the "flop" ( the first 3 community cards ) is displayed.
-And you are always the first player to bet.
 

Data Registers:           •  R00 = n                   ( Registers R00 & R41 are to be initialized before executing "TXEM" )

                                      •  R41 = your Cash      R01 thru R40 & R42 thru R50: temp
Flags: /
Subroutines: /
 

-Lines 104-111-167-212-237-274 are three-byte GTOs
-The append character is denoted  ~
 
 

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

   where x is what you win if x > 0 or what you lose if x < 0 or x = 0 if there is a tie.

Example:   Initialize the random seed, say  1  STO 00  and your cash  40000 $  STO 41

   1000 $  are automatically placed in the pot ( lines 47-48 )

  •   XEQ "TXEM"   the HP-41 successively displays:

        " 5/¤"
        " 55/¤¤"
        " FLOP. . ."
        " 55/A37/¤¤"          and stops: the 1st round of betting may start. Suppose your bet is 2000 $

  •   2000   R/S   the HP-41 makes a higher bid and displays   +2819   If you are in, simply press   ENTER^  R/S

   ( Press 0 R/S to fold, or place another bet in X and R/S if you want to raise )

        " TURN. . ."          and 26 seconds later (!!)
        " 55/A37K/¤¤"      If you bet 2000 $ again:

  •  2000   R/S   the HP-41 displays   +6075      if you match the HP-41's bet,  press  ENTER  R/S

        " RIVER. . ."          and  37 seconds later (!!!)
        " 55/A37K8/¤¤"     Let's bet  1000 $

  •  1000   R/S   the HP-41 doesn't make a higher bid and displays

         55/A37K8/9A     the calculators computes the maximum value of your possible hands and finally displays your cash

    C = 25106 $        ( after 37 seconds )

    X-register = -14894.4076  ( you've lost 14894 $ )  You had  558KA , HP41 had  89KAA

  •  Simply press R/S to continue the game.

Notes:

-The last possible hands of the player are not evaluated if he - or the HP41 - has folded.
-In this case, the HP-41 cards are not displayed.
-This program is obviously very slow on a true HP-41, unless you use the M-Code routine "TRI" listed hereafter.
-But with a good emulator, the delays become acceptable - even without a turbo mode.
-The HP-41 never bluffs with "TXEM"
-If you want to add this option,

    add for instance    RCL 51   *   after line 153
    add    RCL 00    R-D   FRC   STO 00   .12   X>Y?   ST/ 51   after line 99
    and add    1   STO 51    after line 38
 

4°)  Synthesis of the 3 Programs
 

      a)  3 M-Code Routines:  TRI   MV   CARD
 

Warning:   These routines check that the required registers exist but they do not check for alpha data.

-Among these 3 routines, "TRI" is the most important to reduce execution time when playing Texas Hold'em Poker.

-The first one sorts the 5 cards in R01 thru R05, evaluate the poker hand - the value is returned in X -
  compares this result with the number already in R48 and stores the maximum of these 2 numbers into R48.
 

089   "I"
012   "R"
014   "T"
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X           The lines written in red
1D0  1D0h                   check that R48 exist.
306   ?A<C S&X        You might delete them
381   ?NCGO              to save a fraction of a second ... but it's risky if you XEQ "TRI" accidentally.
00A   02E0                  However, the existence of R48 is already checked line 37 of "POKER+"
130   LDI S&X
005   005
146   A=A+C S&X
266   C=C-1 S&X
0E6   B<>C S&X
0A6  A<>C S&X
270   RAMSLCT
0A6  A<>C S&X
038   READDATA
0E6   B<>C S&X
270   RAMSLCT
0E6   B<>C S&X
2F0   WRITDATA
1A6   A=A-1 S&X
0E6   B<>C S&X
266   C=C-1  S&X
01F   JC+03
0E6   B<>C S&X
39B  JNC -13d
130   LDI S&X
005   005
070   N=C ALL
0EE   B<>C ALL
00E   A=0 ALL
0CE  C=B ALL
266   C=C-1 S&X
057   JC+10d
270   RAMSLCT
0EE   B<>C ALL
038   READDATA
31A  ?A<C ALL
3CB  JNC-07
0AE  A<>C ALL
0CE  C=B ALL
158   M=C ALL
3AB  JNC-11d
0B0   C=N ALL
266   C=C-1 S&X
070   N=C ALL
270   RAMSLCT
038   READDATA
0AE  A<>C ALL
2F0   WRITDATA
198   C=M ALL
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
0B0   C=N ALL
2E6   ?C#0 S&X
32F   JC-27d
04E   C=0 ALL
270   RAMSLCT
168   WRIT 5(M)
35C   PT=12
110   LD@PT-4
1A8  WRIT 6(N)
0B8   READ 2(Y)
268   WRIT 9(Q)
0F8   READ 3(X)
228   WRIT 8(P)
138   READ 4(L)
1E8   WRIT 7(O)
046   C=0 S&X
270   RAMSLCT
038   READDATA
158   M=C ALL
10E   A=C ALL
078   READ 1(Z)
070   N=C ALL
36E   ?A#C ALL
18B   JNC+49d
10E   A=C ALL
0B8   READ 2(Y)
36E   ?A#C ALL
15B   JNC+43d
10E   A=C ALL
0F8   READ 3(X)
36E   ?A#C ALL
143   JNC+40d
10E   A=C ALL
138   READ 4(L)
36E   ?A#C ALL
1F3   JNC+62d
2A0   SETDEC
10E   A=C ALL
198   C=M ALL
1CE  A=A-C ALL
08E   B=A ALL
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
1A8   WRIT 6(N)
3CE   RSHFC
30E   ?A<C ALL
187    JC+48d
0F8   READ 3(X)
10E   A=C ALL
198   C=M ALL
1CE  A=A-C ALL
04E   C=0 ALL
19C   PT= 11
0D0   LD@PT-3
158   M=C ALL
36E   ?A#C ALL
087   JC+16d
06E   A<>B ALL
3EE   LSHFA
04E   C=0 ALL
35C   PT= 12
1D0    LD@PT-7
1CE   A=A-C ALL
1B8   READ 6(N)
36E   ?A#C ALL
0D7   JC+26d
078   READ 1(Z)
1E8   WRIT 7(O)
0D3  JNC+26d
11B  JNC+35d
1D3  JNC+58d
0C3  JNC+24d
138   READ 4(L)
10E   A=C ALL
078   READ 1(Z)
1CE  A=A-C ALL
198   C=M ALL
36E   ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
04B   JNC+09
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
0D0   LD@PT-3
110   LD@PT-4
130   LDI S&X
003   003
168   M=C ALL
04E   C=0 ALL
1A8  WRIT 6(N)
163   JNC+44d
1AB  JNC+53d
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
0D0   LD@PT-3
130   LDI S&X
002   002
0C3  JNC+24d
10E   A=C ALL
0F8  READ 3(X)
36E   ?A#C ALL
1CB  JNC+57d
10E   A=C ALL
138   READ 4(L)
36E   ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
183   JNC+48d
228   WRIT 8(P)
078   READ 1(Z)
0AE  A<>C ALL
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
110    LD@PT-4
150    LD@PT-5
130    LDI S&X
002    002
1A3   JNC+52d
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
047   JC+08
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
226    C=C+1 S&X
193    JNC+50d
183    JNC+48d
228    WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
150    LD@PT-5
130    LDI S&X
002    002
103    JNC+32d
10E   A=C ALL
0B8   READ 2(Y)
36E   ?A#C ALL
1BB  JNC+55d
10E   A=C ALL
0F8   READ 3(X)
36E  ?A#C ALL
193   JNC+50d
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
037   JC+06
04E   C=0 ALL
35C   PT= 12
0D0   LD@PT-3
14B   JNC+41d
0C3   JNC+24d
228   WRIT 8(P)
0AE   A<>C ALL
268   WRIT 9(Q)
0B8   READ 2(Y)
070   N=C ALL
078   READ 1(Z)
10E   A=C ALL
04E   C=0 ALL
35C   PT= 12
0D0   LD@PT-3
110    LD@PT-4
150    LD@PT-5
130    LDI S&X
002    002
168    M=C ALL
0AE   A<>C ALL
1E8    WRIT 7(O)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
1A8   WRIT 6(N)
153    JNC+42d
123    JNC+36d
1E8   WRIT 7(O)
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
193    JNC+50d
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
150    LD@PT-5
226   C=C+1 S&X
0A3   JNC+20d
113    JNC+34d
0C3   JNC+24d
1E8   WRIT 7(O)
10E   A=C ALL
0F8   READ 3(X)
36E   ?A#C ALL
12B   JNC+37d
10E   A=C ALL
138   READ 4(L)
228   WRIT 8(P)
36E  ?A#C ALL
183   JNC+48d
0AE  A<>C ALL
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
110    LD@PT-4
150    LD@PT-5
226    C=C+1 S&X
168    WRIT 5(M)
04E   C=0 ALL
35C   PT= 12
0D0    LD@PT-3
1A8   WRIT 6(N)
11B   JNC+35d
1E8   WRIT 7(O)
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
0F3   JNC+30d
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
168   WRIT 5(M)
078   READ 1(Z)
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
090    LD@PT-2
1A8   WRIT 6(N)
093   JNC+18d
063   JNC+12d
04E   C=0 ALL
35C   PT= 12
1D0    LD@PT-7
1A8   WRIT 6(N)
138    READ 4(L)
36E  ?A#C ALL
053   JNC+10d
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
168   WRIT 5(M)
04E   C=0 ALL
35C   PT= 12
190    LD@PT-6
1A8   WRIT 6(N)
260    SETHEX
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X
00B  011d
206   C=A+C S&X
270   RAMSLCT
10E   A=C ALL
0B0   C=N ALL
2F0   WRITDATA
130   LDI S&X
009   009
158   M=C ALL
270   RAMSLCT
038   READDATA
0AE  A<>C ALL
266   C=C-1 S&X
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
198   C=M ALL
266   C=C-1 S&X
3B3   JNC-10d
04E   C=0 ALL
270   RAMSLCT
35C  PT=12
0D0  LD@PT-3                     37 is used to evaluate the poker hands.
1D0  LD@PT-7                     Replace these 2 lines if you prefer another number, but choose at least 16.
226   C=C+1 S&X
2A0  SETDEC
128   WRIT 4(L)
10E   A=C ALL
1B8   READ 6(N)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
1F8   READ 7(O)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
238   READ 8(P)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
278   READ 9(Q)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
0B0   C=N ALL
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
046   C=0 S&X                 C
270   RAMSLCT               =
038   READDATA            T
01D  ?NCXQ                    C=
060   1807                       A+C
0E8   WRIT 3(X)                                 Here, the combination is evaluated.
070   N=C ALL                                   Then, its value is compared to R48 and the maximum is stored in R48
260   SETHEX
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X
030   048d
206   C=A+C S&X
270   RAMSLCT
0E6   B<>C S&X
038   READDATA
10E   A=C ALL
0B0   C=N ALL
306   ?A<C S&X
037   JC+06
0AE  A<>C ALL
306   ?A<C S&X
360   ?C RTN
31A   ?A<C M
360   ?C RTN
0E6   B<>C S&X
270   RAMSLCT
0B0  C=N ALL
2F0   WRITDATA
3E0   RTN
 
 

    Poker Hand      X-OUTPUT
       23457       63459727
       9JQKA       76995333
       22345      123432879
       JQKAA      146391351
       22334      194499001
       QKKAA      215684693
       22234      262068734
       QKAAA      285080672
       22233      331360669
       KKAAA      354424630
       2345A      402682868
       23456      408305351
       TJQKA      423715119
       22223      470048583
       KAAAA      493112581
       22222      539341887
       AAAAA      562456539

 
-The second M-Code routine "MV" is equivalent to  17.001005   REGMOVE
-Checking for alpha data would be unuseful.
 

096   "V"
00D  "M"
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X           The lines written in red
1EB  1EBh                   check that R21 exist.
306   ?A<C S&X        You might delete them
381   ?NCGO              to save a fraction of a second ... but it's risky if you XEQ "MV" accidentally.
00A   02E0                  However, the existence of R42 is checked line 03 of "POKER+". So R21 does exist too !
130   LDI S&X
010   016d
206   C=A+C S&X
0E6   B<>C S&X
130   LDI S&X
004   004
070   N=C ALL
0E6   B<>C S&X
226   C=C+1 S&X
270   RAMSLCT
0E6   B<>C S&X
038   READDATA
0AE  A<>C ALL
226   C=C+1 S&X
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
0B0   C=N ALL
266   C=C-1 S&X
39B   JNC-13d
3E0   RTN
 

-And the 3rd routine "CARD" takes a random number in R00 to calculate another random number which is stored in R00
  and returns a "card",  i-e an integer between 28 & 40 in register X
 

084   "D"
012   "R"
001   "A"
003   "C"
0F8   READ 3(X)
0A8  WRIT 2(Y)
378   READ 13(c)
03C  RCR 3
106   A=C S&X          The lines written in red
130   LDI S&X            check that R00 exist.
1EB  1EBh
306   ?A<C S&X        You might delete them
381   ?NCGO              to save a fraction of a second ... but it's risky if you XEQ "CARD" accidentally.
00A   02E0                  On the other hand, the existence of R42 is checked line 03 of "POKER+".
0A6  A<>C S&X        So R00 does exist too !
270   RAMSLCT
038   READDATA
2A0  SETDEC
231   ?NCXQ           xeq
064   198C               R-D
084   CLRF 5
0ED  ?NCXQ           FRC
064   193B
2F0   WRITDATA
10E   A=C ALL
04E   C=0 ALL
270   RAMSLCT
35C  PT=12
050   LD@PT-1
0D0  LD@PT-3
226   C=C+1 S&X
135   ?NCXQ             C=
060   184D                A*C
088   SETF 5
0ED  ?NCXQ           INT
064   193B
10E   A=C ALL
04E   C=0 ALL
35C  PT=12
090   LD@PT-2
210   LD@PT-8
226   C=C+1 S&X
01D  ?NCXQ              C=
060   1807                  A+C
0E8   WRIT 3(X)
3E0   RTN
 
 

      STACK        INPUTS      OUTPUTS
           Y             /             x
           X             x             N

 
  with  28 <= N <= 40   provided  R00 contains a random seed
 

      b)  "POKER+"
 

-This program combines "POKER" , "POKER1" and "TXEM" and uses the 3 M-Code routines above.
 

Data Registers:           •  R00 = n                 ( Registers R00 & R41 are to be initialized before executing "POKER+" )

                                      •  R41 = your Cash      R01 thru R40 & R42 thru R48: temp
Flags:  F07-F08-F10

  CF 07 & CF 08 = Standard Draw Poker
  SF 07 & CF 08 = One-arm Bandit
  SF 08 = Texas Hold'em Poker

Subroutines:  TRI  MV  CARD

-Lines 72-129-144-163-204-263-323 are three-byte GTOs
-The append character is denoted  ~
 
 

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

 
    ( 872 bytes / SIZE 049 )
 
 

      STACK        INPUTS      OUTPUTS
           X             /             /

 
Instructions:

-The instructions are almost identical except that the program does not stop before your next cash is displayed.
-After displaying your cards, GETKEY is used to place your bet ( draw poker or texas hold'em ):

   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.

-Likewise - with CF 08 - when 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.

-With CF 07  CF 08  ( one-arm bandit ), your bet is randomly evaluated.

Notes:

-The HP-41 does not bluff when playing "Texas Hold'em Poker" i-e  SF 08
-If you want this option,

    add for instance    RCL 49   *   after line 190
    add    RCL 00    R-D   FRC   STO 00   .12   X>Y?   ST/ 49   after line 110
    and add    1   STO 49    after line 33

-With respect to execution time, " RIVER. . ."  is now displayed for 7 or 8 seconds instead of 37s

-It's surely possible to save bytes if you create loops inside LBL 17 & LBL 18,
 but this would increase execution time...
 

      c)  1 M-Code Routine:  $
 

-This routine combines  TRI & MV  listed in paragraph a)  above according to the content of register X:

  If X = 0  "$"  is equivalent to  TRI
  If X < 0  "$"  ---------------  MV
  If X > 0  "$"  ---------------  TRI + MV

-It saves 1 entry in the FAT and runs slightly faster.
 

Warning:   This routine checks that the required registers exist but it does not check for alpha data.
 
 

0A4  "$"                       Perhaps a more exotic name like  0A3 "#"  would be better...      (  @FD32  in my ROM  )
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X           The lines written in red
1D0  1D0h                   check that R48 exist.
306   ?A<C S&X        You might delete them
381   ?NCGO              to save a fraction of a second ... but it's risky if you XEQ "$" accidentally.
00A   02E0                  However, the existence of R48 is already checked line 36 of "POKER" below
0F8   C=X
2FE  ?C<0
361  ?CGO                  GOTO the 2nd part of the routine if X < 0
3FB  FED8                  @FED8 in my ROM.   ->  Change these 2 words according to your own ROM.
104   CLRF 8
2EE  ?C#0
017  JC+02
108  SETF 8
130   LDI S&X
005   005
146   A=A+C S&X
266   C=C-1 S&X
0E6   B<>C S&X
0A6  A<>C S&X
270   RAMSLCT
0A6  A<>C S&X
038   READDATA
0E6   B<>C S&X
270   RAMSLCT
0E6   B<>C S&X
2F0   WRITDATA
1A6   A=A-1 S&X
0E6   B<>C S&X
266   C=C-1  S&X
01F   JC+03
0E6   B<>C S&X
39B  JNC -13d
130   LDI S&X
005   005
070   N=C ALL
0EE   B<>C ALL
00E   A=0 ALL
0CE  C=B ALL
266   C=C-1 S&X
057   JC+10d
270   RAMSLCT
0EE   B<>C ALL
038   READDATA
31A  ?A<C ALL
3CB  JNC-07
0AE  A<>C ALL
0CE  C=B ALL
158   M=C ALL
3AB  JNC-11d
0B0   C=N ALL
266   C=C-1 S&X
070   N=C ALL
270   RAMSLCT
038   READDATA
0AE  A<>C ALL
2F0   WRITDATA
198   C=M ALL
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
0B0   C=N ALL
2E6   ?C#0 S&X
32F   JC-27d
04E   C=0 ALL
270   RAMSLCT
168   WRIT 5(M)
35C   PT=12
110   LD@PT-4
1A8  WRIT 6(N)
0B8   READ 2(Y)
268   WRIT 9(Q)
0F8   READ 3(X)
228   WRIT 8(P)
138   READ 4(L)
1E8   WRIT 7(O)
046   C=0 S&X
270   RAMSLCT
038   READDATA
158   M=C ALL
10E   A=C ALL
078   READ 1(Z)
070   N=C ALL
36E   ?A#C ALL
18B   JNC+49d
10E   A=C ALL
0B8   READ 2(Y)
36E   ?A#C ALL
15B   JNC+43d
10E   A=C ALL
0F8   READ 3(X)
36E   ?A#C ALL
143   JNC+40d
10E   A=C ALL
138   READ 4(L)
36E   ?A#C ALL
1F3   JNC+62d
2A0   SETDEC
10E   A=C ALL
198   C=M ALL
1CE  A=A-C ALL
08E   B=A ALL
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
1A8   WRIT 6(N)
3CE   RSHFC
30E   ?A<C ALL
187    JC+48d
0F8   READ 3(X)
10E   A=C ALL
198   C=M ALL
1CE  A=A-C ALL
04E   C=0 ALL
19C   PT= 11
0D0   LD@PT-3
158   M=C ALL
36E   ?A#C ALL
087   JC+16d
06E   A<>B ALL
3EE   LSHFA
04E   C=0 ALL
35C   PT= 12
1D0    LD@PT-7
1CE   A=A-C ALL
1B8   READ 6(N)
36E   ?A#C ALL
0D7   JC+26d
078   READ 1(Z)
1E8   WRIT 7(O)
0D3  JNC+26d
11B  JNC+35d
1D3  JNC+58d
0C3  JNC+24d
138   READ 4(L)
10E   A=C ALL
078   READ 1(Z)
1CE  A=A-C ALL
198   C=M ALL
36E   ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
04B   JNC+09
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
0D0   LD@PT-3
110   LD@PT-4
130   LDI S&X
003   003
168   M=C ALL
04E   C=0 ALL
1A8  WRIT 6(N)
163   JNC+44d
1AB  JNC+53d
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
0D0   LD@PT-3
130   LDI S&X
002   002
0C3  JNC+24d
10E   A=C ALL
0F8  READ 3(X)
36E   ?A#C ALL
1CB  JNC+57d
10E   A=C ALL
138   READ 4(L)
36E   ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
183   JNC+48d
228   WRIT 8(P)
078   READ 1(Z)
0AE  A<>C ALL
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
110    LD@PT-4
150    LD@PT-5
130    LDI S&X
002    002
1A3   JNC+52d
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
047   JC+08
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
226    C=C+1 S&X
193    JNC+50d
183    JNC+48d
228    WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
090    LD@PT-2
150    LD@PT-5
130    LDI S&X
002    002
103    JNC+32d
10E   A=C ALL
0B8   READ 2(Y)
36E   ?A#C ALL
1BB  JNC+55d
10E   A=C ALL
0F8   READ 3(X)
36E  ?A#C ALL
193   JNC+50d
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
037   JC+06
04E   C=0 ALL
35C   PT= 12
0D0   LD@PT-3
14B   JNC+41d
0C3   JNC+24d
228   WRIT 8(P)
0AE   A<>C ALL
268   WRIT 9(Q)
0B8   READ 2(Y)
070   N=C ALL
078   READ 1(Z)
10E   A=C ALL
04E   C=0 ALL
35C   PT= 12
0D0   LD@PT-3
110    LD@PT-4
150    LD@PT-5
130    LDI S&X
002    002
168    M=C ALL
0AE   A<>C ALL
1E8    WRIT 7(O)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
1A8   WRIT 6(N)
153    JNC+42d
123    JNC+36d
1E8   WRIT 7(O)
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
02F   JC+05
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
193    JNC+50d
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
050    LD@PT-1
150    LD@PT-5
226   C=C+1 S&X
0A3   JNC+20d
113    JNC+34d
0C3   JNC+24d
1E8   WRIT 7(O)
10E   A=C ALL
0F8   READ 3(X)
36E   ?A#C ALL
12B   JNC+37d
10E   A=C ALL
138   READ 4(L)
228   WRIT 8(P)
36E  ?A#C ALL
183   JNC+48d
0AE  A<>C ALL
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
110    LD@PT-4
150    LD@PT-5
226    C=C+1 S&X
168    WRIT 5(M)
04E   C=0 ALL
35C   PT= 12
0D0    LD@PT-3
1A8   WRIT 6(N)
11B   JNC+35d
1E8   WRIT 7(O)
10E   A=C ALL
138   READ 4(L)
36E  ?A#C ALL
0F3   JNC+30d
268   WRIT 9(Q)
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
168   WRIT 5(M)
078   READ 1(Z)
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
090    LD@PT-2
1A8   WRIT 6(N)
093   JNC+18d
063   JNC+12d
04E   C=0 ALL
35C   PT= 12
1D0    LD@PT-7
1A8   WRIT 6(N)
138    READ 4(L)
36E  ?A#C ALL
053   JNC+10d
228   WRIT 8(P)
04E   C=0 ALL
35C   PT= 12
150    LD@PT-5
168   WRIT 5(M)
04E   C=0 ALL
35C   PT= 12
190    LD@PT-6
1A8   WRIT 6(N)
260    SETHEX
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X
00B  011d
206   C=A+C S&X
270   RAMSLCT
10E   A=C ALL
0B0   C=N ALL
2F0   WRITDATA
130   LDI S&X
009   009
158   M=C ALL
270   RAMSLCT
038   READDATA
0AE  A<>C ALL
266   C=C-1 S&X
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
198   C=M ALL
266   C=C-1 S&X
3B3   JNC-10d
04E   C=0 ALL
270   RAMSLCT
35C  PT=12
0D0  LD@PT-3                     37 is used to evaluate the poker hands.
1D0  LD@PT-7                     Replace these 2 lines if you prefer another number, but choose at least 16.
226   C=C+1 S&X
2A0  SETDEC
128   WRIT 4(L)
10E   A=C ALL
1B8   READ 6(N)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
1F8   READ 7(O)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
238   READ 8(P)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
278   READ 9(Q)
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
0B0   C=N ALL
01D  ?NCXQ                    C=
060   1807                       A+C
10E   A=C ALL
138   READ 4(L)
135   ?NCXQ                    C=
060   184D                       A*C
10E   A=C ALL
046   C=0 S&X                 C
270   RAMSLCT               =
038   READDATA            T
01D  ?NCXQ                    C=
060   1807                       A+C
0E8   WRIT 3(X)                                 Here, the combination is evaluated.
070   N=C ALL                                   Then, its value is compared to R48 and the maximum is stored in R48
260   SETHEX
378    READ 13(c)
03C   RCR 3
106   A=C S&X
130   LDI S&X
030   048d
206   C=A+C S&X
270   RAMSLCT
0E6   B<>C S&X
038   READDATA
10E   A=C ALL
0B0   C=N ALL
306   ?A<C S&X
037   JC+06
0AE  A<>C ALL
306   ?A<C S&X
03F   JC+07
31A   ?A<C M
02F   JC+05
0E6   B<>C S&X
270   RAMSLCT
0B0  C=N ALL
2F0   WRITDATA
04E   C=0 ALL
270   RAMSLCT
10C  ?FSET 8
360   ?C RTN
378    READ 13(c)                 @FED8 in my ROM
03C   RCR 3
106   A=C S&X
130   LDI S&X
010   016d
206   C=A+C S&X
0E6   B<>C S&X
130   LDI S&X
004   004
070   N=C ALL
0E6   B<>C S&X
226   C=C+1 S&X
270   RAMSLCT
0E6   B<>C S&X
038   READDATA
0AE  A<>C ALL
226   C=C+1 S&X
270   RAMSLCT
0AE  A<>C ALL
2F0   WRITDATA
0B0   C=N ALL
266   C=C-1 S&X
39B   JNC-13d
3E0   RTN                          @FEEF  in my ROM

  ( 445 words )
 
 
 
 

      d)  "POKER"
 

-Like "POKER+" this program combines "POKER" , "POKER1" and "TXEM"
-It uses the M-Code routines CARD & $  listed above.
-Unlike "POKER+", there is also a round of betting before the flop.
 

Data Registers:           •  R00 = n                 ( Registers R00 & R41 are to be initialized before executing "POKER" )

                                      •  R41 = your Cash      R01 thru R40 & R42 thru R50: temp

Flags:  F07-F08-F09-F10

  CF 07 & CF 08 = Standard Draw Poker
  SF 07 & CF 08 = One-arm Bandit
  SF 08 = Texas Hold'em Poker

Subroutines:  $  CARD

-Lines 77-158-173-192-239-299-359 are three-byte GTOs
-The append character is denoted  >"   ( so that the listing can be use direcly with HP41UC )
 
 
 

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

 
        ( 901 bytes / SIZE 051 )
 
 

      STACK        INPUTS      OUTPUTS
           X             /             /

 
Instructions:

-The instructions are almost identical to "POKER+" listed in paragraph b) except that:

  1-Now, the HP-41 can bluff when playing "Texas Hold'em Poker" too ( SF 08 )
  2-There is a round of bettings before the "flop"

-The HP-41 bets before the flop are determined by a random number between 8000 and 12000 $ ( lines 81 to 87 )
-Change these lines according to your preference ( the HP-41 cards are in R01 & R02 at this step )