OPTION _EXPLICIT ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10 DEFINT A
-Z
' Player's Blackjack pays double the bet set at the beginning of the game '2020-07-05 fix hit (it wasn't brolen), delete line card$ = inkey$ before loop
' force dealer to hit on 16 stay 17
' ties are push
' bring in double down option
' fix dealer has Blackjack should tell also fix exposing 2nd card
' work this towards converting to multiple AI players, so players stats are all located in PlayerType
' 2020-07-06 Installed AI and mods for it
' 2020-07-06 new Compact Tester with 2nd AI
_TITLE "Blackjack AI Tester" ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics. CONST rank$
= "A23456789XJQK"
Players(Player).ID = "Player"
Players(Dealer).ID = "Dealer"
deck$
(i
) = MID$(rank$
+ rank$
+ rank$
+ rank$
, i
, 1)Players(Dealer).chips = -100
Players(Player).chips = 100
'bbbbb"1234567890123456789012345678901234567890
cp 4, "*** BJ Compact AI Tester ***"
cp 6, "You start with 100 chips."
cp 7, "AI sets bet amount to 2."
cp 8, "Dealer must hit on 16 or less."
cp 9, "Blackjack pays 1.5 X the bet."
cp 10, "Double down option available"
cp 11, "when you get 2 cards."
cp 12, "It Doubles the bet and you get one"
cp 13, "more card."
cp 17, "press any to continue..."
Players(Player).setBet = 2
'LOCATE 17, 38: INPUT ""; Players(Player).setBet
IF Players
(Player
).setBet
= 0 THEN cp
10, "You have" + STR$(Players
(Player
).chips
) + "." LOCATE 11, 25:
INPUT "(0 quits) Enter your bet > ", Players
(Player
).bet
IF Players
(Player
).bet
>= Players
(Player
).chips
THEN Players
(Player
).bet
= Players
(Player
).chips
IF Players
(Player
).chips
< Players
(Player
).setBet
THEN Players
(Player
).bet
= Players
(Player
).chips
ELSE Players
(Player
).bet
= Players
(Player
).setBet
clearPlayers 'clears screen too
cp
4, "Chips:" + STR$(Players
(Player
).chips
) + " betting:" + STR$(Players
(Player
).bet
) + " chips." deckIndex = 0
FOR i
= 1 TO 2 'each Player is dealt 2 cards PlayerAddCard Player
IF i
= 1 THEN cp
10, playerShow$
(Player
) PlayerAddCard Dealer
IF i
= 1 THEN cp
7, playerShow$
(Dealer
) cp 10, playerShow$(Player)
cp
7, Players
(Dealer
).ID
+ ": " + MID$(Players
(Dealer
).Hand
, 1, 1) + " ? Total = ??" ' BJ debug players having BJ
'Players(Dealer).Total = 21
'Players(Player).Total = 21
IF Players
(Player
).Total
= 21 AND Players
(Dealer
).Total
= 21 THEN cp 7, playerShow$(Dealer) + " Blackjack!"
cp 10, playerShow$(Player) + " Blackjack!"
cp 13, "Push"
cp 10, playerShow$(Player) + " Blackjack!"
Players(Player).chips = Players(Player).chips + 1.5 * Players(Player).bet
Players(Dealer).chips = Players(Dealer).chips - 1.5 * Players(Player).bet
cp
13, "You won" + STR$(2 * Players
(Player
).bet
) cp 7, playerShow$(Dealer) + " Blackjack!"
Players(Player).chips = Players(Player).chips - Players(Player).bet
Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
cp
13, "You lost" + STR$(Players
(Player
).bet
) WHILE Players
(Player
).Total
< 21 cp 15, "Hit Double or Stay"
cp 15, "Hit or Stay"
'card$ = ""
'WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND ' bplus calling it in now!
card$ = bplusAI$
IF card$
= "h" THEN cp
17, "Hit" IF card$
= "d" THEN cp
17, "Double Down" IF card$
<> "h" AND card$
<> "d" THEN cp
17, "Stay" PlayerAddCard Player
'cp 11, SPACE$(50)
cp 10, playerShow$(Player)
IF Players
(Player
).Total
> 21 THEN GOTO finalReckoning
'busted! skip dealer expose 2nd and play Players(Player).bet = 2 * Players(Player).bet
PlayerAddCard Player
'cp 11, SPACE$(50)
cp 10, playerShow$(Player)
IF Players
(Player
).Total
> 21 THEN GOTO finalReckoning
'bustest! skip dealer expose 2nd and play ' cp 11, SPACE$(50)
cp 7, playerShow$(Dealer)
WHILE Players
(Player
).Total
< 22 AND Players
(Dealer
).Total
< 17 cp 8, "Dealer takes a card."
PlayerAddCard Dealer
cp 7, playerShow$(Dealer)
finalReckoning:
IF Players
(Player
).Total
> 21 OR (Players
(Player
).Total
< Players
(Dealer
).Total
AND Players
(Dealer
).Total
< 22) THEN cp
13, "You lose" + STR$(Players
(Player
).bet
) Players(Player).chips = Players(Player).chips - Players(Player).bet
Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
ELSEIF Players
(Player
).Total
= Players
(Dealer
).Total
THEN cp 13, "Push"
cp
13, "You win!" + STR$(Players
(Player
).bet
) Players(Player).chips = Players(Player).chips + Players(Player).bet
Players(Dealer).chips = Players(Dealer).chips - Players(Player).bet
BJskip:
IF Players
(Player
).chips
= 0 THEN cp
15, "Out of chips!" cp 17, "Goodbye"
round = round + 1
cp
2, "Round:" + STR$(round
) Players(i).Hand = ""
Players(i).Ace = 0
Players(i).Total = 0
'FUNCTION bplusAI$ ' first try
' SELECT CASE Players(Player).Total
' CASE IS < 10: bplusAI$ = "h" 'no caps!
' CASE 10, 11
' IF LEN(Players(Player).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
' CASE IS < 15
' IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
' CASE ELSE: bplusAI$ = "Show me the money!"
' END SELECT
'END FUNCTION
FUNCTION bplusAI$
'after trying first want to try this make it more likely to hit on 12 than 13, 14... CASE IS < 9: bplusAI$
= "h" 'no caps! CASE 9, 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer IF LEN(Players
(Player
).Hand
) = 2 AND LEFT$(Players
(Dealer
).Hand
, 1) <> "A" THEN bplusAI$
= "d" ELSE bplusAI$
= "h" CASE ELSE: bplusAI$
= "Show me the money!"
SUB PlayerAddCard
(receiver
) 'updates player's hand and total deckIndex = deckIndex + 1
Players(receiver).Hand = Players(receiver).Hand + deck$(deckIndex)
IF deck$
(deckIndex
) = "A" THEN Players
(receiver
).Ace
= -1 Players(receiver).Total = 0
FOR i
= 1 TO LEN(Players
(receiver
).Hand
) Players(receiver).Total = Players(receiver).Total + cv
IF Players
(receiver
).Total
< 12 AND Players
(receiver
).Ace
THEN Players
(receiver
).Total
= Players
(receiver
).Total
+ 10
FUNCTION playerShow$
(shower
) 'creates string with player name: hand Total = xx and "Busted!" if so. S$ = Players(shower).ID + ": "
S$
= S$
+ MID$(Players
(shower
).Hand
, i
, 1) + " " S$
= S$
+ "Total =" + STR$(Players
(shower
).Total
) IF Players
(shower
).Total
> 21 THEN S$
= S$
+ " Bust" playerShow$ = S$
SUB cp
(row
, s
AS STRING) 'print centered on row the string