' Started from code not using card images so:
' 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 if dealer has Blackjack should tell also fix exposing 2nd card. Work this
' towards converting to multiple AI players, then all players stats are located
' in PlayerType and displayed with ShowPlayer (player) SUB.
' 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 many players at one time.
' Yes Mouse over a player you want to check on but try and stay out of way of updating.
' 2020-07-08 BJ Multi AI Tester #3
' 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
' 2020-07-09 Some more fixes to Tester #3: Stop dealing cards to players without chips.
' Forbid DD if don't have chips to cover loss. Need Round number when run out of chips.
' First Johnno AI went over 10,000 rounds on 200 chips!
' 2020-07-10 I give up trying to find a strategy to stop draining a player of chips, so one
' little change in rules. ;-)) Something that Casinos would never do...
' 2020-07-11 Final adjustments to Tester #3
' >>>>>>>>>>> GOTO LINE #272 to adjust speed of play uncomment _DELAY line
' >>>>>>>>>>> set to 1 or 2 to watch game play, .01 for fast round and watch chips
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' CAUTION: IN THE INTEREST OF HAVING FUN PLAYING THIS GAME, WE HAVE DEVIATED FROM CASINO RULES.
' NEVER THINK YOUR EXPERIENCE PLAYING THIS GAME HERE WOULD BE LIKE PLAYING IN A REAL CASINO!
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Blackjack Multi-Tester Notes: (removed from screening at start)
' *** Blackjack Multi AI Tester #3 ***
'
' Each AI bot starts with 200 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 CONST rank$
= "A23456789XJQK" ' for building deck and figuring Totals CONST bH
= 12, bW
= 20 ' box height and box width in rows and columns
TYPE PlayerType
' Goal: Put everything in PlayerType that showPlayer needs for display ID
AS STRING ' name of bot including dealer bot Col
AS INTEGER ' left corner column for player box 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 SetBet
AS _INTEGER64 'regular bet amount if enough chips to cover Bet
AS _INTEGER64 ' players bet each round maybe updated by DD Tell
AS STRING ' Hit, Stay Double or Win Push Loss Amt RunOut
AS DOUBLE ' Round player runs out of chips
DIM SHARED p
(1 TO nPlayers
) AS PlayerType
' contains player data for processing and display DIM SHARED xmax
' Screen size _WIDTH is adjusted to number of players and stored here DIM SHARED deck$
(1 TO 52), deckIndex
' cards are just string * 1 see rank$
initGame
startRound 'clears screen too and shuffles deck
FOR plr
= 1 TO nPlayers
'each Player is dealt 2 cards allOut = 0 'signal everyone is out of chips is false
PlayerAddCard plr
showPlayer nPlayers 'final chip count = 0 ? when all is said and done
PlayerAddCard plr
IF p
(nPlayers
).BJ
= 0 THEN 'dealer does not have BJ FOR plr
= 1 TO nPlayers
- 1 IF p
(plr
).Chips
> 0 THEN 'make sure player still can bet showPlayer plr
SELECT CASE plr
' this has to be coded for exactly all nPlayers - 1
'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Insert AI subs here !!!!!!!
CASE 1: chose$
= bplusAI$
(plr
) CASE 2: chose$
= bplusAI2$
(plr
) CASE 3: chose$
= bplusAI3$
(plr
) CASE 4: chose$
= stay18$
(plr
) CASE 5: chose$
= stay17$
(plr
) CASE 6: chose$
= Johnno2$
(plr
) 'no more than 6 bots
IF chose$
= "h" THEN p
(plr
).Tell
= "Hit" IF chose$
= "d" THEN p
(plr
).Tell
= "Double Down" IF chose$
<> "h" AND chose$
<> "d" THEN p
(plr
).Tell
= "Stay" showPlayer plr
PlayerAddCard plr
IF p
(plr
).Chips
>= 2 * p
(plr
).Bet
THEN ' chips to cover a DD? p(plr).Bet = 2 * p(plr).Bet
PlayerAddCard plr
ELSE 'if not play it like a hit PlayerAddCard plr
blockDealer = 0
showPlayer nPlayers ' nPlayers is Dealer player number
WHILE p
(nPlayers
).Tot
< 17 p(nPlayers).Tell = "Dealer hits"
showPlayer nPlayers
PlayerAddCard nPlayers
p(nPlayers).Tell = "Reckoning"
showPlayer nPlayers
' final Reckoning
FOR plr
= 1 TO nPlayers
- 1 showPlayer plr
IF (p
(plr
).BJ
AND p
(nPlayers
).BJ
) OR (p
(plr
).Bust
AND p
(nPlayers
).Bust
) THEN p(plr).Tell = "Push"
ELSEIF p
(plr
).Tot
> 21 OR (p
(plr
).Tot
< p
(nPlayers
).Tot
AND p
(nPlayers
).Tot
< 22) THEN p
(plr
).Tell
= "Lost" + STR$(p
(plr
).Bet
) p(plr).Chips = p(plr).Chips - p(plr).Bet
p(nPlayers).Chips = p(nPlayers).Chips + p(plr).Bet
p(plr).Tell = "Push"
p
(plr
).Tell
= "Win!" + STR$(p
(plr
).Bet
+ .5 * p
(plr
).Bet
) p(plr).Chips = p(plr).Chips + p(plr).Bet + .5 * p(plr).Bet
p(nPlayers).Chips = p(nPlayers).Chips - p(plr).Bet - .5 * p(plr).Bet
p
(plr
).Tell
= "Win!" + STR$(p
(plr
).Bet
) p(plr).Chips = p(plr).Chips + p(plr).Bet
p(nPlayers).Chips = p(nPlayers).Chips - p(plr).Bet
showPlayer plr
p(plr).RunOut = round
p(plr).Tell = "Out of chips!"
showPlayer plr
LOOP UNTIL allOut
OR round
= 1000 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Control # rounds !!!!!!!!!!!! round = 0
results(plr) = results(plr) + p(plr).Chips - 200 'the chips started with
p(plr).Chips = 200 'reset chips to start amount
round = round + 1: allOut = -1
p(i).Hand = ""
p(i).Ace = 0
p(i).Tot = 0
p(i).BJ = 0
p(i).Bust = 0
p(i).Tell = ""
'because of DD 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$(7) = "A": deck$(14) = "J" 'check immediate show of Blackjack for dealer
deckIndex = 0: blockDealer = -1
_TITLE "BJ AI Tester #3 - Session:" + STR$(session
) + " Round:" + STR$(round
)
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).Tot = 0
cv = 10
p(rec).Tot = p(rec).Tot + cv
IF p
(rec
).Tot
< 12 AND p
(rec
).Ace
THEN p
(rec
).Tot
= p
(rec
).Tot
+ 10 IF LEN(p
(rec
).Hand
) = 2 AND p
(rec
).Tot
= 21 THEN p
(rec
).BJ
= -1 IF p
(rec
).Tot
> 21 THEN p
(rec
).Bust
= -1 showPlayer rec 'when ever add card show update
FOR i
= 0 TO bH
- 1 'clear our block cp nP, 1, p(nP).ID
cp nP
, 3, "Chips:" + STR$(p
(nP
).Chips
) IF nP
<> nPlayers
THEN cp nP
, 4, "Bet:" + STR$(p
(nP
).Bet
) S$
= S$
+ MID$(p
(nP
).Hand
, i
, 1) + " " cp nP, 6, S$
cp nP, 7, "Total: ??"
cp nP, 6, S$
cp nP
, 7, "Total:" + STR$(p
(nP
).Tot
) IF p
(nP
).Bust
THEN cp nP
, 8, "Busted" IF p
(nP
).BJ
THEN cp nP
, 8, "Blackjack" IF p
(nP
).RunOut
THEN cp nP
, 9, "Round" + STR$(p
(nP
).RunOut
) cp nP, 10, p(nP).Tell ' last action of player or dealer or final win lost push
272 '_DELAY 1 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< modify this line for speed !!!!!!!!
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
'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV plug in ai names here !!!!!!!! CASE 1: p
(i
).ID
= "b1 s17 dd1" CASE 2: p
(i
).ID
= "b2 s17 dd2" CASE 3: p
(i
).ID
= "b3 s17 dd3" CASE 6: p
(i
).ID
= "johnno 2" p(i).Col = 2 + (i - 1) * 21
p(i).Row = 15
p(i).Chips = startChips
p(i).SetBet = 2
p(i).ID = "Dealer"
p(i).Col = (xmax \ 8 - 20) \ 2 + 1
p(i).Row = 2
p(i).Chips = -startChips * (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;
' =========== AI storage Area #51 stay 16 or 17 are contenders various DD options
' After looking at Dealer stats I like Stay 16 though test runs like Stay 17 same as dealer.
' So I am tryig Stay 16 with 3 different DD options only when Dealer is showing
' card below 10 and no Ace!
' Dang Stay 17 Domimates! Changed all to Stay 17, much better!
FUNCTION bplusAI$
(pn
) ' mod after looking at stats, Stay 16 DD1 CASE 11 ' won't bust but could be a pretty low card to gamble on bplusAI$ = "h"
bplusAI$ = "h"
FUNCTION bplusAI2$
(pN
) 'after trying some stats DD very restricted, Stay 16 CASE 10, 11 'double down unless dealer showing an Ace or 10's bplusAI2$ = "h"
FUNCTION bplusAI3$
(pn
) ' first try modified to stay 16 plus dd on 11 only SELECT CASE p
(pn
).Tot
'try 9 instead of 12 for 3rd DD card CASE 10, 11, 12 'double down unless dealer showing an Ace or high #'s bplusAI3$ = "h"
FUNCTION Johnno$
(pN
) ' this was doing well before the Bust Rule changed but not now Johnno$ = "d"
Johnno$ = "h"
CASE "A", "K", "Q", "J", "X", "9": Johnno$
= "h" Johnno$ = "h"
Johnno$ = "Stay"
FUNCTION Johnno2$
(pN
) ' DD2 stay 13 depends 14-16 Johnno2$ = "d"
Johnno2$ = "h"
CASE "A", "K", "Q", "J", "X", "9": Johnno2$
= "h" Johnno2$ = "h"
Johnno2$ = "Stay"
' ================================= pure Stay Strategies no DD options
'not a contender
FUNCTION stay12$
(pN
) 'how simple is this! never bust make dealer work for it IF p
(pN
).Tot
< 12 THEN stay12$
= "h"
FUNCTION stay16$
(pN
) 'definite contender, no longer! try 18 instead IF p
(pN
).Tot
< 16 THEN stay16$
= "h" FUNCTION stay17$
(pN
) 'definite contender really does well IF p
(pN
).Tot
< 17 THEN stay17$
= "h"
FUNCTION stay18$
(pN
) 'was not a contender before changed player Bust Rule IF p
(pN
).Tot
< 18 THEN stay18$
= "h"