%%HP: T(3)A(D)F(.);
@ by Preston Brown
DIR
@ CPRAC - practice card counting for blackjack
@ This program requires the CASINO 48 application card.
@ The Casino 48 card must be installed when downloading this file.
@
@ Casino 48 is a fun-filled simulation of a casino for the HP-48SX.
@ It includes four games: Blackjack, Video Poker, Slots and Roulette.
@ It also includes commands for drawing cards onto the screen.  
@ This program uses those commands to practice card counting.
@ With card counting the odds in blackjack can be improved to 
@ give the player an advantage over the house.
@
@ To win at blackjack you first need a good basic strategy,
@ Casino 48 includes a recommend function in blackjack which
@ should be used to learn the best strategy.  Once the strategy
@ is mastered, card counting can be used to set your bet.
@ This program allows you to practice a very simple but effective
@ counting technique.  If you wish to use a more advanced method
@ the CALC procedure can be easily modified for other methods.
@
@ SIMPLE COUNT METHOD:
@ For each 3, 4, 5, or 6 add 1 to the count
@ For each 10-valued card subtract 1 from the count
@ Betting:
@  COUNT       BET UNITS
@    <0           1
@    0,1          2
@    2            3
@    3,4,5        4
@    >6           5 or more (be careful the casino may be watching)
@
@ This simple count does not require the player to keep track
@ of the number of cards remaining in the deck but is still effective.
@ A positive count with most of the deck played is more favorable
@ then with most of the deck unplayed.
@ 
@ ************************** NOTICE *****************************
@ Preston Brown Labs does not endorse or recommend card counting.
@ Preston Brown Labs is not responsible for any consequential damages.
@ This program may be distributed freely; in ASCII form with the
@ above information intact.
@
HELP
\<< CLLCD TEXT 3 FREEZE
@123456789012345678912
"Enter number of cards" 1 DISP
"to count: press CPRAC" 2 DISP
"Add 1 for 3-6"         3 DISP
"Sub 1 for 10 valued"   4 DISP
"Raise BET for high"    6 DISP
"counts!"               7 DISP
\>>

CPRAC               @ Main practice program
\<< 
IF CHECKCARD THEN   @ Check for Casino 48 card
     ECAR
     {#0 #0} PVIEW
     0                    @ Initial Count
     SWAP 1 SWAP START
            GETCARD DUP DCAR CALC SPEED WAIT ECAR
            NEXT
     ELSE
     CLLCD 3 FREEZE
     @123456789012345678912
     "Requires Casino 48"    1 DISP
     "Ask your HP dealer or" 3 DISP
     "send check for $65 to" 4 DISP
     "Preston Brown Labs"    5 DISP
     "  2597 Pierce"         6 DISP
     "Eugene, OR 97405"      7 DISP
     END
\>> 

SPEED 0.5           @ Default Speed (set to any value > 0)
                    @ The larger the value the slower the 
                    @ speed

CALC
\<< 
IP
CASE
  DUP 9 > THEN DROP 1 - END            @ 10 Valued Cards subtr 1
  DUP 2 > SWAP 7 < AND THEN 1 + END    @ 3-6 add 1
END
\>>

SHUF                @ Shuffle 4 decks of cards
\<< TEXT CLLCD
"Shuffling..." 1 DISP
"                          " DUP + DUP + DUP + 'DECK' STO 
0 51 FOR i i CHR NEXT 
52 DUPN 104 DUPN 
208 1 FOR I I RAND * .5 + ROLL DECK I ROT REPL 'DECK' STO -1 STEP 
209 CHR 'DECK' STO+
"Shuffle Done" 1 DISP 
1000 1 BEEP
{#0 #0} PVIEW
\>>

GETCARD
\<< 
@GETCARD Check deck and get a card
IF DECK NUM 1 < THEN SHUF END
DECK DUP NUM \-> D N
  \<< D 1 N 1 - CHR REPL 'DECK' STO 
      D N DUP SUB NUM 
      DUP 13 MOD 1 + SWAP 4 MOD 1 + 10 / +
  \>>
\>>

CHECKCARD   @ This function clears the last arg flag
\<< -55 CF  @ Enable last args to get predictable results
    IFERR 1 PVARS DROP :1:769 POS THEN DROP 0 END
    IFERR 2 PVARS DROP :2:769 POS THEN DROP 0 END
    OR
\>>


@ Other Variables
CRDX 0
DECK ""

END
