' 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 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

' 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.

_TITLE "Blackjack Multi AI Tester #2 Mouse over a player you want to check " ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics.

CONST nPlayers

= 9 'dealer counts as the last player this number depends on how many AI's to test CONST xmax

= 800, ymax

= 500, margin

= 4 CONST rank$

= "A23456789XJQK" 'for building deck and figuring Totals CONST bH

= 14, bW

= 20 ' box height and box width in rows and columns CONST white

= &HFFFFFFFF, black

= &HFF000000, bc

= &HFF008822, fc

= &HFFCCCCFF

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

DIM SHARED deck$

(1 TO 52), p

(1 TO nPlayers

) AS PlayerType

, deckIndex

, round

, allOut

, player

, blockDealer

, tN

AS LONG

initGame

'FOR i = 1 TO nPlayers

' showPlayer i

'NEXT

clearPlayers '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

showPlayer player

PlayerAddCard player

showPlayer 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: card$

= Johnno$

(player

) CASE 2: card$

= Johnno$

(player

) CASE 3: card$

= Steve$

(player

) CASE 4: card$

= Steve$

(player

) CASE 5: card$

= bplusAI$

(player

) CASE 6: card$

= bplusAI$

(player

) CASE 7: card$

= bplusAI2$

(player

) CASE 8: card$

= bplusAI2$

(player

) IF card$

= "h" THEN cp player

, 13, "Hit" IF card$

= "d" THEN cp player

, 13, "Double Down" IF card$

<> "h" AND card$

<> "d" THEN cp player

, 13, "Stay" PlayerAddCard player

showPlayer player

p(player).Bet = 2 * p(player).Bet

PlayerAddCard player

showPlayer player

showPlayer player

blockDealer = 0

showPlayer nPlayers

WHILE p

(nPlayers

).Total

< 17 cp nPlayers, 11, "Dealer takes a card."

PlayerAddCard nPlayers

showPlayer nPlayers

' final Reckoning

FOR player

= 1 TO nPlayers

- 1 showPlayer player

IF p

(player

).Total

> 21 OR (p

(player

).Total

< p

(nPlayers

).Total

AND p

(nPlayers

).Total

< 22) THEN cp player

, 13, "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 cp player, 13, "Push"

cp player

, 13, "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

cp player

, 13, "Win!" + STR$(p

(player

).Bet

) p(player).Chips = p(player).Chips + p(player).Bet

p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet

IF p

(player

).Chips

= 0 THEN cp player

, 14, "Out of chips!"

FOR i

= 1 TO nPlayers

- 1 IF ABS(mx

- p

(i

).Col

) <= .5 * bW

- 1 THEN showPlayer i

round = round + 1: allOut = -1

p(i).Hand = ""

p(i).Ace = 0

p(i).Total = 0

p(i).BJ = 0

p(i).Bust = 0

'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

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!"

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"

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

COLOR p

(nPlayer

).FC

, p

(nPlayer

).BC

FOR i

= 0 TO bH

- 1 'clear our block 'PRINT p(nPlayer).Row + i, p(nPlayer).Col

cp nPlayer

, 1, "Round:" + STR$(round

) cp nPlayer, 3, p(nPlayer).ID

cp nPlayer

, 5, "Chips:" + STR$(p

(nPlayer

).Chips

) IF nPlayer

<> nPlayers

THEN cp nPlayer

, 6, "Bet:" + STR$(p

(nPlayer

).Bet

) FOR i

= 1 TO LEN(p

(nPlayer

).Hand

) 'with 12 aces could get very long hands S$

= S$

+ MID$(p

(nPlayer

).Hand

, i

, 1) + " " cp nPlayer, 8, "___Hand___"

IF nPlayer

= nPlayers

AND LEN(p

(nPlayer

).Hand

) = 2 AND p

(nPlayer

).Total

<> 21 AND blockDealer

THEN cp nPlayer, 9, S$

cp nPlayer, 10, "Total: ??"

cp nPlayer, 9, S$

cp nPlayer

, 10, "Total:" + STR$(p

(nPlayer

).Total

)

IF p

(nPlayer

).Bust

THEN cp nPlayer

, 11, "Busted" IF p

(nPlayer

).BJ

THEN cp nPlayer

, 11, "Blackjack"

SUB initGame

'the stuff that never changes FOR i

= 1 TO 52 'get deck ready deck$

(i

) = MID$(rank$

+ rank$

+ rank$

+ rank$

, i

, 1)

'for printing in each players window area of screen = blackjack table

'xmax/8 = 2*margin + bW *(nplayers -1) + spacer *(nplayer-2)

spacer = ((xmax / 8) - margin - bW * (nPlayers - 1)) / (nPlayers - 2)

CASE 1: p

(i

).ID

= "Johnno 1" CASE 2: p

(i

).ID

= "Johnno 2" CASE 3: p

(i

).ID

= "Steve 1" CASE 4: p

(i

).ID

= "Steve 2" CASE 5: p

(i

).ID

= "bplus First AI 1" CASE 6: p

(i

).ID

= "bplus First AI 2" CASE 7: p

(i

).ID

= "bplus 2nd AI 1" CASE 8: p

(i

).ID

= "bplus 2nd AI 2" p(i).Col = margin + (i - 1) * (spacer + bW)

p(i).Row = 18

p(i).Chips = 100

p(i).SetBet = 2

p(i).ID = "Dealer"

p(i).Col = (xmax / 8 - bW) / 2

p(i).Row = 2

p(i).Chips = -100 * (nPlayers - 1)

'ask the user / YOU what e prefers for betting

cp 0, 10, "*** Blackjack Multi AI Tester ***"

cp 0, 12, "Each AI bot starts with 100 chips and bets 2 each round."

cp 0, 13, "Dealer must hit on 16 or less."

cp 0, 14, "Blackjack pays 1.5 X the bet."

cp 0, 15, "Double down option available when you get 2 cards."

cp 0, 16, "It Doubles the bet and you get one more card."

cp 0, 20, "press any to continue..."

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;