hp41programs

Template

Thirty-one ( card game ) for the HP-41


Overview


   1°)  Program#1
   2°)  Program#2


1°)  Program#1


-With this card game, the HP41 deals 3 cards to the player & 3 cards to itself
-The goal is to have a hand which totals 31 ( or as close as possible ).

-If you or the HP41 has 31 points, the round ends.
-Otherwise, you can discard 1 card, idem for the HP41.

-Press 1 to discard your 1st card ( from the left )
-Press 2 to discard your 2nd card
-Press 3 to discard your 3rd card.

-This continues until you - or the HP41 - thinks his hand has a value close enough to 31.

-The HP41 stops discarding when its hand has a value > 25 ( line 123 )
-Change this line if you prefer another value.

-When the HP41 stops discarding, the round ends.
-When you stop discarding ( press any other key than 1  2  3 ), your HP41 can still discard 1 card and the round ends.

-The 2 hands are displayed and the values of the 2 hands are compared.
-Finally, your bank is displayed.

-Press R/S for another round.


Card Values:

 Ace = 11
 King = Queen = Jack 10 points
 2 = 2 , ............... , 9 = 9 , 10 = 10

>>> A three of a kind = 30.5 points


-We use a deck of an infinite number of one-suit cards.
-In other words, the probability of each card is 1/13

-So it's possible to have a hand  ( for instance: AAK ) which totals 32 points.
-The HP41 calculates | 31 - Sum of the points |

-Thus,  AAK and  JQ9  have the same value !


-Initialize register R00 with a pseudo-random seed.


Data Registers:   • R00 = random number                         ( Registers R00 & R01 are to be initialized before executing "31" )

                               • R01 = your cash                            

                                 R02 = | 31 - Sum points player |           R04 to R06 = values of your cards      R10 to R12 = values of HP41 cards              R16: temp
                                 R03 = | 31 - Sum points HP41 |           R07 to R09 = your cards                     R13 to R15 = HP41 cards
Flags:  F09-F10
Subroutines: /

-Lines 84-91-168 are three-byte GTOs

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


         ( 382 bytes / SIZE 017 )


          STACK            INPUT          OUTPUT
              X                /          your cash


Example:
  If you choose 6 as the random seed and 0 in R01

   6  STO 00  
   0  STO 01   XEQ "31"   >>>>     J/¤              ( ¤ symbolizes the starburst, the hidden cards of the HP-41 )
                                                       J2 /¤¤
                                                       J2J /¤¤¤  

-If you want to discard the second card, press   2    your hand becomes:       J7J/¤¤¤      

-If you want to stop discarding, press for instance LN
 ( or any other key, except 1  2  3 )   the HP41 displays                                J7J/T6Q

-So, you have won and your new cash is displayed:                                      +13465 $

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



Notes:

-Here, the bets are randomly choosen by the HP-41 ( lines 236 to 241 ) between  10000 $ and ~ 13900 $
-If you want to place your own bets, replace these lines by  RCL 17  and add   FS?C 22   STO 17   after line 01.

-If you or the HP41 has a hand which totals exactly 31, the bet is multiplied by 2 ( line 244 )


2°)  Program#2



-This variant employs the same rules as the Blackjack program in paragraph 2-b) of  "Blackjack for the HP41"
  except that 21 is replaced by 31 and the HP41 deals 3 cards instead of 2.

-The HP41 deals cards for itself until its total equals or exceeds the player's total


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

                                      •  R01 = your cash

                                         R02 thru R12: temp

Flags:  F29  F09  F10
Subroutines:  /    


-Line 92 = TEXT0 , it may be replaced by any NOP instruction:  STO X  for example.
-Line 08 = STO d  is also a synthetic function: it may be replaced by  CF 09  CF 10  CF 29

 
 01 LBL "31+"
 02 31
 03 STO 02
 04 STO 03
 05 CLX
 06 STO 08          
 07 STO 09
 08 STO d
 09 SIGN
 10 STO 10
 11 CLA
 12 ASTO 04
 13 ASTO 05
 14 ASTO 11
 15 ASTO 12
 16 FIX 0
 17 XEQ 04
 18 XEQ 05
 19 XEQ 04
 20 XEQ 05
 21 XEQ 04
 22 RCL 09
 23 *
 24 X#Y?
 25 GTO 02
 26 3
 27 CHS
 28 STO 07
 29 SF 09
 30 GTO 06
 31 LBL 00
 32 ABS
 33 ISG Y
 34 LBL 10
 35 DSE Y
 36 X<0?
 37 RTN
 38 LASTX
 39 10
 40 -
 41 ABS
 42 X<Y?
 43 X<>Y
 44 RDN
 45 GTO 10
 46 LBL 01
 47 RCL 00          
 48 R-D
 49 FRC
 50 STO 00
 51 13
 52 *
 53 INT
 54 1
 55 +
 56 CLA
 57 ARCL X
 58 13
 59 X=Y?
 60 "K"
 61 DSE X
 62 X=Y?
 63 "Q"
 64 DSE X
 65 X=Y?
 66 "J"
 67 DSE X
 68 X=Y?
 69 "T"
 70 X<Y?
 71 X<>Y
 72 SIGN
 73 X=Y?
 74 "A"
 75 X<>Y
 76 ASTO Z
 77 CLA
 78 RTN
 79 LBL 02          
 80 41
 81 GETKEY
 82 X#Y?
 83 GTO 03
 84 XEQ 04
 85 CLX
 86 X<Y?
 87 GTO 02
 88 LBL 03
 89 11
 90 X=Y?
 91 ISG 10
 92 ""
 93 X=Y?
 94 XEQ 04
 95 RCL 09
 96 RCL 03
 97 XEQ 00
 98 STO 07
 99 LBL 06
100 XEQ 05
101 RCL 08          
102 *
103 X#Y?
104 GTO 08
105 3
106 CHS
107 STO 06
108 SF 10
109 GTO 09
110 LBL 04
111 XEQ 01
112 ST- 03
113 X=Y?
114 ST+ 09
115 ARCL 05
116 ARCL 11
117 ARCL Z
118 ASTO 05
119 ASHF
120 ASTO 11
121 RCL 03
122 GTO 06
123 LBL 05
124 XEQ 01
125 ST- 02
126 X=Y?
127 ST+ 08
128 ARCL 04
129 ARCL 12
130 ARCL Z
131 ASTO 04
132 ASHF
133 ASTO 12
134 RCL 02          
135 LBL 06
136 " "
137 ARCL 05
138 ARCL 11
139 >"/"
140 ARCL 04
141 ARCL 12
142 AVIEW
143 10
144 RTN
145 LBL 07
146 RCL 02
147 X<0?
148 GTO 09
149 XEQ 05
150 LBL 08
151 RCL 08
152 RCL 02
153 XEQ 00
154 STO 06          
155 RCL 07
156 X<Y?
157 FS? 09
158 FS? 30
159 GTO 07
160 LBL 09
161 COS
162 1.5
163 RCL 06
164 RCL 07
165 -
166 X#0?
167 SIGN
168 FC? 09
169 FS? 10
170 *
171 RCL 10
172 *
173 RCL 00
174 7
175 /
176 4
177 +
178 10^X
179 *
180 ST+ 01
181 RCL 01          
182 "  "
183 X>0?
184 >"+"
185 ARCL 01
186 >" $"
187 FIX 4
188 AVIEW
189 END


     ( 299 bytes / SIZE 013 )

 

      STACK        INPUT      OUTPUT
           X             /          Cash

 
Example:    If you choose 6 as the random seed and 0 in R01

   6  STO 00  
   0  STO 01   XEQ "31"   >>>>     J/       
                                                       J/6     
                                                       J2 /6
                                                       J2/6T
                                                       J2J /6T  
           
-If you press ENTER to get another card:              J2J2/6T  
-If you press again ENTER to get another card:     J2J27/6T  

-Your total = 31 so the HP41 deals cards to itself:     J2J27/6TQ     then    J2J27/6TQJ   so you won and your cash is     +13110 $

-Press R/S to continue to play.


Notes:

-There is no bust: the winner has its total closer to 31

-With a total equal to 31 with 3 cards, the bet is multiplied by 1.5 ( line 162 )
-This happens with  AKK , AQJ  and so on... but also with  AA9.

-Here, the bets are randomly choosen by the HP-41 ( lines 173 to 178 ) between  10000 $ and ~ 13900 $
-If you want to place your own bets, replace these lines by  RCL 13  and add   FS?C 22   STO 13   after line 01.

-A deck of an infinite number of one-suit cards is also used.
  ( In other words, the probability of each card = 1/13 )

-Press the SIGMA+ key to double the bet: in this case, you receive one card only.
-Press ENTER^  to hit: you can receive as many cards as you want ( until your points reach or exceed 31 )
-Press any other key to stand.


Reference:

[1]  https://en.wikipedia.org/w/index.php?title=Thirty-one_(card_game)&oldid=987340666