OPTION _EXPLICIT ' No suits for cards A is Ace, J, Q, K are Jack, Queen, King, X is Roman for 10 DEFINT A
-Z
' Dealer wins all ties except a Player's Blackjack which pays double the bet _TITLE "Blackjack with Bots" ' started 2019-06-07 Players 1 through 3 are bots you play bottom right
TYPE XY
'graphic or cell location on screen or in array
TYPE PlayerType
'a container for all program data! Win
AS Box
'for screening the players data
CONST nPlayers
= 5 ' the 5th is the Dealer, the 4th is You and 1 - 3 are the bots who go first CONST dk
= "A2345A6789AXJQKA2345A6789AXJQKA2345A6789AXJQKA2345A6789AXJQK" CONST orange
= &HFFFF3300 CONST ltCyan
= &HFF99BBFF CONST drkRed
= &HFF220102 CONST yellow
= &HFFFFFF00
DIM i
, j
, r
, in
, is$
, stillPlayer
deck$
(i
) = MID$(dk
, i
, 1)initPlayers
clearPlayers 'clears screen too start a round
stillPlayer = 0 ' to check at end of round if there is still a player playing
IF player
(3).Chips
> 0 THEN ' handle bets player
(3).Bet
= INT(player
(3).Chips
/ 2 + .5) IF player
(You
).SetBet
= 0 THEN cp
0, 10, "You have" + STR$(player
(4).Chips
) + " chips to bet." IF in
> player
(You
).Chips
THEN player
(You
).Bet
= player
(You
).Chips
ELSE player
(You
).Bet
= in
player(You).Bet = player(You).SetBet
FOR i
= 1 TO 4 'make sure everyone is not betting more than amount of chips they have IF player
(i
).Bet
> player
(i
).Chips
THEN player
(i
).Bet
= player
(i
).Chips
deckIndex = 0
FOR j
= 1 TO 2 ' everybody gets 2 cards if they still have chips FOR i
= 1 TO nPlayers
'each Player is dealt 2 cards IF ((player
(i
).Chips
> 0) AND (i
<> Dealer
)) OR (i
= Dealer
) THEN addCard i
showPlayer i
cp Dealer, 7, "? "
cp Dealer, 8, "Total: ?"
cp Dealer
, 7, "Hand: ? " + MID$(player
(Dealer
).Hand
, 2, 1) cp Dealer, 8, "Total: ?"
cp i, 9, "Blackjack!"
player(i).Blackjack = -1
clsPlayer i
FOR i
= 1 TO nPlayers
- 1 ' OK now handle the players until they stay or bust WHILE player
(i
).Total
< 21 cp i, 11, "<h>it <s>tay"
addCard You
showPlayer i
IF player
(i
).Total
< 16 THEN ' bots to hit on < 16 cp i, 11, "Hit me."
addCard i
showPlayer i
showPlayer Dealer ' dealer's turn
WHILE player
(Dealer
).Total
< 17 cp Dealer, 10, "(Takes a card)"
addCard Dealer
showPlayer Dealer
FOR i
= 1 TO nPlayers
- 1 ' name the winners and losers, payup IF player
(i
).Blackjack
= 0 THEN IF player
(i
).Total
> 21 OR (player
(i
).Total
<= player
(Dealer
).Total
AND player
(Dealer
).Total
< 22) THEN cp i, 11, player(i).ID + " lost."
player(i).Chips = player(i).Chips - player(i).Bet
player(Dealer).Chips = player(Dealer).Chips + player(i).Bet
cp i, 11, player(i).ID + " won!"
player(i).Chips = player(i).Chips + player(i).Bet
player(Dealer).Chips = player(Dealer).Chips - player(i).Bet
cp i, 11, player(i).ID + " won!"
player(i).Chips = player(i).Chips + 2 * player(i).Bet
player(Dealer).Chips = player(Dealer).Chips - 2 * player(i).Bet
IF player
(i
).Chips
= 0 THEN cp i
, 12, "Out of chips!" ELSE stillPlayer
= -1 cp 0, 12, "Goodbye"
SUB clearPlayers
'clear player data for new game player(i).Hand = ""
player(i).Ace = 0
player(i).Total = 0
player(i).Blackjack = 0
SUB addCard
(nPlayer
) 'add a card to reciever's hand and retotal points according to aces present deckIndex = deckIndex + 1
player(nPlayer).Hand = player(nPlayer).Hand + deck$(deckIndex)
IF deck$
(deckIndex
) = "A" THEN player
(nPlayer
).Ace
= -1 player(nPlayer).Total = 0
'IF INSTR(rank, MID$(player(nPlayer).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(player(nPlayer).Hand, i, 1))
player
(nPlayer
).Total
= player
(nPlayer
).Total
+ CardValue
(MID$(player
(nPlayer
).Hand
, i
, 1)) IF player
(nPlayer
).Total
< 12 AND player
(nPlayer
).Ace
THEN player
(nPlayer
).Total
= player
(nPlayer
).Total
+ 10
clsPlayer nPlayer
cp nPlayer, 1, player(nPlayer).ID
cp nPlayer
, 3, "Chips:" + STR$(player
(nPlayer
).Chips
) cp nPlayer
, 4, "Bet:" + STR$(player
(nPlayer
).Bet
) FOR i
= 1 TO LEN(player
(nPlayer
).Hand
) 'with 12 aces could get very long hands IF LEN(player
(nPlayer
).Hand
) * 2 < player
(nPlayer
).Win.W
THEN S$
= S$
+ MID$(player
(nPlayer
).Hand
, i
, 1) + " " S$
= S$
+ MID$(player
(nPlayer
).Hand
, i
, 1) cp nPlayer, 6, "___Hand___"
cp nPlayer, 7, S$
cp nPlayer
, 8, "Total:" + STR$(player
(nPlayer
).Total
) IF player
(nPlayer
).Total
> 21 THEN cp nPlayer, 9, "Busted!"
COLOR player
(nPlayer
).Win.FC
, player
(nPlayer
).Win.BC
lastR = player(nPlayer).Win.TopLeft.Y + player(nPlayer).Win.H - 1
lastR = player(nPlayer).Win.TopLeft.Y + player(nPlayer).Win.H
FOR i
= player
(nPlayer
).Win.TopLeft.Y
TO lastR
SUB cp
(nPlayer
, row
, s
AS STRING) 'center print a string on the given row COLOR player
(nPlayer
).Win.FC
, player
(nPlayer
).Win.BC
LOCATE player
(nPlayer
).Win.TopLeft.Y
+ row
, player
(nPlayer
).Win.TopLeft.X
+ (player
(nPlayer
).Win.W
- LEN(s
)) / 2:
PRINT s;
SUB initPlayers
'the stuff that never changes
'for printing in each players window area of screen = blackjack table
FOR i
= 1 TO nPlayers
- 1 player(i).Win.TopLeft.X = widt * (i - 1) + 2
player(i).Win.TopLeft.Y = height - 1
player(i).Win.W = widt - 2
player(i).Win.H = height - 1
player(i).Chips = 100
player
(Dealer
).Win.TopLeft.X
= (_WIDTH / 8 - widt
) / 2 + 1 player(Dealer).Win.TopLeft.Y = 1
player(Dealer).Win.W = widt
player(Dealer).Win.H = height - 2
player(Dealer).Chips = -400 'the dealer has "lent" 100 chips to each player
player(1).Win.FC = brown: player(1).Win.BC = orange: player(1).ID = "Pete": player(1).SetBet = 5: player(1).Bet = 5
player(2).Win.FC = drkRed: player(2).Win.BC = cyan: player(2).ID = "Qwerkey": player(2).SetBet = 15: player(2).Bet = 15
player(3).Win.FC = white: player(3).Win.BC = mRed: player(3).ID = "Johnno": player(3).SetBet = 0
player(4).Win.FC = ltCyan: player(4).Win.BC = blue: player(4).ID = "You"
player(5).Win.FC = yellow: player(5).Win.BC = green: player(5).ID = "Dealer"
'ask the user / YOU what e prefers for betting
cp 0, 8, "For this Blackjack Game, you start with 100 chips"
cp 0, 9, "and can bet any amount of them for each game."
cp 0, 10, "If you'd like to set your bet for each game now"
cp 0, 11, "enter that amount otherwise enter 0 and get asked"
cp 0, 12, "before each round at the table."
IF i
< 0 THEN i
= 0 'lets not do allot of checking and reasking player(You).SetBet = i
CardValue = 1
CardValue = 10