' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
'2020-07-05 fix hit (it wasn't broken), delete line chose$ = 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
' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester
' add in allot of code worked out in Blackjack with Bots 2019-06-07
' Yes, major overhaul of last year bot code which was/is neat!
' Thanks Johnno and Steve for some interesting AI ideas to try!
' 2020-07-07 for Blackjack Multi AI Tester #2, I hope to do something kind of interesting with displaying players
' Yes Mouse over a player you want to check on but try and stay out of way of updating.
' 2020-07-08 No overlapping players, sucks, get rid of timer stuff, removed.
' Screen Size depends on how many players go against Dealer from 1 to 6 maximum.
' 1 row of players with screen width < 1024, Dealer at top.
' Added more items to Player type to display status solely from it's array contents.
' Also forbid player to double down if es chips can't cover loss.
' Display round number in Title Bar
' 2020-07-08 added some basic stay strategies
'=================================================================================================================
' Blackjack Multi-Tester Notes: (removed from screening at start)
' *** Blackjack Multi AI Tester #3 ***
'
' Each AI bot starts with 100 chips and bets 2 each round.
' Dealer must hit on 16 or less.
' Blackjack pays 1.5 X the bet.
' Double down option available when you get 2 cards.
' It Doubles the bet and you get one more card.
'
'====================================================================================================================
CONST nPlayers
= 7 ' 2 to 7 only! Dealer counts as the last player Screen size is adjusted to this! CONST rank$
= "A23456789XJQK" ' for building deck and figuring Totals CONST bH
= 12, bW
= 20 ' box height and box width in rows and columns CONST bc
= &HFF008822, fc
= &HFFCCCCFF ' screen back and fore colors , no printing though
ID
AS STRING ' name of bot including dealer bot FC
AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White Hand
AS STRING ' cards are 1 char strings 10 is X Ace
AS INTEGER ' flag has ace for totalling hand Tell
AS STRING ' Hit, Stay Double or Win Push Loss Amt goal to put everything in PlayerType that showPlayer needs for display
DIM SHARED xmax
, deck$
(1 TO 52), p
(1 TO nPlayers
) AS PlayerType
, deckIndex
, round
, allOut
, player
, blockDealer
initGame
'FOR i = 1 TO nPlayers
' showPlayer i
'NEXT
'SLEEP
'END
startRound 'clears screen too and shuffles deck
FOR player
= 1 TO nPlayers
'each Player is dealt 2 cards allOut = 0 'signal everyone is out of chips is false
PlayerAddCard player
PlayerAddCard player
IF p
(nPlayers
).BJ
= 0 THEN 'dealer does not have BJ FOR player
= 1 TO nPlayers
- 1 showPlayer player
WHILE p
(player
).Total
< 21 SELECT CASE player
' this has to be coded for exactly all nPlayers - 1 CASE 1: chose$
= Johnno$
(player
) CASE 2: chose$
= Steve$
(player
) CASE 3: chose$
= stay16$
(player
) CASE 4: chose$
= stay17$
(player
) CASE 5: chose$
= stay18$
(player
) CASE 6: chose$
= bplusAI3$
(player
) 'no more than 6 bots IF chose$
= "h" THEN p
(player
).Tell
= "Hit" IF chose$
= "d" THEN p
(player
).Tell
= "Double Down" IF chose$
<> "h" AND chose$
<> "d" THEN p
(player
).Tell
= "Stay" showPlayer player
PlayerAddCard player
p(player).Bet = 2 * p(player).Bet
PlayerAddCard player
blockDealer = 0
showPlayer nPlayers
WHILE p
(nPlayers
).Total
< 17 p(nPlayers).Tell = "Dealer takes a card."
showPlayer nPlayers
PlayerAddCard nPlayers
p(nPlayers).Tell = "Reckoning"
showPlayer nPlayers
' final Reckoning
FOR player
= 1 TO nPlayers
- 1 showPlayer player
p(player).Tell = "Push"
ELSEIF p
(player
).Total
> 21 OR (p
(player
).Total
< p
(nPlayers
).Total
AND p
(nPlayers
).Total
< 22) THEN p
(player
).Tell
= "Lost" + STR$(p
(player
).Bet
) p(player).Chips = p(player).Chips - p(player).Bet
p(nPlayers).Chips = p(nPlayers).Chips + p(player).Bet
ELSEIF p
(player
).Total
= p
(nPlayers
).Total
AND p
(player
).BJ
= 0 THEN p(player).Tell = "Push"
p
(player
).Tell
= "Win!" + STR$(p
(player
).Bet
+ .5 * p
(player
).Bet
) p(player).Chips = p(player).Chips + p(player).Bet + .5 * p(player).Bet
p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet - .5 * p(player).Bet
p
(player
).Tell
= "Win!" + STR$(p
(player
).Bet
) p(player).Chips = p(player).Chips + p(player).Bet
p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet
showPlayer player
p(player).Tell = "Out of chips!":
showPlayer player
round = round + 1: allOut = -1
p(i).Hand = ""
p(i).Ace = 0
p(i).Total = 0
p(i).BJ = 0
p(i).Bust = 0
p(i).Tell = ""
'because of double down option I have to reset bet during play and set it back at each new round
'make sure we aren't betting more than our chips count at least to start
IF p
(i
).Chips
< p
(i
).SetBet
THEN p
(i
).Bet
= p
(i
).Chips
ELSE p
(i
).Bet
= p
(i
).SetBet
'deck$(5) = "A": deck$(10) = "J" 'check immediate show of Blackjack for dealer
deckIndex = 0: blockDealer = -1
SUB PlayerAddCard
(rec
) 'updates player's hand and total deckIndex = deckIndex + 1
p(rec).Hand = p(rec).Hand + deck$(deckIndex)
IF deck$
(deckIndex
) = "A" THEN p
(rec
).Ace
= -1 p(rec).Total = 0
p(rec).Total = p(rec).Total + cv
IF p
(rec
).Total
< 12 AND p
(rec
).Ace
THEN p
(rec
).Total
= p
(rec
).Total
+ 10 IF LEN(p
(rec
).Hand
) = 2 AND p
(rec
).Total
= 21 THEN p
(rec
).BJ
= -1 IF p
(rec
).Total
> 21 THEN p
(rec
).Bust
= -1 showPlayer rec 'when ever add card show update
SUB showPlayer
(nPlayer
) ' COLOR p
(nPlayer
).FC
, p
(nPlayer
).BC
FOR i
= 0 TO bH
- 1 'clear our block cp nPlayer, 1, p(nPlayer).ID
cp nPlayer
, 3, "Chips:" + STR$(p
(nPlayer
).Chips
) IF nPlayer
<> nPlayers
THEN cp nPlayer
, 4, "Bet:" + STR$(p
(nPlayer
).Bet
) S$
= S$
+ MID$(p
(nPlayer
).Hand
, i
, 1) + " " IF nPlayer
= nPlayers
AND LEN(p
(nPlayer
).Hand
) = 2 AND p
(nPlayer
).Total
<> 21 AND blockDealer
THEN cp nPlayer, 6, S$
cp nPlayer, 7, "Total: ??"
cp nPlayer, 6, S$
cp nPlayer
, 7, "Total:" + STR$(p
(nPlayer
).Total
) IF p
(nPlayer
).Bust
THEN cp nPlayer
, 8, "Busted" IF p
(nPlayer
).BJ
THEN cp nPlayer
, 8, "Blackjack" cp nPlayer, 10, p(nPlayer).Tell ' last action of player or dealer or final win lost push
_DELAY 1 'when ever showPlayer need a delay to read
SUB initGame
'the stuff that never changes ' 1+13*2 rows = 27*16 = 432 ymax
xmax = ((nPlayers - 1) * 21 + 1) * 8
'dealer on top row then max 2 rows of 5 players
SELECT CASE i
'vvvvvvvvvvvvvvvvvvvvvvvvvvvv plug in ai names here CASE 1: p
(i
).ID
= "Johnno" CASE 2: p
(i
).ID
= "Steve Stay 12" CASE 3: p
(i
).ID
= "George Stay 16" CASE 4: p
(i
).ID
= "Dealer Stay 17" CASE 5: p
(i
).ID
= "Steve2 Stay 18" CASE 6: p
(i
).ID
= "b3 stay16 dd11" p(i).Col = 2 + (i - 1) * 21
p(i).Row = 15
p(i).Chips = 100
p(i).SetBet = 2
p(i).ID = "Dealer"
p(i).Col = (xmax \ 8 - 20) \ 2 + 1
p(i).Row = 2
p(i).Chips = -100 * (nPlayers - 1)
p(i).BC = &HFF000000
p(i).FC = &HFFFFFFFF
FOR i
= 1 TO 52 'get deck ready deck$
(i
) = MID$(rank$
+ rank$
+ rank$
+ rank$
, i
, 1)
SUB cp
(nPlayer
, row
, s
AS STRING) 'center print a string on the given row COLOR p
(nPlayer
).FC
, p
(nPlayer
).BC
LOCATE p
(nPlayer
).Row
+ row
, p
(nPlayer
).Col
+ (bW
- LEN(s
)) / 2:
PRINT s;
PRINT s
, row
, (xmax \
8 - LEN(s
)) / 2 + 1
' ======================================= AI storage Area #51
CASE IS < 10: bplusAI$
= "h" 'no caps! CASE ELSE: bplusAI$
= "Show me the money!"
FUNCTION bplusAI2$
(pN
) 'after trying first want to try this make it more likely to hit on 12 than 13, 14... CASE IS < 10: bplusAI2$
= "h" 'no caps! CASE 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer CASE ELSE: bplusAI2$
= "Show me the money!"
FUNCTION bplusAI3$
(pn
) ' first try modified to stay 16 plus dd on 11 only
Johnno$ = "d"
Johnno$ = "h"
CASE "A", "K", "Q", "J", "X", "9": Johnno$
= "h" Johnno$ = "h"
Johnno$ = "Stay"
FUNCTION Steve$
(pN
) 'how simple is this! never bust make dealer work for it IF p
(pN
).Total
< 12 THEN Steve$
= "h"
FUNCTION stay16$
(pN
) ' calling this George because he seems to agree, might want to do more about what Dealer is showing IF p
(pN
).Total
< 16 THEN stay16$
= "h" IF p
(pN
).Total
< 17 THEN stay17$
= "h" FUNCTION stay18$
(pN
) 'this might have been what Steve was talking about so calling it Steve2 IF p
(pN
).Total
< 18 THEN stay18$
= "h"