Post Reply 
(12C) Twenty-One (aka Blackjack)
08-09-2023, 01:41 PM
Post: #1
(12C) Twenty-One (aka Blackjack)
I've noticed that the programming capabilities of the HP12c are very similar to my first programmable calculator from the 1970's, the Commodore PR100. So I converted some small programs from that time.

One of my favorite calculator games back then was Twenty-One, which seems perfect for the HP12C.

Code:

01 CLEAR STAT     clears also the stack (player starts)
02 STO 5          #5 (1=bank else player)
03 RCL 0          #4 card (in advance save a seed between 0 and 1 to STO 0)
04 9
05 LN
06 +
07 5
08 Y^X
09 FRAC           "random" number between 0 and 1
10 STO 0          store as new seed to STO 0
11 1
12 0
13 *
14 2
15 +
16 INTG           create a number (card) between 2-11
17 PSE
18 RCL 5
19 1
20 -
21 X=0
22 GTO 40         >1 if R5=1 <bank> else <player>
23 R down         <player>
24 STO + 1
25 RCL 1
26 2
27 2
28 X<=Y
29 GTO 57         >2 lost
30 R down
31 R/S            show players "cards" and wait for R/S oder <1> R/S
32 ENTER
33 1
34 -
35 X=0
36 GTO 38         >3 if input is 1 then stand and init bank draws
37 GTO 03         >4 next card (player)
38 1              #3 set target to bank
39 GTO 02         >5 draw 1st card (bank)
40 R down         #1 <bank>
41 STO + 2
42 1
43 6
44 RCL 2
45 PSE
46 X<=Y
47 GTO 03         >4 next card (bank)
48 2
49 2
50 X<=Y
51 GTO 58         >6 bust, player wins
52 RCL 2
53 RCL 1
54 1
55 +              player wins on equal
56 X<=Y
57 ,              #2 <lost>
58 1              #6 <win>
59 STO + 3
60 RLC 3
61 R/S
62 CLX            <new round>
63 STO 1
64 STO 2
65 GTO 02         >5 start new round (as player)

Twenty-One (aka Blackjack)

Usage:
<R/S> = hit/card, <1> <R/S> = stand/hold (bank draws)
The display shows the new card value, blinks and shows the total of all cards.
If the total is higher than 21, the player/bank loses.
Player wins a round if he scores the same or more than the bank.
Display of e.g. 3.2 means player won 3 rounds so far, bank 2.
The game ends if bank loses 9 times, then you must start a new game.

REG 0 - random
REG 1 - player
REG 2 - bank
REG 3 - counter
REG 5 - target

My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C
Find all posts by this user
Quote this message in a reply
08-09-2023, 07:51 PM
Post: #2
RE: (12C) Twenty-One (aka Blackjack)
This code is amazing.
Visit this user's website Find all posts by this user
Quote this message in a reply
08-10-2023, 08:46 PM
Post: #3
RE: (12C) Twenty-One (aka Blackjack)
Who says a financial calculator can't be fun Smile

My calculators - former: CBM PR100, HP41CV, HP11C, HP28S - current: HP48G, HP35S, Prime, DM41X, DM42, HP12C
Find all posts by this user
Quote this message in a reply
Post Reply 




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