QB64.org Forum

Active Forums => Programs => Topic started by: bplus on June 07, 2019, 02:54:46 pm

Title: Blackjack
Post by: bplus on June 07, 2019, 02:54:46 pm
Simple game without card images and doesn't bother with suits. X is Roman for 10 when looking at the hands. Dealer wins all ties, except Blackjack for Player immediately pays double the bet.
Code: QB64: [Select]
  1. OPTION _EXPLICIT ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. DEFINT A-Z '       Player's Blackjack pays double the bet set at the beginning of the game
  3.  
  4. _TITLE "Blackjack Best B+ mod" ' started 2019-06-06
  5.  
  6. CONST rank$ = "A23456789XJQK"
  7. CONST player = 1
  8. CONST dealer = 2
  9.  
  10. TYPE playerType
  11.     ID AS STRING
  12.     Hand AS STRING
  13.     Ace AS INTEGER
  14.     Total AS INTEGER
  15. DIM SHARED deck$(1 TO 52), players(1 TO 2) AS playerType, deckIndex
  16.  
  17. DIM i, r, card$, chips, bet, setbet
  18. players(player).ID = "Player"
  19. players(dealer).ID = "Dealer"
  20. FOR i = 1 TO 52
  21.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  22. chips = 100
  23. cp 8, "For this Blackjack Game, you start with 100 chips"
  24. cp 9, "and can bet any amount of them for each game."
  25. cp 10, "If you'd like to set your bet for each game now"
  26. cp 11, "enter that amount otherwise enter 0 "
  27. LOCATE 12, 38: INPUT ""; setbet
  28.     IF setbet = 0 THEN
  29.         CLS
  30.         cp 10, "You have" + STR$(chips) + " chips to bet."
  31.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", bet
  32.         IF bet = 0 THEN EXIT DO
  33.         IF bet > chips THEN bet = chips
  34.     ELSE
  35.         bet = setbet
  36.     END IF
  37.     clearPlayers 'clears screen too
  38.     cp 4, "BLACKJACK    chips:" + STR$(chips) + "   betting:" + STR$(bet) + " chips."
  39.     FOR i = 52 TO 2 STEP -1 'shuffle
  40.         r = INT(RND * i) + 1
  41.         SWAP deck$(r), deck$(i)
  42.     NEXT
  43.     deckIndex = 0
  44.     FOR i = 1 TO 2 'each Player is dealt 2 cards
  45.         PlayerAddCard player
  46.         PlayerAddCard dealer
  47.     NEXT
  48.     cp 7, players(dealer).ID + " ? " + MID$(players(dealer).Hand, 2, 1)
  49.     cp 10, playerShow$(player)
  50.     IF players(player).Total = 21 THEN
  51.         chips = chips + 2 * bet
  52.         cp 11, "BlackJack! You added" + STR$(2 * bet) + " to your chips."
  53.         _DELAY 2
  54.         GOTO BJskip
  55.     END IF
  56.     WHILE players(player).Total < 21
  57.         cp 11, "Press h for Hit, any other to stay..."
  58.         card$ = INKEY$
  59.         WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND
  60.         IF card$ = "h" THEN
  61.             PlayerAddCard player
  62.             cp 11, SPACE$(50)
  63.             cp 10, playerShow$(player)
  64.         ELSE
  65.             cp 11, SPACE$(50)
  66.             EXIT WHILE
  67.         END IF
  68.     WEND
  69.     cp 7, playerShow$(dealer)
  70.     _DELAY 1
  71.     WHILE players(player).Total < 22 AND (players(dealer).Total < 21 AND players(dealer).Total < players(player).Total)
  72.         cp 8, "Dealer takes a card."
  73.         _DELAY 1
  74.         PlayerAddCard dealer
  75.         cp 7, playerShow$(dealer)
  76.         cp 8, SPACE$(50)
  77.         _DELAY 2
  78.     WEND
  79.     IF players(player).Total > 21 OR (players(player).Total <= players(dealer).Total AND players(dealer).Total < 22) THEN
  80.         cp 13, "You lose."
  81.         chips = chips - bet
  82.     ELSE
  83.         cp 13, "You win!"
  84.         chips = chips + bet
  85.     END IF
  86.     BJskip:
  87.     IF chips = 0 THEN cp 15, "Out of chips!"
  88.     _DELAY 4
  89. LOOP UNTIL chips = 0
  90. cp 17, "Goodbye"
  91.  
  92. SUB clearPlayers
  93.     DIM i
  94.     CLS
  95.     FOR i = 1 TO 2
  96.         players(i).Hand = ""
  97.         players(i).Ace = 0
  98.         players(i).Total = 0
  99.     NEXT
  100.  
  101. SUB PlayerAddCard (receiver)
  102.     DIM i AS INTEGER, cv AS INTEGER
  103.     deckIndex = deckIndex + 1
  104.     players(receiver).Hand = players(receiver).Hand + deck$(deckIndex)
  105.     IF deck$(deckIndex) = "A" THEN players(receiver).Ace = -1
  106.     players(receiver).Total = 0
  107.     FOR i = 1 TO LEN(players(receiver).Hand)
  108.         IF INSTR(rank, MID$(players(receiver).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(players(receiver).Hand, i, 1))
  109.         players(receiver).Total = players(receiver).Total + cv
  110.     NEXT
  111.     IF players(receiver).Total < 12 AND players(receiver).Ace THEN players(receiver).Total = players(receiver).Total + 10
  112.  
  113. FUNCTION playerShow$ (shower)
  114.     DIM i AS INTEGER, S$
  115.     S$ = players(shower).ID + " "
  116.     FOR i = 1 TO LEN(players(shower).Hand)
  117.         S$ = S$ + MID$(players(shower).Hand, i, 1) + " "
  118.     NEXT
  119.     S$ = S$ + "Total =" + STR$(players(shower).Total)
  120.     IF players(shower).Total > 21 THEN S$ = S$ + " Busted!"
  121.     playerShow$ = S$
  122.  
  123. SUB cp (row, s AS STRING)
  124.     LOCATE row, (80 - LEN(s)) / 2: PRINT s
  125.  

I am thinking of setting up a number of dummy players so Dealer wouldn't be looking to beat any one player in particular, ie it would have to stay more often than it does here, playing one-on-one.

Title: Re: Blackjack
Post by: johnno56 on June 07, 2019, 07:08:23 pm
Cut and paste into IDE. Run... Then this....

Title: Re: Blackjack
Post by: bplus on June 07, 2019, 07:57:09 pm
Hi Johnno,

Yeah time to update to QB64 v1.3 where Type allows variable length strings. :)

This version of Blackjack will save you bundles of money lost at casinos. ;D

Besides, you might have card images and noises for a real app. ;-))
Title: Re: Blackjack
Post by: johnno56 on June 07, 2019, 09:05:34 pm
Well spotted. I indeed was 'still' using version 1.2. New version installed. No more error. Many thanks.

J

ps: Your 'dealer' cleaned me out!! :(
Title: Re: Blackjack
Post by: bplus on June 07, 2019, 09:19:59 pm
Well spotted. I indeed was 'still' using version 1.2. New version installed. No more error. Many thanks.

J

ps: Your 'dealer' cleaned me out!! :(


Yeah! That's why I need to add more dummy players, so it has to "stay" more conservative, instead of drawing cards until it matches or beats or busts the only player it goes against.
Title: Re: Blackjack
Post by: Pete on June 07, 2019, 09:28:47 pm
One on my first programs after I graduated colors was Black Jack, played Las Vegas style, out of a shoe. Instead of a two player game, I made it an analysis program, to test different well documented playing strategies. I can credit that project with keeping out of casinos. In order to win anything of any significance, you have to make large bets, and play all day. You also literally cannot afford to make mistakes. You risk being banned for card counting if you actually do well, and, as one interesting book I read stated, "If you think people who built these casinos on drug money and prostitution wouldn't cheat you are cards, there is no helping you." All the casino has to do is take out a ace, pop in a couple of extra 5's or 2's, and you're totally screwed, no matter how well you play the system. I wish I could credit that program to QBasic, but at that time, I was using an Atari.

Pete
Title: Re: Blackjack
Post by: bplus on June 08, 2019, 10:09:47 am
Hi Pete,

You know, adding aces to the deck might make my little Blackjack game more interesting and be another way to overcome the dealer's advantage of winning ties. I would have to change the neat way to total a hand and create the deck but I am no longer interested in minimum lines of code.


Preliminary plans with dummy players:
The shoe in my game is only 1 deck and is shuffled before each round. I like the simplicity of that.

So I think 3 dummies plus me and dealer is ideal, just enough cards used that card counting might work, if you want to try a hand at that. Let the 3 dummies go first get a feel of cards played.

So far my dummy players have a choice of playing a set bet amount all the time or altering the bet. But what conditions could possible be used to alter the bet intelligently?

As I have been coding the game, all the betting occurs before any cards are shown. I know in real games after 2 cards dealt (dealer shows 1 face up), you can double down or split or buy insurance... however that goes, that too might make game more enjoyable against dealer and house rules.

Main rule at casinos: The Odds must be in favor of the house! Which is no fun!

My main rule: Have fun playing (and coding). Which means a probable chance of payoff for diligence and skill employed.

Well I guess I am just thinking out loud here... coding rarely ever goes as I had thought in preliminary plans.
But the aces idea with dummy players seem a good experiment.
Title: Re: Blackjack
Post by: bplus on June 09, 2019, 12:18:52 am
12 Aces and 4 bots including the dealer:
Code: QB64: [Select]
  1. OPTION _EXPLICIT '     No suits for cards A is Ace, J, Q, K are Jack, Queen, King, X is Roman for 10
  2. DEFINT A-Z '              Dealer wins all ties except a Player's Blackjack which pays double the bet
  3. _TITLE "Blackjack with Bots" ' started 2019-06-07 Players 1 through 3 are bots you play bottom right
  4.  
  5. TYPE XY 'graphic or cell location on screen or in array
  6.     X AS INTEGER
  7.     Y AS INTEGER
  8.  
  9. TYPE Box
  10.     TopLeft AS XY
  11.     W AS INTEGER
  12.     H AS INTEGER
  13.     BC AS _UNSIGNED LONG
  14.     FC AS _UNSIGNED LONG
  15.  
  16. TYPE PlayerType 'a container for all program data!
  17.     Win AS Box 'for screening the players data
  18.     ID AS STRING
  19.     Chips AS INTEGER
  20.     SetBet AS INTEGER
  21.     Bet AS INTEGER
  22.     Hand AS STRING
  23.     Ace AS INTEGER
  24.     Total AS INTEGER
  25.     Blackjack AS INTEGER
  26.  
  27. CONST xmax = 640
  28. CONST ymax = 432
  29. CONST nPlayers = 5 '       the 5th is the Dealer, the 4th is You and 1 - 3 are the bots who go first
  30. CONST You = 4
  31. CONST Dealer = 5
  32. CONST dk = "A2345A6789AXJQKA2345A6789AXJQKA2345A6789AXJQKA2345A6789AXJQK"
  33. CONST white = &HFFFDDFDD
  34. CONST black = &HFF000000
  35. CONST green = &HFF004515
  36. CONST orange = &HFFFF3300
  37. CONST brown = &HFF3C1D06
  38. CONST cyan = &HFF3774C0
  39. CONST ltCyan = &HFF99BBFF
  40. CONST drkRed = &HFF220102
  41. CONST mRed = &HFF7F0000
  42. CONST yellow = &HFFFFFF00
  43. CONST blue = &HFF00008D
  44.  
  45. DIM SHARED deck$(1 TO LEN(dk)), player(1 TO nPlayers) AS PlayerType, deckIndex
  46. DIM i, j, r, in, is$, stillPlayer
  47. SCREEN _NEWIMAGE(xmax, ymax, 32)
  48. COLOR yellow, green
  49. FOR i = 1 TO LEN(dk)
  50.     deck$(i) = MID$(dk, i, 1)
  51. initPlayers
  52.     clearPlayers 'clears screen too                                                    start a round
  53.     stillPlayer = 0 ' to check at end of round if there is still a player playing
  54.  
  55.     IF player(3).Chips > 0 THEN '                                                        handle bets
  56.         player(3).Bet = INT(player(3).Chips / 2 + .5)
  57.     END IF
  58.     IF player(You).Chips > 0 THEN
  59.         IF player(You).SetBet = 0 THEN
  60.             CLS
  61.             cp 0, 10, "You have" + STR$(player(4).Chips) + " chips to bet."
  62.             LOCATE 11, 25: INPUT "Enter your bet > ", in
  63.             IF in = 0 THEN EXIT DO
  64.             IF in > player(You).Chips THEN player(You).Bet = player(You).Chips ELSE player(You).Bet = in
  65.             CLS
  66.         ELSE
  67.             player(You).Bet = player(You).SetBet
  68.         END IF
  69.     END IF
  70.     FOR i = 1 TO 4 'make sure everyone is not betting more than amount of chips they have
  71.         IF player(i).Bet > player(i).Chips THEN player(i).Bet = player(i).Chips
  72.     NEXT
  73.  
  74.     FOR i = LEN(dk) TO 2 STEP -1 '                                                                shuffle
  75.         r = INT(RND * i) + 1
  76.         SWAP deck$(r), deck$(i)
  77.     NEXT
  78.     deckIndex = 0
  79.  
  80.     FOR j = 1 TO 2 '                                 everybody gets 2 cards if they still have chips
  81.         FOR i = 1 TO nPlayers 'each Player is dealt 2 cards
  82.             IF ((player(i).Chips > 0) AND (i <> Dealer)) OR (i = Dealer) THEN
  83.                 addCard i
  84.                 showPlayer i
  85.                 IF i = Dealer THEN
  86.                     cp Dealer, 7, SPACE$(18)
  87.                     cp Dealer, 8, SPACE$(18)
  88.                     IF j = 1 THEN
  89.                         cp Dealer, 7, "? "
  90.                         cp Dealer, 8, "Total: ?"
  91.                     ELSE
  92.                         cp Dealer, 7, SPACE$(18)
  93.                         cp Dealer, 7, "Hand: ? " + MID$(player(Dealer).Hand, 2, 1)
  94.                         cp Dealer, 8, "Total: ?"
  95.                     END IF
  96.                 END IF
  97.                 _DELAY 1
  98.                 IF i <> Dealer AND j = 2 AND player(i).Total = 21 THEN
  99.                     cp i, 9, "Blackjack!"
  100.                     player(i).Blackjack = -1
  101.                     _DELAY 1
  102.                 END IF
  103.             ELSE
  104.                 clsPlayer i
  105.             END IF
  106.         NEXT
  107.     NEXT
  108.  
  109.     FOR i = 1 TO nPlayers - 1 '                    OK now handle the players until they stay or bust
  110.         IF player(i).Chips > 0 THEN
  111.             WHILE player(i).Total < 21
  112.                 IF i = You THEN
  113.                     cp i, 11, "<h>it <s>tay"
  114.                     is$ = INKEY$
  115.                     WHILE LEN(is$) = 0: is$ = INKEY$: _LIMIT 60: WEND
  116.                     IF is$ = "h" THEN
  117.                         addCard You
  118.                         cp i, 11, SPACE$(18)
  119.                         showPlayer i
  120.                     ELSE
  121.                         cp i, 11, SPACE$(18)
  122.                         EXIT WHILE
  123.                     END IF
  124.                 ELSE
  125.                     IF player(i).Total < 16 THEN '                               bots to hit on < 16
  126.                         cp i, 11, "Hit me."
  127.                         _DELAY 1
  128.                         addCard i
  129.                         showPlayer i
  130.                         _DELAY 2
  131.                     ELSE
  132.                         EXIT WHILE 'stay
  133.                     END IF
  134.                 END IF
  135.             WEND
  136.         END IF
  137.     NEXT
  138.  
  139.     showPlayer Dealer '                                                                dealer's turn
  140.     _DELAY 1
  141.     WHILE player(Dealer).Total < 17
  142.         cp Dealer, 10, "(Takes a card)"
  143.         _DELAY 1
  144.         addCard Dealer
  145.         showPlayer Dealer
  146.         cp Dealer, 10, SPACE$(18)
  147.         _DELAY 2
  148.     WEND
  149.  
  150.     FOR i = 1 TO nPlayers - 1 '                                   name the winners and losers, payup
  151.         IF player(i).Chips > 0 THEN
  152.             IF player(i).Blackjack = 0 THEN
  153.                 IF player(i).Total > 21 OR (player(i).Total <= player(Dealer).Total AND player(Dealer).Total < 22) THEN
  154.                     cp i, 11, player(i).ID + " lost."
  155.                     player(i).Chips = player(i).Chips - player(i).Bet
  156.                     player(Dealer).Chips = player(Dealer).Chips + player(i).Bet
  157.                 ELSE
  158.                     cp i, 11, player(i).ID + " won!"
  159.                     player(i).Chips = player(i).Chips + player(i).Bet
  160.                     player(Dealer).Chips = player(Dealer).Chips - player(i).Bet
  161.                 END IF
  162.             ELSE
  163.                 cp i, 11, player(i).ID + " won!"
  164.                 player(i).Chips = player(i).Chips + 2 * player(i).Bet
  165.                 player(Dealer).Chips = player(Dealer).Chips - 2 * player(i).Bet
  166.             END IF
  167.             IF player(i).Chips = 0 THEN cp i, 12, "Out of chips!" ELSE stillPlayer = -1
  168.         END IF
  169.         _DELAY .5
  170.     NEXT
  171.     _DELAY 3
  172. LOOP UNTIL stillPlayer = 0
  173. cp 0, 12, "Goodbye"
  174.  
  175. SUB clearPlayers 'clear player data for new game
  176.     DIM i
  177.     CLS
  178.     FOR i = 1 TO nPlayers
  179.         player(i).Hand = ""
  180.         player(i).Ace = 0
  181.         player(i).Total = 0
  182.         player(i).Blackjack = 0
  183.     NEXT
  184.  
  185. SUB addCard (nPlayer) 'add a card to reciever's hand and retotal points according to aces present
  186.     DIM i AS INTEGER
  187.     deckIndex = deckIndex + 1
  188.     player(nPlayer).Hand = player(nPlayer).Hand + deck$(deckIndex)
  189.     IF deck$(deckIndex) = "A" THEN player(nPlayer).Ace = -1
  190.     player(nPlayer).Total = 0
  191.     FOR i = 1 TO LEN(player(nPlayer).Hand)
  192.         'IF INSTR(rank, MID$(player(nPlayer).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(player(nPlayer).Hand, i, 1))
  193.         player(nPlayer).Total = player(nPlayer).Total + CardValue(MID$(player(nPlayer).Hand, i, 1))
  194.     NEXT
  195.     IF player(nPlayer).Total < 12 AND player(nPlayer).Ace THEN player(nPlayer).Total = player(nPlayer).Total + 10
  196.  
  197. SUB showPlayer (nPlayer)
  198.     DIM i AS INTEGER, S$
  199.     clsPlayer nPlayer
  200.     cp nPlayer, 1, player(nPlayer).ID
  201.     cp nPlayer, 3, "Chips:" + STR$(player(nPlayer).Chips)
  202.     IF nPlayer <> Dealer THEN
  203.         cp nPlayer, 4, "Bet:" + STR$(player(nPlayer).Bet)
  204.     END IF
  205.     FOR i = 1 TO LEN(player(nPlayer).Hand) 'with 12 aces could get very long hands
  206.         IF LEN(player(nPlayer).Hand) * 2 < player(nPlayer).Win.W THEN
  207.             S$ = S$ + MID$(player(nPlayer).Hand, i, 1) + " "
  208.         ELSE
  209.             S$ = S$ + MID$(player(nPlayer).Hand, i, 1)
  210.         END IF
  211.     NEXT
  212.     cp nPlayer, 6, "___Hand___"
  213.     cp nPlayer, 7, S$
  214.     cp nPlayer, 8, "Total:" + STR$(player(nPlayer).Total)
  215.     IF player(nPlayer).Total > 21 THEN
  216.         cp nPlayer, 9, "Busted!"
  217.     END IF
  218.  
  219. SUB clsPlayer (nPlayer)
  220.     DIM i, lastR
  221.     COLOR player(nPlayer).Win.FC, player(nPlayer).Win.BC
  222.     IF nPlayer = Dealer THEN
  223.         lastR = player(nPlayer).Win.TopLeft.Y + player(nPlayer).Win.H - 1
  224.     ELSE
  225.         lastR = player(nPlayer).Win.TopLeft.Y + player(nPlayer).Win.H
  226.     END IF
  227.     FOR i = player(nPlayer).Win.TopLeft.Y TO lastR
  228.         LOCATE i, player(nPlayer).Win.TopLeft.X: PRINT SPACE$(player(nPlayer).Win.W);
  229.     NEXT
  230.     COLOR yellow, green
  231.  
  232. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  233.     IF nPlayer THEN
  234.         COLOR player(nPlayer).Win.FC, player(nPlayer).Win.BC
  235.         LOCATE player(nPlayer).Win.TopLeft.Y + row, player(nPlayer).Win.TopLeft.X + (player(nPlayer).Win.W - LEN(s)) / 2: PRINT s;
  236.         COLOR yellow, green
  237.     ELSE
  238.         COLOR yellow, green
  239.         LOCATE row, (80 - LEN(s)) / 2: PRINT s;
  240.     END IF
  241.  
  242. SUB initPlayers 'the stuff that never changes
  243.     DIM i, widt, height
  244.  
  245.     'for printing in each players window area of screen = blackjack table
  246.     widt = _WIDTH / (4 * 8)
  247.     height = _HEIGHT / (2 * 16)
  248.     FOR i = 1 TO nPlayers - 1
  249.         player(i).Win.TopLeft.X = widt * (i - 1) + 2
  250.         player(i).Win.TopLeft.Y = height - 1
  251.         player(i).Win.W = widt - 2
  252.         player(i).Win.H = height - 1
  253.         player(i).Chips = 100
  254.     NEXT
  255.     player(Dealer).Win.TopLeft.X = (_WIDTH / 8 - widt) / 2 + 1
  256.     player(Dealer).Win.TopLeft.Y = 1
  257.     player(Dealer).Win.W = widt
  258.     player(Dealer).Win.H = height - 2
  259.     player(Dealer).Chips = -400 'the dealer has "lent" 100 chips to each player
  260.  
  261.     player(1).Win.FC = brown: player(1).Win.BC = orange: player(1).ID = "Pete": player(1).SetBet = 5: player(1).Bet = 5
  262.     player(2).Win.FC = drkRed: player(2).Win.BC = cyan: player(2).ID = "Qwerkey": player(2).SetBet = 15: player(2).Bet = 15
  263.     player(3).Win.FC = white: player(3).Win.BC = mRed: player(3).ID = "Johnno": player(3).SetBet = 0
  264.     player(4).Win.FC = ltCyan: player(4).Win.BC = blue: player(4).ID = "You"
  265.     player(5).Win.FC = yellow: player(5).Win.BC = green: player(5).ID = "Dealer"
  266.  
  267.     'ask the user / YOU what e prefers for betting
  268.     CLS
  269.     cp 0, 8, "For this Blackjack Game, you start with 100 chips"
  270.     cp 0, 9, "and can bet any amount of them for each game."
  271.     cp 0, 10, "If you'd like to set your bet for each game now"
  272.     cp 0, 11, "enter that amount otherwise enter 0 and get asked"
  273.     cp 0, 12, "before each round at the table."
  274.     LOCATE 13, 38: INPUT ""; i
  275.     IF i < 0 THEN i = 0 'lets not do allot of checking and reasking
  276.     IF i > 100 THEN i = 100
  277.     player(You).SetBet = i
  278.  
  279. FUNCTION CardValue (s$)
  280.     IF s$ = "A" THEN
  281.         CardValue = 1
  282.     ELSEIF INSTR("23456789", s$) > 0 THEN
  283.         CardValue = VAL(s$)
  284.     ELSEIF INSTR("XJQK", s$) > 0 THEN
  285.         CardValue = 10
  286.     END IF
  287.  
Title: Re: Blackjack
Post by: QBExile on June 09, 2019, 05:17:25 am
Very nice program!
One spelling error i encountered is "You loose." should be "You lose."
Title: Re: Blackjack
Post by: bplus on June 09, 2019, 08:54:50 am
Very nice program!
One spelling error i encountered is "You loose." should be "You lose."

Oh, 'loose" was in first program... OK fixed, Thanks

A couple of things I like in second program is using Types within Types that creates a window for each player, and a perfect accounting system: Dealer's Total Chips + all the Player's Chips = 0 (and the Player's chips are always positive or 0).
Title: Re: Blackjack
Post by: bplus on June 10, 2019, 11:47:14 am
Thanks to [banned user] and his deck image png file, I have more visual representation of cards.

I also eased up on the House Rules st the Dealer only draws until the total > 16 PLUS this game allows more ties eg when both players bust or match totals.

Code: QB64: [Select]
  1. OPTION _EXPLICIT ' Easier House Rules: Dealer must draw if card total < 17.
  2. DEFINT A-Z '       Player's Blackjack pays double the bet set at the beginning of the game.
  3. RANDOMIZE TIMER '  If both Dealer and Player match totals or bust, it is a tie.
  4. _TITLE "BJ 1on1 wImages" ' started 2019-06-09 B+ thanks to [banned user] Card Image file.
  5. CONST xmax = 800, ymax = 640 '40 lines
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 300, 20
  8.  
  9. TYPE CardType
  10.     ID AS INTEGER
  11.     cname AS STRING
  12.     value AS INTEGER '1 to 13
  13.     suit AS INTEGER
  14.     points AS INTEGER '1 to 10
  15.  
  16. TYPE PlayerType
  17.     ID AS STRING
  18.     hand AS STRING
  19.     cardY AS INTEGER
  20.     Ace AS INTEGER
  21.     Total AS INTEGER
  22.  
  23. CONST player = 1
  24. CONST dealer = 2
  25.  
  26. DIM SHARED Deck(1 TO 52) AS CardType, Players(1 TO 2) AS PlayerType, deckIndex
  27. DIM SHARED CardDeck AS LONG, round
  28. Players(player).ID = "Player": Players(player).cardY = 420
  29. Players(dealer).ID = "Dealer": Players(dealer).cardY = 100
  30. DIM SHARED bet, chips
  31. DIM i, card$, setbet, loaded
  32.  
  33. loaded = loadCardImages
  34. IF loaded = 0 THEN PRINT "PlayingCards.png failed to load, bye!": END
  35.  
  36. initDeck
  37.  
  38. chips = 100
  39. cp 8, "For this Blackjack Game, you start with 100 chips"
  40. cp 9, "and can bet any amount of them for each game."
  41. cp 10, "If you'd like to set your bet for each game now"
  42. cp 11, "enter that amount otherwise enter 0 "
  43. cp 12, ""
  44. INPUT ""; setbet
  45.     IF setbet = 0 THEN
  46.         CLS
  47.         cp 10, "You have" + STR$(chips) + " chips to bet."
  48.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", bet
  49.         IF bet = 0 THEN EXIT DO
  50.         IF bet > chips THEN bet = chips
  51.     ELSE
  52.         bet = setbet
  53.     END IF
  54.     clearPlayers 'clears screen too
  55.     shuffle
  56.     deckIndex = 0
  57.     FOR i = 1 TO 2 'each Player is dealt 2 cards
  58.         PlayerAddCard player
  59.         PlayerAddCard dealer
  60.         round = round + 1
  61.     NEXT
  62.     'cp 7, Players(dealer).ID + " ? " + MID$(Players(dealer).hand, 2, 1)
  63.     playerShow dealer
  64.     playerShow player
  65.     IF Players(player).Total = 21 THEN
  66.         chips = chips + 2 * bet
  67.         cp 36, "BlackJack! You added" + STR$(2 * bet) + " to your chips."
  68.         _DELAY 2
  69.         GOTO BJskip
  70.     END IF
  71.     WHILE Players(player).Total < 21
  72.         cp 36, "Press h for Hit, any other to stay..."
  73.         card$ = INKEY$
  74.         WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND
  75.         IF card$ = "h" THEN
  76.             PlayerAddCard player
  77.             playerShow player
  78.         ELSE
  79.             cp 38, SPACE$(50)
  80.             EXIT WHILE
  81.         END IF
  82.     WEND
  83.     round = round + 1 'now round > 2 so first card won't be hidden
  84.     playerShow dealer
  85.     _DELAY 1
  86.     WHILE Players(dealer).Total < 17
  87.         cp 16, "Dealer takes a card."
  88.         _DELAY 1
  89.         PlayerAddCard dealer
  90.         playerShow dealer
  91.         _DELAY 2
  92.     WEND
  93.     IF (Players(player).Total > 21 AND Players(dealer).Total < 22) OR (Players(player).Total < Players(dealer).Total AND Players(dealer).Total < 22) THEN
  94.         cp 38, "You lost."
  95.         chips = chips - bet
  96.     ELSEIF (Players(player).Total > Players(dealer).Total AND Players(player).Total < 22) OR (Players(player).Total < 22 AND Players(dealer).Total > 21) THEN
  97.         cp 38, "You won!"
  98.         chips = chips + bet
  99.     ELSEIF (Players(player).Total = Players(dealer).Total) OR (Players(player).Total > 21 AND Players(dealer).Total > 21) THEN
  100.         cp 38, "We tied..."
  101.     END IF
  102.     BJskip:
  103.     IF chips = 0 THEN cp 40, "Out of chips!"
  104.     _DELAY 4
  105. LOOP UNTIL chips = 0
  106. cp 5, "Goodbye"
  107.  
  108. SUB clearPlayers
  109.     DIM i
  110.     CLS
  111.     FOR i = 1 TO 2
  112.         Players(i).hand = ""
  113.         Players(i).Ace = 0
  114.         Players(i).Total = 0
  115.     NEXT
  116.     round = 0
  117.  
  118. SUB PlayerAddCard (receiver)
  119.     DIM i, di
  120.     deckIndex = deckIndex + 1
  121.     Players(receiver).hand = Players(receiver).hand + d2$(deckIndex)
  122.     IF Deck(deckIndex).value = 1 THEN Players(receiver).Ace = -1
  123.     Players(receiver).Total = 0
  124.     FOR i = 1 TO LEN(Players(receiver).hand) STEP 2
  125.         di = VAL(MID$(Players(receiver).hand, i, 2))
  126.         Players(receiver).Total = Players(receiver).Total + Deck(di).points
  127.     NEXT
  128.     IF Players(receiver).Total < 12 AND Players(receiver).Ace THEN Players(receiver).Total = Players(receiver).Total + 10
  129.  
  130. FUNCTION d2$ (num) 'we have to store 1 or 2 digit numbers in a string to represent hand that is buch of card indexes
  131.     d2$ = LEFT$(_TRIM$(STR$(num)) + "  ", 2)
  132.  
  133. SUB playerShow (shower)
  134.     DIM i, xoff, di
  135.  
  136.     IF shower = dealer THEN
  137.         LINE (0, 0)-STEP(xmax, 319), &HFF000000, BF
  138.         cp 2, "B+ BLACKJACK: If Dealer total < 16 then must hit else stays."
  139.         cp 5, Players(shower).ID
  140.         cp 15, "Total =" + STR$(Players(shower).Total)
  141.         IF Players(shower).Total > 21 THEN cp 16, "Busted!"
  142.     ELSE
  143.         LINE (0, 320)-STEP(xmax, 320), &HFF000000, BF
  144.         cp 25, "Chips:" + STR$(chips) + "   Betting:" + STR$(bet) + " chips."
  145.         cp 23, Players(shower).ID
  146.         cp 35, "Total =" + STR$(Players(shower).Total)
  147.         IF Players(shower).Total > 21 THEN cp 36, "Busted!"
  148.     END IF
  149.     xoff = (xmax - 43 * LEN(Players(shower).hand)) / 2
  150.     FOR i = 1 TO LEN(Players(shower).hand) STEP 2
  151.         di = VAL(MID$(Players(shower).hand, i, 2))
  152.         showCardDI xoff, Players(shower).cardY, di
  153.         xoff = xoff + 86
  154.     NEXT
  155.     IF shower = dealer AND round <= 2 THEN 'hide first card
  156.         xoff = (xmax - 43 * LEN(Players(shower).hand)) / 2
  157.         ShowCard xoff, Players(dealer).cardY, 0, 4
  158.         cp 15, " Total = ?? "
  159.     END IF
  160.  
  161. SUB cp (row, s AS STRING)
  162.     LOCATE row, (xmax / 8 - LEN(s)) / 2: PRINT s;
  163.  
  164. SUB initDeck
  165.     DIM i, s, v
  166.     DIM suit$(3)
  167.     suit$(0) = "Hearts": suit$(1) = "Clubs": suit$(2) = "Diamonds": suit$(3) = "Spades"
  168.     DIM v$(1 TO 13)
  169.     v$(1) = "Ace": v$(11) = "Jack": v$(12) = "Queen": v$(13) = "King"
  170.     FOR i = 2 TO 10
  171.         v$(i) = _TRIM$(STR$(i))
  172.     NEXT
  173.     i = 0
  174.     FOR s = 0 TO 3
  175.         FOR v = 1 TO 13
  176.             i = i + 1
  177.             Deck(i).ID = i
  178.             Deck(i).cname = v$(v) + " of " + suit$(s)
  179.             Deck(i).value = v
  180.             Deck(i).suit = s
  181.             IF v < 11 THEN Deck(i).points = v ELSE Deck(i).points = 10
  182.         NEXT
  183.     NEXT
  184.  
  185. SUB shuffle
  186.     DIM i, r
  187.     FOR i = 52 TO 2 STEP -1
  188.         r = INT(i * RND) + 1
  189.         SWAP Deck(i), Deck(r)
  190.     NEXT
  191.  
  192. SUB showCardDI (x AS INTEGER, y AS INTEGER, deckI AS INTEGER)
  193.     ShowCard x, y, Deck(deckI).value - 1, Deck(deckI).suit
  194.  
  195. 'at scale = 2 need screen space of 76 x 100 for one card
  196. SUB ShowCard (ScrnX, ScrnY, imageCol, imageRow) 'screen x, y  h= horizontal  , v =vertical  image h, v
  197.     DIM ch, cv, scale
  198.     ch = 38 * imageCol + 1: cv = 51 * imageRow + 1: scale = 2 ' <  might want to change?
  199.     _PUTIMAGE (ScrnX, ScrnY)-STEP(38 * scale, 50 * scale), CardDeck, 0, (ch, cv)-(ch + 37, cv + 50)
  200.  
  201. FUNCTION loadCardImages%
  202.     CardDeck = _LOADIMAGE("PlayingCards.png")
  203.     IF CardDeck = -1 THEN EXIT FUNCTION
  204.     _SOURCE CardDeck
  205.     _CLEARCOLOR POINT(0, 0), CardDeck
  206.     _SOURCE 0
  207.     loadCardImages% = -1
  208.  
  209.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Blackjack
Post by: Pete on June 10, 2019, 04:10:40 pm
You owe me 500 chips. I like the ones with ruffles.

Any thoughts to add a way to change the betting amount?

Pete
Title: Re: Blackjack
Post by: bplus on June 10, 2019, 05:24:02 pm
You owe me 500 chips. I like the ones with ruffles.

Any thoughts to add a way to change the betting amount?

Pete

You can bet any amount up to the amount of chips you have each round by entering 0 or just enter on very first screen.
Quote
cp 8, "For this Blackjack Game, you start with 100 chips"
cp 9, "and can bet any amount of them for each game."
cp 10, "If you'd like to set your bet for each game now"
cp 11, "enter that amount otherwise enter 0 "

I am planning more options for the player at Hit or Stay time so if you've won so much money it's burning holes in your pocket you will have option to change the SetBet amount and maybe change your room to the Penthouse Suite.
Title: Re: Blackjack
Post by: johnno56 on June 10, 2019, 05:45:00 pm
Nicely done! But, not so much, the $600 your dealer took from me!!  lol
Title: Re: Blackjack
Post by: bplus on June 10, 2019, 05:59:40 pm
Nicely done! But, not so much, the $600 your dealer took from me!!  lol

See the bundle I am saving you by keeping you out of casinos! :-))
Title: Re: Blackjack
Post by: Pete on June 10, 2019, 08:32:29 pm
Don't forget about the option to "double-down."

Pecos Pete
Title: Re: Blackjack
Post by: xra7en on June 10, 2019, 09:29:51 pm
oops mis-post!
Title: Re: Blackjack
Post by: bplus on June 11, 2019, 11:40:36 pm
Added the Double Down Option and Overhauled the whole game:
Quote
' Fixes since BJ 1on1 wImages.bas 2019-06-09:
' + Fix label: Dealer must hit if es Total is < 17, not 16.
' + I added Double Down (DD) option, not just for Pete's sake.
' So for DD, I read BJ rules according to Hoyle, more fixes to those rules:
' + The 2nd card to Dealer is face down not first.
' + Blackjack pays 3:2 or 1.5 times bet, IF Dealer does not match = "push".
' + If player busts e loses immediately, no push if Dealer also busts.
' + After everyone gets 2 cards, Dealer looks to see if e has BJ, if so, shows it.
' + Splash Screen and introduction.
Title: Re: Blackjack
Post by: johnno56 on June 10, 2020, 10:07:51 pm
I know, I know... This thread is OLD... But I had an impulse to play BJ.

In doing so, I cheated and started with 1,000 chips... Of course, it didn't take me long to amass a decent score... One thing I did notice was that, when my score got over 30k+, my score would show as a negative amount. Would this be a limitation of QB? If so, is there a way to redefine the variable, 'chips'?

Another thing was, whenever I "Bust", the dealer continues and if it busts we "tie", and my bet is restored... Not sure if that is supposed to happen, but there you go...

J
Title: Re: Blackjack
Post by: bplus on June 10, 2020, 11:36:30 pm
Hi Johnno,

Dang, I was hoping you were going to tell me you applied some of your asset magic to the game.

Yeah, your score goes negative after 32,000+ because I was not very optimistic Typing the score using Integer instead of _INTEGER64 (look out Donald Trump). ;-))  Easy fix.

And I am generous with fake money er, ah, points, the house is not required to make a profit which is why you don't loose if the dealer busts also.

Think I will try the game again too. :)



Title: Re: Blackjack
Post by: johnno56 on June 11, 2020, 12:06:01 am
Actually, I was thinking about using more graphics.... but my knowledge of QB64's graphics commands is not very good and I am not 100% sure that I can do it... lol

I have been looking for a Basic blackjack program (not with line numbers and goto's...) that follow the basic rules of two handed BJ with play again option.... There seems to be plenty of examples in python, java, javascript etc. but I know only a little of python and nothing about the others, so conversion, for me at least, is out of reach...

I'm going to go through you example and see what I can do... but I can't promise anything...

I have copies of pseudo-code that may be able to help... I will compare them with your game and see what I can throw together... This will either be fun or a nightmare... I'll start with the 'fun' option... lol
Title: Re: Blackjack
Post by: bplus on June 11, 2020, 11:07:35 am
@johnno56

Well it would be great to work on a project again with you. I really like what we came up with on Battleship.

I would be glad to change rules around, up the points/money/chips stake at beginning of game, I call them chips in program and change so you can win more points/fake money/chips. It would be nice distraction from Gin Rummy which I am still stuck on.

Do you still want to loose if you go bust or wait and see if dealer busts as well = push or tie? (of course you can make your own version)

I hope you bulleted "Output EXE to Source File" under the Run menu in your new QB64 version. That would make loading and running assets a breeze if in same folder as the source .bas file.
 
Title: Re: Blackjack
Post by: johnno56 on June 12, 2020, 09:28:02 am
Hmm... Not overly concerned about which rules to include, change or delete... I prefer 'simple'... ('cos I find 'difficult' hard to do... lol).

Like: Player dealt two cards face up. Dealer One up. One down. If player busts, dealer wins, end of hand. Push is ok when there is a tie. The only 'problem' I see in waiting to see if the dealer busts as well, is that, if both bust then it's a 'tie' and this is an advantage to the player as there is no loss of chips. Game continues until Quit or broke. Oh. 'Chips' are fine by me...

I am working my way through your game because it's relatively easy to follow and I refuse to try and untangle "lined and goto-ed' prehistoric basic code... lol. Well, maybe not quite so easy to follow, but WAY easier than the old code....

I was thinking more along the lines of how Battleships was controlled. Basically by mouse. Click on various valued 'chip' images to place a bet. Click on 'hit' to deal an extra card; Click on 'Stay" to switch to dealer. As always, esc or 'exit', to end the game.

Possible extras: Intro screen; Menu to switch on/off stuff like ambient sound; Music; Highscores; Player name; Max bet... stuff like that...

The least I can do is to start sourcing assets... If I can't find public domain stuff I'll try to make it myself... lol  I think I made a card game table some time ago... It's either floating around on this site or an old drive somewhere... If I can find it, perhaps we can use it, or use as an example of how 'not' to make a table... lol

It's almost 2330 and I have to be up at 0500 to do our fortnightly produce market shopping... Time to hit the sack...
Title: Re: Blackjack
Post by: bplus on June 12, 2020, 10:04:25 am
Hmm... Not overly concerned about which rules to include, change or delete... I prefer 'simple'... ('cos I find 'difficult' hard to do... lol).

Yep! you bet, simple is easy to understand, usually logical and easy to remember. So it makes sense to choose simple over complex. If I have a philosophy, that might be it's core. Rule #1


Like: Player dealt two cards face up. Dealer One up. One down. If player busts, dealer wins, end of hand. Push is ok when there is a tie. The only 'problem' I see in waiting to see if the dealer busts as well, is that, if both bust then it's a 'tie' and this is an advantage to the player as there is no loss of chips. Game continues until Quit or broke. Oh. 'Chips' are fine by me...

OK, by Rule#1 AND everyone already knows this game as played:
 If player busts, dealer wins, end of hand.


I am working my way through your game because it's relatively easy to follow and I refuse to try and untangle "lined and goto-ed' prehistoric basic code... lol. Well, maybe not quite so easy to follow, but WAY easier than the old code....

I was thinking more along the lines of how Battleships was controlled. Basically by mouse. Click on various valued 'chip' images to place a bet. Click on 'hit' to deal an extra card; Click on 'Stay" to switch to dealer. As always, esc or 'exit', to end the game.

I have just the thing for that, developed in Gin Rummy Variation Series (though so far only posted one game and found it faulty) it is an extremely simple way to do a "Menu" of buttons customized to the exact situation you're at in the game. I will start rewrite of that along with higher stake, round over with player bust and I have new idea about setting up an account, so after first time you are staked, you are really in hole 1000... well details can be worked out later, point is you have an account and can borrow up to 1000, so every time you start game and log in... you get drift I think. Getting into banking, I can think of a number of bells and whistles for that! ;-))


Possible extras: Intro screen; Menu to switch on/off stuff like ambient sound; Music; Highscores; Player name; Max bet... stuff like that...

The least I can do is to start sourcing assets... If I can't find public domain stuff I'll try to make it myself... lol  I think I made a card game table some time ago... It's either floating around on this site or an old drive somewhere... If I can find it, perhaps we can use it, or use as an example of how 'not' to make a table... lol

...

Yeah! That's the asset magic I am talking about :) 
Oh, I think we should maintain a better credit list for sources of images or sounds.

Oh yeah, and change chips UDT Type to _INTEGER64 so we can go sky high with the points/fake money/chips.
That's quite a Punch List already Johnno! :)
Title: Re: Blackjack
Post by: johnno56 on June 12, 2020, 07:18:02 pm
hmm... I just hope that I am not punching above my weight class... lol

By the way... I found that "card table"... The smallbasic BJ program you converted to sdlbasic but I never got around to adding graphics...

This table... (I will redo it with proper chip values - 10,20,50,100,ALL)

Title: Re: Blackjack
Post by: bplus on June 12, 2020, 08:21:26 pm
Hi @johnno56

Almost done with very rudimentary bank, B+ Banking and Loan, a little rusty with filing and trying to rush it out.
The rest is ready and BTW it was already conceding round to dealer if player busts.

I just removed an entire bush and chopped it up into leave bags so I am ready to play :)

I am allowing unlimited bets, start thinking about graphics for that. Maybe stacking chips or something?
Title: Re: Blackjack
Post by: johnno56 on June 12, 2020, 09:11:17 pm
Did a search on opengameart.org and found a simple 'poker' set of graphics. The attached cards are about 130x200 (small set) large is about 530x830

The cards do not have to be used. The cards and chips came in seperate files. The cards (or something similar) to the ones you used could replace them.
I think yours would be better... They look more 'real' than the opengameart cards... lol

Small cards and chips...

Title: Re: Blackjack
Post by: bplus on June 13, 2020, 12:54:55 am
@johnno56

Oh sorry, I finally got the stupid files to work correctly but ran out of gas and crashed. I wanted to do something kinda of fun (for me anyway) before posting. Famous last words, it shouldn't take long now :-))

Yeah those cards are weird but chips look great and same with table. It would be cool if had like King of Diamonds with the Ace of Spades, something that shouts Black Jack! My splash screen too pixelated.

Probably will need button images for "Quit" or something similar like "Cash In Chips", "Stand" or Stay?, "Hit Me".

A funny or smart mouthed Dealer?

Eh, got to finish my banking...
Title: Re: Blackjack
Post by: johnno56 on June 13, 2020, 02:21:36 am
Ok. Re-created the original table using GIMP and have separated the image into layers. Added Blackjack cards to the centre  of the table and learning how to draw text to a circular path. Possible "Black" on the top path and "Jack" on the bottom path. Once done I'll post another image. This time, because of layers, will make future changes much easier...
Title: Re: Blackjack
Post by: bplus on June 13, 2020, 03:09:49 am
@johnno56

OK I think I have all the kinks out of new banking system for chip tracking between games.
You are charged interest if you owe but make interest if you are in the Black. The "Founder" who makes the original loan makes money on every thing except starting the loan.

At present the user log-in is super plain, just type your name, possibly want password and encryption in future.

Title: Re: Blackjack
Post by: bplus on June 13, 2020, 03:12:43 am
Man! so tired I am making mistakes, this was supposed to be a mod not a new post.
Title: Re: Blackjack
Post by: johnno56 on June 13, 2020, 03:52:32 am
As promised... Next mockup... If you need something changed, just ask...

Title: Re: Blackjack
Post by: bplus on June 13, 2020, 10:42:24 am
YES! and the "Powered by QB64" is nice touch.
Title: Re: Blackjack
Post by: OldMoses on June 13, 2020, 11:02:22 am
This is SO realistic, I always lose. I used to play Blackjack with a cousin and one of his friends. I lost more quarters to those guys... ;)
Title: Re: Blackjack
Post by: bplus on June 13, 2020, 11:10:18 am
This is SO realistic, I always lose. I used to play Blackjack with a cousin and one of his friends. I lost more quarters to those guys... ;)

Same here. The only time I stand a chance is if I vary bets, ie start increasing bets when my loosing streak has gone on long enough, maybe I can break even or get ahead a little.

That's why I got into the fake banking business with the code, to finance my gambling itch.

You wanna buy a Founder's share in the business? ;-))

While bplus the player is down -2314, the Founder has recovered his loan to bplus and is 349 ahead from bplus business.
Title: Re: Blackjack
Post by: bplus on June 13, 2020, 01:13:55 pm
As promised... Next mockup... If you need something changed, just ask...

Hi @johnno56

I am using the mockup as Splash screen what an improvement over last! And then I started using it's background color for the game (continuity) but it's an awfully yellow green. Is it possible to make it more "mintly" _RGB32(0, 51, 102) the color I had AKA &HFF003366. If so, while making change could you put the Black Jack on the right with the Ace on left underneath. If this is an official Blackjack table color (is there one?) then forget about changing color.

BTW were you thinking that mockup also as the table background for during the game?

And some more work in banking:
Title: Re: Blackjack
Post by: johnno56 on June 13, 2020, 06:56:38 pm
"Same here.", fascinating. You lost quaters to 'OldMoses's' cousin and friend as well? Small world...

Looking at 'table' images, the absence of a 'table edge', was glaringly obvious... I will try to recreate something closer to an actual table... Fingers crossed.

In regards to the colour... 'Minty' - reduce 'green' by 80% and reduce 'blue' by 60%. I am going to assume that 'minty' will be our 'official' colour. ie: solid colour, no gradient? If so, might I suggest, applying a 'felt-like' texture... Just to 'breakup' a single colour. By the way, https://www.shutterstock.com/search/blackjack+table, shows various styles and cloth colours. Mostly green, but we have the advantage, of using whatever colour you like... Solid, gradient or textured.

I will see if I can produce just the 'minty' textured cloth with and without border gradient... It's been a long time since I tackled textures... Sounds like fun!

In regards to a 'splash screen'... My artistic talents (for want of a better word) are far from useful when it comes to that kind of creativity. As I have stated before, "I like simple". So, the image I provided, was a mockup of the game-play table. But, if you want to use if for a 'splash screen', I have no problem with that.  If so, then perhaps adding some cards and or chips, might lend to a better 'look'?

"Black Jack on the right with the Ace on left underneath"... I'm not quite sure how to interpret this one... How are your pencil and paper skills? Perhaps a sketch of the layout might be helpful... If you are sketching, perhaps an image of what 'you' think the game-play table could look like... It will certainly help with eliminating the 'guessing' factor... In the meantime, I will work on a better 'splash' and a new table cloth... Being Sunday, here in Oz, it will be particularly heavily weighted with family time... Not sure how much I can get done today, but I will do my best to at least get something done...
Title: Re: Blackjack
Post by: bplus on June 13, 2020, 07:39:43 pm
Hi @johnno56

Sorry, I write code functionality of game, you should have free hand to dress it up how you see fit. Nice images from Google link, those greens seem to me less yellow but like I said, free hand with images, sounds, smart mouth Dealer... ;-))

Don't worry about this but here is how I pictured logo for Blackjack: Red Ace on Left Overlapped by Blackjack on Right on Minty Green (felt? textured, nice idea!) background:
 

This is splash screen from last 2019 version.

The reason for Minty Green is that White print shows up very well in foreground, also reminds me more of felt like pool table.
Title: Re: Blackjack
Post by: johnno56 on June 14, 2020, 02:40:21 am
Minty and Green direct from the Editor....

Let me know which colour you would prefer and I'll go with that one... but I might sneak in a layout of the 'other' colour... wink, wink...

note: rgb(0, 51,102) is more blue than green...



Title: Re: Blackjack
Post by: bplus on June 14, 2020, 01:01:24 pm
HI @johnno56

Yeah I was looking up "Mint Green" on Internet last night and what a range! many way too heavy on the blue side. When I was saying minty green, I was just meaning slightly more cool blue than bright yellow.

Then I checked out "Emerald Green", which mostly does not show too much yellow nor blue, that is what I am going for, I think if we have to find a name socially agreed upon it would be Emerald Green. That name all the more appealing to me personally because I do have some Irish blood; my Grandfather was from Ireland :)

So in your next 2 mockup's the "Minty" is way too blue but the "Green.png" is it: color, cards, card positioning and even felt texture. I was worried you'd think me too picky and find something else to do but you are so close to my imagined image. In a perfect actualization of my imagination, I would like to see all of the central heart of the Ace cleared of the Blackjack card (as my current Avatar has it), just saying ;-))

Yikes! all this just for splash screen? Oh, I am not sure about the marble border, but decorating with some cards and chips, stacks sounds like an idea.

Now about the table:

Just a green felt from splash screen is OK. Maybe you could layout a Blackjack table like the images in link? but don't see the need for all those card slots unless we can get a multi-player thing going here at forum.

I don't know how to code a multi-player game, maybe someone else here would like to offer help?

I had a question come up when viewing your Google link to Blackjack images of tables,
"Blackjack pays 3 to 2" Is exactly what the game is doing now.
"Dealer must stand on 17, draw on 16" also is what this game is doing now.

But "Insurance Pays 2 to 1", what is Insurance?

This game is currently offering Double Down which pays 2 to 1 of your original bet if you win but charges twice as much as original bet if you loose. With DD, you have the advantage of seeing your cards and altering your bet, but disadvantage of only getting one more card, period.

Guess I have some home work.

BTW this revival of Blackjack game has helped get me going with Gin Rummy; making slow but steady progress for all the cases of card sets to optimize a hand. :)



To all,

Can any Blackjack fans here explain the difference between Insurance and Double Down? @Pete was the one who requested Double Down option be added.

Try for multi-player thing going here at forum? I would need help coding some kind of On-line thing.

I offer Founder's shares in the B+ Banking and Load system ;-))
Title: Re: Blackjack
Post by: bplus on June 14, 2020, 01:50:45 pm
Oh looks like I hit Jackpot with first link to my query:
http://www.readybetgo.com/blackjack/rules/blackjack-decisions-918.html

Explains rules and strategies, might use as reference source eg rules lookup, and guide for coding and playing BJ.
(Will read over after lunch.)

Oh hey! Surrender option, I get so many 15's that I loose at, sounds interesting for another button option.
Title: Re: Blackjack
Post by: bplus on June 14, 2020, 03:02:26 pm
OK, Insurance has to do with case of seeing the Dealer has an Ace after e deals out the 1st first round of cards.

As I recall now, with this reminder, when I considered this option before, the card sharks advised against taking out Insurance, so I never offered it as an option in my version. Still like that reasoning of all that but if anyone whats to challenge that logic, I am all "pointy" ears ;-))

BTW the House only pays 2 to 1 on the Insurance Bet and the original bet is still lost if Dealer gets Blackjack, so the 2 to 1 win only counters the loss of your original bet and is lost if Dealer does not have BJ.

Update: Surrender is interesting Option to offer but:
1. Double Down is nice alternate after you are resigned to hopeless hand (after first 2 cards only).
2. A surrender button doesn't really fit screen as 5th option for play (after first 2 cards and DD is 4th option).
Title: Re: Blackjack
Post by: johnno56 on June 14, 2020, 06:42:09 pm
The point of "picky" did not enter into my thought processes. After all, the distance between us and the time differences, would tend to make progress seeming slower but never picky.

Display the central heart on the Ace, no problem, now where is that shrink button?... lol

"Yikes! all this just for splash screen?" - Yep. All this. You only get one chance to make a first impression... Believe it or not, I had been thinking of a better 'splash screen', more like the kind you see when you search for "Blackjack"... lol Oh. I agree about the "border"... Consider it gone... By the way... It was walnut... Marble would have been a little too 'showy'... lol

"Double Down" would explain the "D" on the chips... But some of them have "BB"... No idea what that means....

I played a "Scratch" version of Blackjack and part of the "sounds" were Dealer comments... like "Too bad", "Place your bets", "That's the way." etc... When you mentioned, 'Smart mouthed', what did you have in mind... Oh. Whatever the comments are, with they be audio, audio and text or speech bubbles? etc  Getting a bit to far ahead? lol

In regards to the table cloth design.... I'm ok with 'Emerald'... On some of the table images, shapes etc, placed on the cloth, were 'simple' shape that were slightly lighter than the cloth, Maybe a 'simpler' version of the 'cards' might be better. After all, we don't want the player (or the dealer) to confuse the actual cards with the cloth logo... lol  I will work on a more simplistic design and reserve the 'cards' for the splash screen. It may not work, but as they say (and it's never said who 'they' are...) 'a change is as good as a holiday".

Hmm... Surrender. I tend to agree with you on this one. Surrender is much like quit which is closely associated with exit... Exit was one of the 'buttons' was it not?... lol Oh. Button design... Did you have a particular 'shape' in mind or perhaps just have then as 'printed' images on the cloth? Either way works for me. Point-click-highlight (two states - on and off) or three states. Hover, on and off) ... oh, now who's getting picky... lol
Title: Re: Blackjack
Post by: bplus on June 14, 2020, 08:27:05 pm
Hi @johnno56

Ah yes, let's make a good first impression then!

Dealer speech could be audio but I expect that not so portable between Windows and Linux? I was thinking more like what you did in Battleship, just text to read, instructions as needed along with funny comments on the side, maybe we can tip the Dealer if we find em amusing enough :)

Could I have link to Scratch version? (assuming I can just run it without download and setup.)

RE: D, BB on chips,  I will look into chip designations.

Yeah for table I am thinking buttons will go across the middle (we might try a column of buttons on the right side? what do you think), how ever you want to design them but 200 pixels wide and 50 pixels high is what I am using for model. Maybe could do table clothes like the casino tables in that link = print the "Blackjack pays 3 to 2" and "Dealer must stand on 17, draw on 16" that's OK and draw box(es) for the bet(s) very near bottom of screen.

Stack Players chips on left, bet on right of cards? or above? or below? Oh looks like the bet goes in the boxes under the cards closer to player and some tables have a whole section further down towards player to store all the players chips. Ok maybe chips in the boxes for the bets but the players account will be a digital readout from B+ Banking and Loan :) readable only by the player for privacy and security reasons :)

Speaking of banking, I am still revising the code as original system worked with a single stake and when that was gone then game over but it's completely different now with banking system and continuous account updating.


Oh! Idea for shapes of buttons: diamonds, hearts, clubs, spades... hardly 200 x 50 though, maybe all 4 just touching  for an outline to one button, will that work? sure! ;-)) the order you wonder? heart club diamond spade overlap just enough to hold a line of print in the center of shape = 20 pixels, wait you have way better graphics for lettering!
Title: Re: Blackjack
Post by: bplus on June 14, 2020, 08:55:57 pm
@johnno56

Re: your link to Blackjack tables

Hey did you see the Blackjack sign in neon lights against a brick wall in the dark, that would be so cool!

And some of those tile patterns for tablecloth of hearts, diamonds, spades, clubs also cool though has to be dark and subtle not to distract for cards, buttons and text messages.
Title: Re: Blackjack
Post by: johnno56 on June 14, 2020, 09:13:49 pm
I thought you might have noticed those patterns.... already downloaded some images and attempted to 'tile' the images. I think they are actually images of real cloth. The angle of the image causes slight lighting and tiling irregularities. I may be able to do something with them but not sure...

No, I didn't notice the neon sign, but sounds neat, especially if it was flashing.... ;)

Here is the link to a version of ScratchJack.... https://scratch.mit.edu/projects/472525/

It's web based. Click on the little green flag (next to the red dot). Use the slider to place a bet. You know the rest... lol

Here is a 'minimal' cloth that isn't too distracting. Buttons can also be 'printed'. Easy enough to change the cloth colour. This is just a style concept.

Title: Re: Blackjack
Post by: bplus on June 14, 2020, 09:29:24 pm
@johnno56 nice!

OK I will move buttons to right side in mockup of game for that logo on tablecloth, that might give more w x h size for buttons as well. I was worried buttons across middle would mess up anything nice in middle of table cloth.

Here is an update on the game code. Delete the old B+ Banking and Loan.txt file if you have one started, everybody is starting at 0 instead of in the hole for 1000 stake to start. Just remember every bet while in the hole is a loan with interest paid the next time you play and positive balances earn interest. ;-))

Same asset files as in last zip:
Code: QB64: [Select]
  1. DEFINT A-Z
  2. _TITLE "Blackjack B+ Johnno v 2020-06" ' started 2019-06-11 B+ as: BJ 1on1 DD w Images.bas
  3. ' Thanks to [banned user] for Card Image file.
  4. ' Fixes since BJ 1on1 wImages.bas 2019-06-09:
  5. ' + Fix label: Dealer must hit if es Total is < 17, not 16.
  6. ' + I added Double Down (DD) option, not just for Pete's sake.
  7. ' So for DD, I read BJ rules according to Hoyle, more fixes to those rules:
  8. ' + The 2nd card to Dealer is face down not first.
  9. ' + Blackjack pays 3:2 or 1.5 times bet, IF Dealer does not match = "push".
  10. ' + If player busts e loses immediately, no push if Dealer also busts.
  11. ' + After everyone gets 2 cards, Dealer looks to see if e has BJ, if so, shows it.
  12. ' + Splash Screen and introduction.
  13.  
  14. 'BJ restart 2020-06-12 wow 1 year later w Johnno collaboration
  15. ' Punch List: from easy to hard
  16. ' + change chips type to _integer64 ;-)) done
  17. ' + larger stakes to start 1000 instead of 100 done
  18. ' + If player busts Dealer wins as everyone is familiar to this rule: this was done already!
  19. ' + Buttons controls like in Gin Rummy, OK done
  20. ' + Banking system charge interest on negative balances and pay interest on positive ones, sound fun? Done very basic
  21. ' + get done quickly so Johnno can work in assets, eh not so quick
  22. ' + fixed up new betting system that involves the bank file.
  23. ' 2020-06-13 post
  24.  
  25. 'BJ v2020-06-13
  26. ' + add Johnno's image for splash screen (or table background?)
  27. ' + charge/pay player interest as soon as sign in again, along with Founder update
  28.  
  29. 'BJ v2020-06-14
  30. ' + update acct at every change of chips count, so user cant cut all loses during session by X-out
  31. ' + start tracking dealer wins and losses too = wins and losses of house without Interest
  32. ' + Oh, oh, oh everybody starts at 0! so it's an automatic P&L statement
  33.  
  34.  
  35. CONST xmax = 900, ymax = 640, white = &HFFFFFFFF ' 40 lines
  36. CONST player = 1 ' at the table
  37. CONST dealer = 2
  38.  
  39. TYPE CardType
  40.     ID AS INTEGER
  41.     cname AS STRING
  42.     value AS INTEGER '1 to 13
  43.     suit AS INTEGER
  44.     points AS INTEGER '1 to 10
  45.  
  46. TYPE PlayerType
  47.     ID AS STRING '         for game player numbers
  48.     name AS STRING '       for tracking accts
  49.     chips AS _INTEGER64 '  current status of player's account
  50.     setbet AS _INTEGER64 ' what's this again? a preset bet for all bets so not constantly queried about a bet amount now has limit of 1000
  51.     bet AS _INTEGER64 '    cuurent round stakes
  52.     hand AS STRING '       the cards?
  53.     cardY AS INTEGER '     graphic Y position for cards
  54.     Ace AS INTEGER '       ace 1 or 11?
  55.     Total AS INTEGER '     cards total
  56.  
  57. DIM SHARED cardDeck AS LONG '                     image file handle
  58. DIM SHARED deck(1 TO 52) AS CardType, deckIndex ' deck and last card dealt
  59. DIM SHARED players(1 TO 2) AS PlayerType '        players
  60. DIM SHARED blockDealerCard '
  61.  
  62. SCREEN _NEWIMAGE(xmax, ymax, 32)
  63. _DELAY .25
  64.  
  65. players(player).ID = "Player": players(player).cardY = 420
  66. players(dealer).ID = "Dealer": players(dealer).cardY = 100
  67. players(dealer).name = "Dealer"
  68.  
  69. DIM i, choice, pick2$(0 TO 2), pick3$(0 TO 3) ' declare main variables
  70. pick2$(1) = "Hit": pick2$(2) = "Stand": pick2$(0) = "Quit"
  71. pick3$(1) = "Hit": pick3$(2) = "Stand": pick3$(3) = "Double Down": pick3$(0) = "Quit"
  72.  
  73. GetStarted 'sets bColor to Johnno splash screen backcolor
  74.     IF players(player).setbet = 0 THEN '                                     Get Bet (if not preset)
  75.         CLS
  76.         ShowAndTell 10, "You have " + _TRIM$(STR$(players(player).chips)) + " chips."
  77.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", players(player).bet
  78.         IF players(player).bet = 0 THEN 'quits
  79.             'updateBankAcct players(player).name, players(player).chips    should now be constantly updated
  80.             SYSTEM
  81.         ELSEIF players(player).bet > 1000 THEN 'you can bet up to half your chips
  82.             IF players(player).chips < 2000 THEN
  83.                 players(player).bet = 1000
  84.             ELSEIF players(player).bet > .5 * players(player).chips THEN 'half because player can Double Down
  85.                 players(player).bet = .5 * players(player).chips
  86.             END IF
  87.         END IF
  88.     ELSE 'using preset betting set at beginning of the game see GetStarted
  89.         players(player).bet = players(player).setbet
  90.     END IF
  91.  
  92.     ClearPlayers 'and screen
  93.     blockDealerCard = -1
  94.     FOR i = 1 TO 2 '                                                         2 Cards for Each Player
  95.         PlayerAddCard player
  96.         PlayerAddCard dealer
  97.     NEXT
  98.     blockDealerCard = 0
  99.     IF players(player).Total = 21 THEN '                                   Handle all the Blackjacks
  100.         ShowAndTell 36, "Blackjack!"
  101.     END IF
  102.     IF players(dealer).Total = 21 THEN '  Dealer BJ
  103.         PlayerShow (dealer)
  104.         ShowAndTell 16, "Dealer has Blackjack!"
  105.         IF players(player).Total <> 21 THEN
  106.             players(player).chips = players(player).chips - players(player).bet
  107.             players(dealer).chips = players(dealer).chips + players(player).bet
  108.             roundUpdate
  109.             ShowAndTell 38, "You lose" + STR$(players(player).bet)
  110.         ELSE
  111.             ShowAndTell 38, "Push, Dealer and Player have Blackjack."
  112.         END IF
  113.         _DELAY .5
  114.         GOTO skip
  115.     END IF
  116.     IF players(player).Total = 21 THEN ' Player BJ! pays 1.5 times bet
  117.         players(player).chips = players(player).chips + 1.5 * players(player).bet
  118.         players(dealer).chips = players(dealer).chips - 1.5 * players(player).bet
  119.         roundUpdate
  120.         ShowAndTell 38, "You win" + STR$(1.5 * players(player).bet)
  121.         GOTO skip
  122.     END IF
  123.     WHILE players(player).Total < 21 '                                                 Player's turn
  124.         IF LEN(players(player).hand) = 4 THEN
  125.             choice = getButtonNumberChoice%(pick3$())
  126.         ELSE
  127.             choice = getButtonNumberChoice%(pick2$())
  128.         END IF
  129.         IF choice = 1 THEN '                                                          Hit  Option
  130.             PlayerAddCard player
  131.             ShowAndTell 36, SPACE$(50)
  132.         ELSEIF choice = 3 AND LEN(players(player).hand) = 4 THEN '             Double Down Option
  133.             players(player).bet = 2 * players(player).bet
  134.             PlayerAddCard player
  135.             ShowAndTell 36, SPACE$(50)
  136.             EXIT WHILE
  137.         ELSEIF choice = 0 THEN '                                                              quit
  138.             'updateBankAcct players(player).name, players(player).chips  should be updated after each round
  139.             SYSTEM
  140.         ELSE 'stand                                                                           Stand
  141.             ShowAndTell 36, SPACE$(50)
  142.             EXIT WHILE
  143.         END IF
  144.     WEND
  145.     IF players(player).Total > 21 THEN '                                                Oops! busted
  146.         ShowAndTell 36, "Busted!"
  147.         ShowAndTell 38, "You lost" + STR$(players(player).bet)
  148.         players(player).chips = players(player).chips - players(player).bet
  149.         players(dealer).chips = players(dealer).chips + players(player).bet
  150.         roundUpdate
  151.         _DELAY 2
  152.         GOTO skip
  153.     END IF
  154.     PlayerShow dealer '                                                                Dealer's Turn
  155.     WHILE players(dealer).Total < 17
  156.         ShowAndTell 16, "Dealer takes a card."
  157.         _DELAY .5
  158.         PlayerAddCard dealer
  159.     WEND
  160.     IF players(dealer).Total > 21 THEN 'busted                                    Results Accounting
  161.         ShowAndTell 38, "You won" + STR$(players(player).bet)
  162.         players(player).chips = players(player).chips + players(player).bet
  163.         players(dealer).chips = players(dealer).chips - players(player).bet
  164.         roundUpdate
  165.     ELSEIF players(player).Total > players(dealer).Total THEN
  166.         ShowAndTell 38, "You won!"
  167.         players(player).chips = players(player).chips + players(player).bet
  168.         players(dealer).chips = players(dealer).chips - players(player).bet
  169.         roundUpdate
  170.     ELSEIF players(player).Total < players(dealer).Total THEN
  171.         ShowAndTell 38, "You lost" + STR$(players(player).bet)
  172.         players(player).chips = players(player).chips - players(player).bet
  173.         players(dealer).chips = players(dealer).chips + players(player).bet
  174.         roundUpdate
  175.     ELSEIF players(player).Total = players(dealer).Total THEN
  176.         ShowAndTell 38, "Push"
  177.     END IF
  178.     skip:
  179.     'IF players(player).chips = 0 THEN ShowAndTell 40, "Out of chips!"
  180.     _DELAY 4
  181. 'that's all folks the game ends when Player quits inside the main loop
  182.  
  183. SUB GetStarted
  184.     DIM splash&, name$, fline$, fname$, amount AS _INTEGER64, nFound, bankerFee AS _INTEGER64, Founder AS _INTEGER64
  185.     IF LoadCardImages = 0 THEN PRINT "PlayingCards.png failed to load, bye!": END
  186.     splash& = _LOADIMAGE("BJ Splash.png")
  187.     _PUTIMAGE , splash&, 0, (100, 100)-(_WIDTH(splash&) - 100, _HEIGHT(splash&) - 100)
  188.     bColor = POINT(40 * 8, 7 / 8 * _HEIGHT)
  189.     COLOR white, bColor
  190.     _DELAY 3
  191.  
  192.     'quick log in to get started with Bank  to be developed more later
  193.     IF _FILEEXISTS("B+ Banking and Loan.txt") = 0 THEN ' get a file started to track player acounts
  194.         OPEN "B+ Banking and Loan.txt" FOR APPEND AS #1
  195.         PRINT #1, "Founder$" + STR$(0)
  196.         PRINT #1, "Dealer$" + STR$(0)
  197.         CLOSE #1
  198.     END IF
  199.     LOCATE 7 / 8 * _HEIGHT \ 16, 40: INPUT "Please enter Player name "; name$
  200.     OPEN "B+ Banking and Loan.txt" FOR INPUT AS #1
  201.     WHILE EOF(1) = 0
  202.         LINE INPUT #1, fline$
  203.         PRINT fline$
  204.         fname$ = MID$(fline$, 1, INSTR(fline$, "$") - 1)
  205.         IF _TRIM$(fname$) <> "" THEN
  206.             IF fname$ = name$ THEN
  207.                 nFound = 1
  208.                 amount = VAL(MID$(fline$, INSTR(fline$, "$") + 1))
  209.                 IF amount < 0 THEN bankerFee = .1 * ABS(amount) ELSE bankerFee = .05 * amount 'interest made by banker
  210.                 IF amount < 0 THEN amount = 1.1 * amount ELSE amount = 1.05 * amount
  211.                 players(player).name = name$
  212.                 players(player).chips = amount
  213.             ELSEIF fname$ = "Founder" THEN
  214.                 Founder = VAL(MID$(fline$, INSTR(fline$, "$") + 1))
  215.             ELSEIF fname$ = "Dealer" THEN
  216.                 amount = VAL(MID$(fline$, INSTR(fline$, "$") + 1))
  217.                 players(dealer).chips = amount
  218.             END IF
  219.         END IF
  220.     WEND
  221.     CLOSE #1
  222.     IF nFound = 0 THEN
  223.         OPEN "B+ Banking and Loan.txt" FOR APPEND AS #1
  224.         PRINT #1, name$ + "$" + STR$(0) ' zero balance to start
  225.         players(player).name = name$
  226.         players(player).chips = 0
  227.         bankerFee = 0
  228.         CLOSE #1
  229.     END IF
  230.     updateBankAcct "Founder", Founder + bankerFee '              update banker's acct
  231.     updateBankAcct players(player).name, players(player).chips ' update player acct
  232.     CLS
  233.     InitDeck
  234.     IF nFound THEN
  235.         ShowAndTell 6, "Welcome back to B+J Blackjack, " + name$
  236.         ShowAndTell 8, "The banker informs us you have a balance of " + _TRIM$(STR$(players(player).chips))
  237.     ELSE
  238.         ShowAndTell 3, "Welcome to B+ and Johnno's Game of Blackjack, " + name$
  239.         ShowAndTell 5, "An account has been setup for you at B+ Banking and Loan."
  240.         ShowAndTell 6, "Terms are 10% interest payments for negative balance and"
  241.         ShowAndTell 7, "5% interest paid to you for positive balance."
  242.         ShowAndTell 8, "Thankyou for banking with B+."
  243.     END IF
  244.  
  245.     ShowAndTell 10, "The object of the game is to get to 21 or as close as possible without going over."
  246.     ShowAndTell 11, "You will need to get closer than dealer to win your bet (placed before cards are dealt)."
  247.     ShowAndTell 12, "An Ace counts as 1 or 11, points for 2-10 cards are 2-10, Jack, Queen, King are 10."
  248.  
  249.     ShowAndTell 14, "Some Blackjack Terms:"
  250.  
  251.     ShowAndTell 16, "Blackjack is getting a total of 21 with first 2 cards (an Ace and a 10 point card)."
  252.     ShowAndTell 17, "Blackjack pays 1.5 times the bet if the Dealer does not also have Blackjack."
  253.     ShowAndTell 18, "Hit is asking for another card."
  254.     ShowAndTell 19, "Stand is saying, no more cards."
  255.     ShowAndTell 20, "Double Down option occurs after 2nd card."
  256.     ShowAndTell 21, "Double Down is doubling your bet and getting just one more card."
  257.     ShowAndTell 22, "If 2 X Bet > Player's Chips, Bet will be Player's Chips."
  258.     ShowAndTell 23, "A Push is the same as a tie or a draw, no one loses."
  259.  
  260.     ShowAndTell 25, "For this Blackjack Game, you start by owing bank -1000 chips."
  261.     ShowAndTell 26, "If you owe you can bet up to 1000. If have more than 2000, you can bet half of"
  262.     ShowAndTell 27, " any positive amount you have."
  263.     ShowAndTell 29, "If you'd like to set your bet for each round now, enter that Amount (<=1000),"
  264.     ShowAndTell 30, "otherwise, to place your bet before each round, enter 0 now."
  265.  
  266.     ShowAndTell 32, ""
  267.     INPUT ""; players(player).setbet
  268.     IF players(player).setbet > 1000 THEN players(player).setbet = 1000
  269.  
  270. SUB roundUpdate
  271.     updateBankAcct players(dealer).name, players(dealer).chips
  272.     updateBankAcct players(player).name, players(player).chips
  273.  
  274.  
  275. SUB updateBankAcct (name$, amount AS _INTEGER64) ' store players chips back into bank
  276.     DIM accts(0) AS STRING, fline$, fname$, i
  277.     OPEN "B+ Banking and Loan.txt" FOR INPUT AS #1
  278.     WHILE NOT EOF(1)
  279.         LINE INPUT #1, fline$
  280.         fname$ = MID$(fline$, 1, INSTR(fline$, "$") - 1)
  281.         IF _TRIM$(fname$) = name$ THEN
  282.             loadSort name$ + "$" + STR$(amount), accts()
  283.         ELSE
  284.             loadSort fline$, accts()
  285.         END IF
  286.     WEND
  287.     CLOSE #1
  288.     OPEN "B+ Banking and Loan.txt" FOR OUTPUT AS #1
  289.     FOR i = 1 TO UBOUND(accts)
  290.         PRINT #1, accts(i)
  291.     NEXT
  292.     CLOSE #1
  293.  
  294. SUB ClearPlayers
  295.     DIM i
  296.     CLS
  297.     Shuffle
  298.     deckIndex = 0
  299.     FOR i = 1 TO 2
  300.         players(i).hand = ""
  301.         players(i).Ace = 0
  302.         players(i).Total = 0
  303.     NEXT
  304.  
  305. SUB PlayerAddCard (receiver)
  306.     DIM i, di
  307.     deckIndex = deckIndex + 1
  308.     players(receiver).hand = players(receiver).hand + D2$(deckIndex)
  309.     IF deck(deckIndex).value = 1 THEN players(receiver).Ace = -1
  310.     players(receiver).Total = 0
  311.     FOR i = 1 TO LEN(players(receiver).hand) STEP 2
  312.         di = VAL(MID$(players(receiver).hand, i, 2))
  313.         players(receiver).Total = players(receiver).Total + deck(di).points
  314.     NEXT
  315.     IF players(receiver).Total < 12 AND players(receiver).Ace THEN players(receiver).Total = players(receiver).Total + 10
  316.     PlayerShow receiver
  317.  
  318. FUNCTION D2$ (num) 'we have to store 1 or 2 digit numbers in a string to represent hand that is buch of card indexes
  319.     D2$ = LEFT$(_TRIM$(STR$(num)) + "  ", 2)
  320.  
  321. SUB PlayerShow (shower)
  322.     DIM i, xoff, di
  323.  
  324.     IF shower = dealer THEN
  325.         LINE (0, 0)-STEP(xmax, 319), bColor, BF
  326.         ShowAndTell 1, STR$(players(dealer).chips)
  327.         ShowAndTell 2, "BLACKJACK: Dealer must Hit if House Total < 17, Blackjack pays 3:2 unless Push"
  328.         ShowAndTell 5, players(shower).ID
  329.         ShowAndTell 15, "Total =" + STR$(players(shower).Total)
  330.         IF players(shower).Total > 21 THEN ShowAndTell 16, "Busted!"
  331.     ELSE
  332.         LINE (0, 320)-STEP(xmax, 320), bColor, BF
  333.         ShowAndTell 25, "Chips:" + STR$(players(player).chips) + "   Betting:" + STR$(players(player).bet) + " chips."
  334.         ShowAndTell 23, players(shower).ID
  335.         ShowAndTell 35, "Total =" + STR$(players(shower).Total)
  336.         IF players(shower).Total > 21 THEN ShowAndTell 36, "Busted!"
  337.     END IF
  338.     xoff = (xmax - 43 * LEN(players(shower).hand)) / 2
  339.     FOR i = 1 TO LEN(players(shower).hand) STEP 2
  340.         di = VAL(MID$(players(shower).hand, i, 2))
  341.         ShowCardDI xoff, players(shower).cardY, di
  342.         xoff = xoff + 86
  343.     NEXT
  344.     IF shower = dealer AND blockDealerCard AND LEN(players(dealer).hand) = 4 THEN 'hide first card
  345.         xoff = xoff - 86
  346.         ShowCard 2, xoff, players(dealer).cardY, 0, 4
  347.         ShowAndTell 15, " Total = ?? "
  348.     END IF
  349.     _DELAY 1.5
  350.  
  351. SUB ShowAndTell (row, s AS STRING)
  352.     LOCATE row, (xmax / 8 - LEN(s)) / 2: PRINT s;
  353.  
  354. SUB InitDeck
  355.     DIM i, s, v
  356.     DIM suit$(3)
  357.     suit$(0) = "Hearts": suit$(1) = "Clubs": suit$(2) = "Diamonds": suit$(3) = "Spades"
  358.     DIM v$(1 TO 13)
  359.     v$(1) = "Ace": v$(11) = "Jack": v$(12) = "Queen": v$(13) = "King"
  360.     FOR i = 2 TO 10
  361.         v$(i) = _TRIM$(STR$(i))
  362.     NEXT
  363.     i = 0
  364.     FOR s = 0 TO 3
  365.         FOR v = 1 TO 13
  366.             i = i + 1
  367.             deck(i).ID = i
  368.             deck(i).cname = v$(v) + " of " + suit$(s)
  369.             deck(i).value = v
  370.             deck(i).suit = s
  371.             IF v < 11 THEN deck(i).points = v ELSE deck(i).points = 10
  372.         NEXT
  373.     NEXT
  374.  
  375. SUB Shuffle
  376.     DIM i, r
  377.     FOR i = 52 TO 2 STEP -1
  378.         r = INT(i * RND) + 1
  379.         SWAP deck(i), deck(r)
  380.     NEXT
  381.  
  382. SUB ShowCardDI (x AS INTEGER, y AS INTEGER, deckI AS INTEGER)
  383.     ShowCard 2, x, y, deck(deckI).value - 1, deck(deckI).suit
  384.  
  385. 'at scale = 2 need screen space of 76 x 100 for one card
  386. SUB ShowCard (scale, ScrnX, ScrnY, imageCol, imageRow) 'screen x, y  h= horizontal  , v =vertical  image h, v
  387.     DIM ch, cv
  388.     ch = 38 * imageCol + 1: cv = 51 * imageRow + 1
  389.     _PUTIMAGE (ScrnX, ScrnY)-STEP(38 * scale, 50 * scale), cardDeck, 0, (ch, cv)-(ch + 37, cv + 50)
  390.  
  391. FUNCTION LoadCardImages%
  392.     cardDeck = _LOADIMAGE("PlayingCards.png")
  393.     IF cardDeck = -1 THEN EXIT FUNCTION
  394.     _SOURCE cardDeck
  395.     _CLEARCOLOR POINT(0, 0), cardDeck
  396.     _SOURCE 0
  397.     LoadCardImages% = -1
  398.  
  399.  
  400. 'this sub uses drwBtn  Const bColor for background
  401. FUNCTION getButtonNumberChoice% (choice$()) 'developed for this app but likely can use as is elsewhere
  402.     DIM ub, s1, b, oldmouse, mx, my, mb
  403.  
  404.     ub = UBOUND(choice$)
  405.     s1 = (_WIDTH - (ub + 1) * 200 - ub * 20) / 2
  406.     FOR b = 0 TO ub
  407.         drwBtn b * 220 + s1, 270, choice$(b)
  408.     NEXT
  409.     oldmouse = -1
  410.     DO
  411.         WHILE _MOUSEINPUT: WEND
  412.         mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  413.         IF mb AND oldmouse = 0 THEN
  414.             IF my >= 270 AND my <= 270 + 50 THEN
  415.                 FOR b = 0 TO ub
  416.                     IF mx > b * 220 + s1 AND mx <= b * 250 + s1 + 200 THEN
  417.                         LINE (0, 265)-(_WIDTH, 330), bColor, BF 'erase buttons
  418.                         getButtonNumberChoice% = b: EXIT FUNCTION
  419.                     END IF
  420.                 NEXT
  421.                 BEEP
  422.             ELSE
  423.                 BEEP
  424.             END IF
  425.         END IF
  426.         oldmouse = _MOUSEBUTTON(1)
  427.         _LIMIT 200
  428.     LOOP
  429.  
  430. SUB drwBtn (x, y, s$) '200 x 50   const white = &hffffffff and bColor
  431.     DIM th, tw, gray~&
  432.     th = 16: tw = 8 * LEN(s$): gray~& = _RGB32(190, 190, 190)
  433.     LINE (x, y)-STEP(204, 54), _RGB32(0, 0, 0), BF
  434.     LINE (x - 2, y - 2)-STEP(201, 51), _RGB32(255, 255, 255), BF
  435.     LINE (x, y)-STEP(200, 50), gray~&, BF
  436.     COLOR _RGB32(0, 0, 0), gray~&
  437.     _PRINTSTRING (x + 100 - 4 * LEN(s$), y + 17), s$
  438.     COLOR white, bColor
  439.  
  440. SUB loadSort (insertN AS STRING, dynArr() AS STRING) ' note this leaves dynArr(0) empty! so ubound of array is also number of items in list
  441.     DIM ub, j, k
  442.     ub = UBOUND(dynArr) + 1
  443.     REDIM _PRESERVE dynArr(LBOUND(dynArr) TO ub) AS STRING
  444.     FOR j = 1 TO ub - 1
  445.         IF insertN > dynArr(j) THEN '  GT to LT according to descending or ascending sort
  446.             FOR k = ub TO j + 1 STEP -1
  447.                 dynArr(k) = dynArr(k - 1)
  448.             NEXT
  449.             EXIT FOR
  450.         END IF
  451.     NEXT
  452.     dynArr(j) = insertN
  453.  
  454.  

Title: Re: Blackjack
Post by: johnno56 on June 14, 2020, 11:55:19 pm
The size of the cloth logo was made larger to demonstrate the style. It can be made the same size as the original logo (or any other size) to accommodate the layout of the cloth.... I will try to throw together a complete table... I hope... lol
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 02:08:34 am
Here is the minimal cloth only.

I have made buttons for all three states. On, Off and Hover.

Is this ok? I can add / subtract whatever you need...

In regards to sound: Ogg/Vorbis compresses a little more than MP3, but not sure about using on Windows. WAV files play on most but are usually larger in size than MP3's or OGG's. Midi - for a game like this - maybe not.... lol

The next step would be the sprites for chips (activated using 'BET' button).  The card "shu" in the Scratch game looked interesting. I ca try to simulate a minimal verion of that... Not sure how it will go... Might need some coding wizardry to make the cards slide and flip.... or just have them 'appear' on screen...

ps: I managed to tweak and tile the suit patterns into the cloth... ;)
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 07:14:11 am
@johnno56  Looking good!

Ogg files are fine with Windows and QB64.

With buttons built into table, don't have to worry about drawing them. But how to make Double Down option disappear when not available? A second table maybe without that button?
No lets draw them as needed (like Scratch Jack) as have been doing that way, we can stack them in as needed or across then bottom, will just show an image instead of drawing the button, can detect mouseover as well.

BTW a slide bar is fine for setting bet, I could draw it in as needed. We could also use an Input box for special (really high) bets. And I have a Message box for Text portion of instructions to player that Scratch's does with bubble.

Along with "BJ Pays 3 to 2"  also need "Dealer must stand on 17, draw on 16" (can be all on same line across).
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 08:02:40 am
All button images have three states. All buttons 'off' initially. When it come to DD being available, use the hover state, then 'on' when clicked. then 'off' when done... Oh, that sounds like a lot of code... Maybe your way will be better... lol

I couldn't remember the "Dealer" notice at the time of making the table.... Consider id done.

I used a "shutterstock" image as inspiration for a sample splash. I will make another that looks more traditional....

Title: Re: Blackjack
Post by: bplus on June 15, 2020, 09:14:02 am
Hi @johnno56

Yeah, I tried to work in green-minimal.png for background table for game and had to rework all messages and labels to try and fit cards and such off the center logo, didn't work too well and code is a mess BUT I will have to fix it to work with any table cloth you come up with for the background, so I will practice with mockup6.

Buttons and slider bars, I think will work better on top of the background table.

Do you have new set of cards in works or plans?

Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 10:06:11 am
I can make the table cloth colour as dark or as light as you need. What are you basic colours for the buttons? Are they like the grey buttons you used in an earlier version? If your buttons are images, send them, and I will try to match. If you are using primitives, may I suggest using black and white for contrast and aligning the buttons, then select a colour(s) when the beastie is working?

So, rather than the 'printed' buttons, you are leaning towards 'normal' buttons, for the table?

I will attach a 'button-less' copy of the table cloth (mockup6b).

Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 10:11:21 am
By the way... I have setup the table cloth in layers. The cloth pattern has had a 50% transparency applied to it. So to either lighten or darken it, all I have to do, is place a solid colour layer 'under' the cloth. Easy as. So, if you need it changed, just ask... ;)
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 10:56:57 am
@johnno56

Mockup6 is working fine!, don't change as I am recoding program layout for it. We might not need x in top right, the window already has it and looks redundant. We can allow esc key as alternative. And I am drawing buttons over the place you have them on table cloth for when you have button graphic ready the mouse will find the same places.

Also if you have new cards, higher definition?, than current, OK to make them a little bigger too

Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 11:58:36 am
I was going to ask you what size cards did you need. I have 2 sizes of the same deck: 500x726 and 209x303.

They are all individual. I can put them is a grid the same as your current deck. I can also resize the cards to whatever dimensions you need.

 
Title: Re: Blackjack
Post by: Dav on June 15, 2020, 12:06:49 pm
THese may be lower quality than you want, but I'd thought id offer it if you would like it.  I used this card set for an iPad game I made in smartbasic.

www.qbasicnews.com/dav/files/cards.png (http://www.qbasicnews.com/dav/files/cards.png)

- Dav
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 12:09:54 pm
Thanks, Dav. Much appreciated.
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 12:43:58 pm
Ah Dav's cards look better than what I am using now, thanks @Dav

Yes they worked without allot of difficulty. Using them scaled up to 1.35 X's
Title: Re: Blackjack
Post by: SierraKen on June 15, 2020, 01:29:51 pm
This is a really great game bplus and Johnno! I'm impressed at the graphics and the game play. Last year I posted my old 1990's game of 21 here on the forum but nobody replied to it. With the game 21 you don't bet so it's just whoever gets to 21 or closest wins. The graphics are simple ASCII stuff. I first made it in QBasic and then made it in ASIC 5.0 (which was like GW-Basic but had a tiny compiler). So last year I made it work with QB64 if any of you want to try it? I'm not trying to compete with yours though of course. Just wanted you all to see what I did too. You can see the post here:


https://www.qb64.org/forum/index.php?topic=1500.msg106998#msg106998
 (https://www.qb64.org/forum/index.php?topic=1500.msg106998#msg106998)
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 01:58:45 pm
This is a really great game bplus and Johnno! I'm impressed at the graphics and the game play. Last year I posted my old 1990's game of 21 here on the forum but nobody replied to it. With the game 21 you don't bet so it's just whoever gets to 21 or closest wins. The graphics are simple ASCII stuff. I first made it in QBasic and then made it in ASIC 5.0 (which was like GW-Basic but had a tiny compiler). So last year I made it work with QB64 if any of you want to try it? I'm not trying to compete with yours though of course. Just wanted you all to see what I did too. You can see the post here:


https://www.qb64.org/forum/index.php?topic=1500.msg106998#msg106998
 (https://www.qb64.org/forum/index.php?topic=1500.msg106998#msg106998)

Thanks Ken,

Very odd! The forum search engine is not locating any old Blackjack games, yours Ken and mine, well no, I guess mine is listed first from yesterday. Oh! you call yours 21 OK :)

The first post in this thread was about a month before yours, Ken, in 2019.

qbguy had one a year before ours: https://www.qb64.org/forum/index.php?topic=678.msg5477#msg5477
no reply to that one either, pretty short game.

And in Discussion someone had brought in old spaghetti code.

I almost have an update with the new png's and new layout for Johnno's Table mockup6.png. One little snag to go.
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 02:12:51 pm
OK the snag wasn't a snag, just rounding to 0 which is OK for Founder ;-))

Here is all new working code with all new .png's:

I might play around with the chip images for setting bets, right now that screen is very rudimentary.

Update: attachment removed see latest version later in this thread
Title: Re: Blackjack
Post by: SierraKen on June 15, 2020, 03:43:09 pm
Ohh wow OK thanks bplus, I had no idea. Oh well.
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 06:38:54 pm
Bplus,

As long as you have not made physical changes to the tablecloth, just replace the cloth with the 'button-less' cloth I posted yesterday, then the 'cloth buttons' will not be seen.

It's not even 9am and I came up with a solution, minor though it be, but a solution none the less... 'without' coffee!!  What could have happened if I 'did' have coffee... I can feel an experiment coming on...

ps: I see you have added a slash screen... It looks familiar... lol  Started working on a more 'traditional' splash. Not sure how 'that' one will turn out or how long it will take. I am experimenting with a couple of my many  little used methods, creativity and imagination.... Yeah. Surprised 'me' as well... By the way... Stop laughing... lol
Title: Re: Blackjack
Post by: bplus on June 15, 2020, 06:50:18 pm
Bplus,

As long as you have not made physical changes to the tablecloth, just replace the cloth with the 'button-less' cloth I posted yesterday, then the 'cloth buttons' will not be seen.

@johnno56  Oh those are just hand-draw placeholders until we have the button images I think you said you were working on 3 types: plain, mouse over, and activated (pressed) was it? I was using the hand-drawn buttons to get mouse alignments and to test the rest of game and alignments. Maybe the plain was the table cloth button itself?
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 06:53:37 pm
Ah you posted whilst I was typing... I will bundle the buttons and post them...

Done...

Title: Re: Blackjack
Post by: bplus on June 15, 2020, 07:00:46 pm
Most excellent, I was wondering what I would do tonight :-))

Hey, I just noticed, the instructions in the open screens have not been updated. Nobody starts in the hole -1000, just that every bet is a loan when your balance is less than 0 and it is only official when end the session in the hole.
Title: Re: Blackjack
Post by: johnno56 on June 15, 2020, 08:13:25 pm
I hope that they work out for you.

Have you decided on the dimensions of the playing cards? No rush. I figured that, that task, might give 'me' something to do tonight... lol

New splash: No. It's not ready yet... lol  I'm thinking of 'old school black mirror'.
I made a small stack of chips, using opengamart's free sprites, then added a reflection... The size is for the demo... It looks a lot better in my head... lol

Title: Re: Blackjack
Post by: bplus on June 15, 2020, 09:43:30 pm
Hi @johnno56

Sorry those buttons are not going to work. I need opaque ones to cover the ones on the cloth, just 3 for Hit, Stay and Double Down, oh and a blank for the bet slot to write numbers on and to use when Double Down is not available.

I tried to align the buttons over the cloth ones but they are blurry and smeared because the cloth is fit over different screen dimensions than it's png image, such that if perfectly aligned on left then way off by the time you reach the right side, same with top to bottom.

I don't want to use the plain cloth because that logo is too big and 2nd cloth pattern is cool!

So I can stay with hand drawn ones unless you have better idea. I am thinking doing screen updates while showing and clearing mouse over of buttons wont be fun either. It's pretty clear to me when a mouse is over a button so don't really need that. I could try different colored hand drawn buttons with better font.

If you want to try a cloth without the buttons just logo and tile pattern that would be great because it would get rid of the redundant X box at the top right otherwise we could find some other image to cover it.

The bet slot is going to hold the amount of the bet so it is more a label that will need numbers than a button.

Title: Re: Blackjack
Post by: bplus on June 15, 2020, 11:25:58 pm
@johnno56

Listening to Episode 2 Podcast, they discussed idea of layering screens over main screen, this might work with mouse over or button press image altering... so don't have to redraw main screen with cards and messages already current, cool! So a new cloth without buttons can be worked with mouse over and button press, I think.
Title: Re: Blackjack
Post by: johnno56 on June 16, 2020, 01:42:15 am
Here are your opaque buttons....

Title: Re: Blackjack
Post by: SMcNeill on June 16, 2020, 02:21:13 am
@johnno56

Listening to Episode 2 Podcast, they discussed idea of layering screens over main screen, this might work with mouse over or button press image altering... so don't have to redraw main screen with cards and messages already current, cool! So a new cloth without buttons can be worked with mouse over and button press, I think.

Sounds like you guys need a little help in saving and restoring backgrounds.  See if this very simple demo will highlight a *very* easy way to handle things for you:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3. 'Draw some background
  4. FOR i = 1 TO 2000
  5.     out$ = out$ + "Hello World "
  6. FOR i = 0 TO 480 STEP 16
  7.     _PRINTSTRING (0, i), MID$(out$, i)
  8. SLEEP 'A sleep statement so we can see our undisturbed background
  9.  
  10. SBG = SaveBackground(100, 100, 300, 200) 'Saved BackGround from (100,100)-(300,200), which is where I'm going to put my "button"
  11.  
  12.     k = _KEYHIT
  13.     SELECT CASE k
  14.         CASE 32 'space
  15.             toggle = NOT toggle
  16.             IF toggle THEN
  17.                 LINE (100, 100)-(300, 200), DarkGray, BF
  18.                 _PRINTSTRING (170, 140), "BUTTON!"
  19.             ELSE
  20.                 RestoreBackground SBG, 100, 100
  21.             END IF
  22.         CASE 27 'esc
  23.             SYSTEM
  24.     END SELECT
  25.     _LIMIT 30
  26.  
  27. FUNCTION SaveBackground (x1, y1, x2, y2)
  28.     SaveBackground = _NEWIMAGE(x2 - x1 + 1, y2 - y1 + 1, 32)
  29.     _PUTIMAGE , 0, SaveBackground, (x1, y1)-(x2, y2)
  30.  
  31. SUB RestoreBackground (Background, x1, y1)
  32.     _PUTIMAGE (x1, y1), Background
  33.  
  34.  

Use the spacebar to toggle the button.  :)

For your needs, just save the background where the buttons will appear, and then you can restore/overwrite them as needed easily enough. 
Title: Re: Blackjack
Post by: bplus on June 16, 2020, 12:11:16 pm
Thanks Steve, looks like we don't have to save a whole screen sized image with button in just the right place and just lay it over current screen. I will check out.

Update: Looks good for my tool box too! Thanks again!
Title: Re: Blackjack
Post by: bplus on June 16, 2020, 12:36:33 pm
@johnno56

Wow! buttons with cloth background that will be interesting to see!

Well with Steve's help and new buttons I have some homework.

Can't wait to see how the buttons work out :) Thanks for quick reply.

@SMcNeill

Update: Oh wait, I think I can just _putimage the button image at x, y location on screen. The problem was that the buttons were transparent and the cloth already had different sized button images embedded in it's image.

If the material did not have a pattern, I could patch over the button areas with clear section but likely to be a chore to patch over and match a pattern cloth perfectly.

So either needed new cloth without embedded buttons or over sized opaque buttons to paste over embedded buttons.
Title: Re: Blackjack
Post by: SMcNeill on June 16, 2020, 03:18:26 pm
Thanks Steve, looks like we don't have to save a whole screen sized image with button in just the right place and just lay it over current screen. I will check out.

Update: Looks good for my tool box too! Thanks again!

And here's another option you may not have considered -- make the button a hardware image.  Then, you're guaranteed that your button won't affect the main image, because it'll be rendered on a separate layer completely.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3. 'Draw some background
  4. FOR i = 1 TO 2000
  5.     OUT$ = OUT$ + "Hello World "
  6. FOR i = 0 TO 480 STEP 16
  7.     _PRINTSTRING (0, i), MID$(OUT$, i)
  8. SLEEP 'A sleep statement so we can see our undisturbed background
  9.  
  10. temp = _NEWIMAGE(200, 100, 32)
  11. _DEST temp 'sw
  12. CLS , DarkGray 'color the button
  13. _PRINTSTRING (70, 40), "BUTTON!" 'Add a highlight to the button
  14. SBGHW = _COPYIMAGE(temp, 33) 'Make that saved button a hardware image
  15. _FREEIMAGE temp 'Free the original software image
  16.  
  17.  
  18.     k = _KEYHIT
  19.     SELECT CASE k
  20.         CASE 32 'space
  21.             toggle = NOT toggle
  22.         CASE 27 'esc
  23.             SYSTEM
  24.     END SELECT
  25.     IF toggle THEN _PUTIMAGE (100, 100), SBGHW 'Now overlay the button over the original image on the screen, using the hardware image
  26.     _DISPLAY 'Display is needed so that the hardware image will render
  27.     _LIMIT 30
  28.  
Title: Re: Blackjack
Post by: bplus on June 16, 2020, 05:38:27 pm
Thanks Steve, I am interested in hardware images I will check that out.

Here is the current state of affairs with Johnno's new opaque buttons and some other minor changes:
 


And zip package: see next post
Title: Re: Blackjack
Post by: bplus on June 17, 2020, 12:35:55 am
Added fonts, revised an INPUT function for fonts looks better with larger Arial Fonts.
 


Yes and it was an Ace of hearts too! Should pay more than 1.5 X's the bet for that ;)

@johnno56  why does the first line in Table look cut off right at the top?

The much improved B+J Blackjack Game package .zip file is now here:
https://www.qb64.org/forum/index.php?topic=1406.msg119406#msg119406
Title: Re: Blackjack
Post by: johnno56 on June 17, 2020, 03:43:21 am
The display looks much better. The font I used was Sans Bold size 24 for 'yellow' and button text. Size 40 for 'blackjack' and size 18 for 'powered'.

As to the 'clipping' of the yellow text... The original mockup6 image is ok. Cannot explain that one... The yellow text is 'part' of cloth image itself. Most puzzling.

Just a minor cloth layout 'niggle'. The playing cards do not seem to have much "room" to spare between the text. Without changing the actual size of the cards, I think the easiest solution would be, to move the text of the "logo" closer to the logo itself... Then all you have to tweak in the program are the coordinates at which the cards are displayed. I hope I explained that well enough? It's easier for me to change the cloth than for you to modify the cards and coordinates...
Title: Re: Blackjack
Post by: johnno56 on June 17, 2020, 04:40:59 am
This is a modified cloth (mockup7). The logo text have been moved closer to the logo. Should give you some 'breathing space" for your cards. As I mentioned earlier, the card coord's will need to be tweaked... Let me know how you went with this version...

Title: Re: Blackjack
Post by: bplus on June 17, 2020, 02:06:13 pm
Hi @johnno56

First off I will assume and hope everything is working OK in Linux with this latest version(?).

Issue Screen / Table cloth sizing:
About the mystery cut-off of text, I have a theory. It might be happening because the absolute highest screen that I can show everything from title bar down to bottom of screen is 740 pixels with my laptop. So if I _PUTIMAGE your cloth to my screen setup there is some shrinking for the full fit (which is what threw the button images blurry) and that shrinking probably effected the print on the table cloth.

For maximum portable screen size, Terry discovered and Fellippe confirms is 1024 for width for best results and I need a max 740 pixels for height but 640 or 680?? might be more standard height for maximum porting.

So a table cloth to those dimensions we can show pixel for pixel without stretching or shrinking.

To all, I wonder if anyone else has an idea for this? What is maximum portable screen height? before I ask Johnno for another table cloth.


Issue: Table cloth Logo
Being centrally located, it is hogging allot of room that might be better spent showing cards. Also showing "BLACKJACK" directly below the Dealers cards is a bit disorienting.

Johnno what do you think about moving it to Top Left Corner and then next to it we write those 2 Yellow Texts, centered, and then have room on the right for additional buttons should an occasion arise.

OR

Move the text there now above and below ("BLACKJACK" and "Powered by QB64" to left or right or both, keeping Logo in center as that does make a natural divide between Dealer section and Player section but it wouldn't be as tall as it is now so we can show bigger cards.

BTW the "Tip Dealer" dummy button was put there as joke and to cover the X button that we really don't need.

Issue: Buttons and writing
Yes a Table Cloth with just Logo would require only one single Blank button Image with transparent background (maybe some more blank sizes to try out).

Everything else can be written in and colored with nice fonts and transparent overlay boxes and the table cloth pattern underneath will show through without having to match opaque buttons perfectly.

If you want your fonts used just give me a ttf copy, I can draw in the text per your directions or approval.

For bigger cards, which I would love to do, I would need higher definition cards Dav's linked card set are already pixelating at 1.3 magnification, those were 72 X 96 multiplied by 1.3 is about 94 X 125 used in current version.

Issue: Extra dimension audio
Yes indeed that Scratch version is greatly enhanced by the audio both of crowd and the Dealer speech. Can you do that? That would be amazing!

Issue Splash screen:
The one in there now is just a mockup place holder I think, or is that made by you Johnno or Public Domain or you have permission or should you or I get busy cloning a graphic?

Finally, how about a B+J Blackjack that pays X's 9 your Bet if you get exactly an Ace of Hearts and a Jack of Spades in that order?



Title: Re: Blackjack
Post by: Dav on June 17, 2020, 05:46:01 pm
Well, I'm having some fun playing this. Good thing it's not real money I'm losing.

I may have a higher resolution version of that card set still on an old drive - I remember reducing it to the final cards.png version to save smartbasic memory usage but still looked decent on the iPad screen.  I'll look for it if you'd like.

- Dav
Title: Re: Blackjack
Post by: bplus on June 17, 2020, 06:47:36 pm
Well, I'm having some fun playing this. Good thing it's not real money I'm losing.

I may have a higher resolution version of that card set still on an old drive - I remember reducing it to the final cards.png version to save smartbasic memory usage but still looked decent on the iPad screen.  I'll look for it if you'd like.

- Dav

Yes the winning strategy is: better fake money here than real at a casino, LOL. So many times I get 15 or 16 or when I do get up to 20 the Dealer matches or better. I never see the Dealer sweat like I do.

@Dav  if your higher resolution cards that are Public Domain I'd be glad to use them, thanks.
Title: Re: Blackjack
Post by: johnno56 on June 17, 2020, 07:20:55 pm
Ok. I will tackle each point in turn....

Linux is exceptionally case sensitive when it comes to file names... But changing splash1.png to Splash1.png fix the only programming error.

Table cloth size: For me it's not an issue to change the size. The cloth can be scaled to whatever size you nee. The buttons are another issue... With a re-sized screen the buttons would need to re-created to match the pattern of the new cloth. That only takes a few minutes. Just let me know what size you want and it will be done.

The central logo/text is purely decoration. Because they are part of the cloth, just like the decorations of 'real' tablecloths, cards and chips can be placed on the logo. Because the cards are 'placed' and not animated when dealt... (oh. Wouldn't 'that' be cool? lol...) I can 'lighten the logo, so as to be less of a distraction, with the 'text' placed as you suggested. Perhaps use a larger version of the logo as a splash screen with a smaller version of the logo in the two upper corners... But, of course, these changes would be dependent on the final screen size....

"One single blank button". Probably will not work. If the cloth did not have a pattern you would be correct.

Fonts: I will attach the font I used. I am not familiar with the base fonts that Windows uses. If you like, so as to preserve consistency, select a font you like and I will update the cloth...

Card dimensions and resolution. I will prepare a "sheet" of 94X125 cards, using the set I have, just in case Dav cannot find his set of cards. I will probably have the same issue of pixelation as did Dav. I will experiment on a 'picture' card and post the result.

Sound: Card shuffle; Ambient noise and or music track are freely available for both personal and or commercial use. My advice would be to have the 'noise' and or the 'music' to be 'noticeable'... Soft enough to 'know' it's there and not to be a distraction... I hope I explained that correctly... lol

The 'speech' part of the Scratch version was the Authors' own voice. Scratch has a nice Text to Speech function built-in, but I doubt it could be used to 'output' to a file... lol  If all else fails, as you have already stated, we could modify the same system that was used in Battleships..  Many response types could be used... at the cost of some string space... lol

Splash screen. You are correct. Because it is my interpretation of a commercial image, using it without permission, would not be advisable. So, it is as you have so rightly stated, a 'place holder'.

Extra payout on a specific blackjack combination.... Sounds like a great idea... But, you may have to pay out a serious amount of change, for that to happen. If you are using a singe 52 card deck, the odds of being dealt a specific blackjack, if I am not mistaken, would be approximately 2,652 to 1. This is based on two consecutive cards being dealt. A 1 in 52 chance of a Specific Ace multiplied by a 1 in 51 chance of a specific face card. If you are using, let's say four decks, then the odds could be 41,412 to 1.  How much did you have in mind for a payout? lol
Title: Re: Blackjack
Post by: Dav on June 17, 2020, 07:28:05 pm
Ok, I'll start looking for it.  In the meantime, I stumbled on this page which says it has public domain card images for download.  I can't verify it is, but a quick google on that url turns up a lot of other peoples projects using it freely.

https://code.google.com/archive/p/vector-playing-cards/ (https://code.google.com/archive/p/vector-playing-cards/)

- Dav
Title: Re: Blackjack
Post by: johnno56 on June 17, 2020, 07:43:54 pm
Dav,

Those are the cards that I have.. Ha. Small world...

I will attach a 240x336 King of Spades and a 94x125 (slightly sharpened) scaled version.

J

Title: Re: Blackjack
Post by: SMcNeill on June 17, 2020, 08:07:49 pm
https://github.com/SteveMcNeill/Steve64/blob/master/Archives/Images/Sexy%20Cards.JPG -- Personally, I think this little cardset looks good for any sort of gambling card game. 
Title: Re: Blackjack
Post by: _vince on June 17, 2020, 08:40:50 pm
https://github.com/SteveMcNeill/Steve64/blob/master/Archives/Images/Sexy%20Cards.JPG -- Personally, I think this little cardset looks good for any sort of gambling card game.

just a random assortment of photographs, could be a little more creative
Title: Re: Blackjack
Post by: johnno56 on June 17, 2020, 08:44:20 pm
Fascinating. Your choice of 'personal' cards are certainly different to mine. With images like those, I seriously doubt, much attention would be applied to the card suit or value... lol
Title: Re: Blackjack
Post by: bplus on June 17, 2020, 08:45:57 pm
Yeah, I had to look at them a second time just to see that they did actually have card values on them LOL
Title: Re: Blackjack
Post by: bplus on June 17, 2020, 09:48:09 pm
@johnno56

LOL I forgot where we were at?

Quote
Card dimensions and resolution. I will prepare a "sheet" of 94X125 cards, using the set I have, just in case Dav cannot find his set of cards. I will probably have the same issue of pixelation as did Dav. I will experiment on a 'picture' card and post the result.

Yeah I just ran the math on the 240 x 336 card size, those are too big but probably shrink is better than expand. I don't know.
But I think a card sheet 4 rows of 14 with 14th's being Joker (optional) and card backs 1 needed.

You say you'd like to see the cards being flung into position from a shoe? I am picturing a real shoe for a play on words, they walk across the table leaving card footprints...  just joking, I think. :)

I'd like to try your latest table mockup with a blank transparent button so the table background shows through the button shape and print inside button. BTW I like the thicker of the 2 fonts you sent for button text I can draw up the buttons in the GetStarted sub and save as images instead of downloading each button. That would cut down on asset files specially if we have audio coming. Still deciding on final size leaning toward 1024 x 740 washing out logo might work but I am picturing the text to the right of logo because the right side of table is so empty of text it would balance it some.

For the splash can you do lettering for sign? I can do brick wall and some lighting effects? (remember the neon blue?)

OK for all the losers playing B+J version of Blackjack, we will offer 50 times your bet if you hit Ace of Hearts + Jack of Spades in that order, so it will be like a lottery on every round. I think the banker can cover that ;-))
Title: Re: Blackjack
Post by: bplus on June 18, 2020, 01:01:44 am
New Splash? looks a little better when plugged in and blue neon running.
 
Title: Re: Blackjack
Post by: johnno56 on June 18, 2020, 08:32:22 am
Hmm... Blue you say?...

If you want the wall in your original image, send it, and I will swap it over...

Just in case you would like a kind of animation... I have also made a 'blink' image.

Perhaps you can create the 'blink' by alternating between images a few times before prompting for a name?

Title: Re: Blackjack
Post by: bplus on June 18, 2020, 12:14:15 pm
Hey Johnno

You found the source of the neon2.ttf which is same link as your font. Speaking of that source for fonts I tried FreeSansBold.ttf, I used to replace my Arial.ttf but all the letters seem to have the tops cut into a tiny bit, I do like the thicker lettering. I think Arial has a Bold too, I will try.

I like in your screen shot how yours glows, I did neon pulsing by finding interior points (The A's need 3 for PAINT) and used PAINT of different colors while looping through the sign letter by letter so the whole thing feels electric but I don't have glow, maybe yours is easier but 2+ images would be huge MB of image files.

I found my brick wall at unsplash.com, I think the credit goes like this:
Thanks to Donnie Rosie @drosie for sharing their work @unsplash.com and I will ref a direct link:
https://unsplash.com/photos/taO2fC7sxDU 
We might go further and describe how we used the image, this satisfies requirements of many types of Open License I think.

Johnno try downloading from there and see if you get the same directions for using as I. I had to shade down the wall with various black transparencies to make it look like night time. The screenshot I show is when the pulsing stops to get the Player name. Ha the image is certainly large enough, as I recall 3 sizes are offered I picked the one closest to our screen of 1024 x 740.

I guess for best comparison we need to see splash screens in action. I will clean up my code a little and show you.

Update: oh I can make it glow too (without extra images to load) I will try, also add the the 50 X's bet for special Blackjack.

I wonder if you could neon the logo of cards?

I do want to try a blank transparent button please.
Title: Re: Blackjack
Post by: johnno56 on June 18, 2020, 09:07:01 pm
I usually get most of the fonts I use from free or open source sites...  I had to look for a font (Sans) that is similar to my system's 'San' font. I can try to find it, but there are squillions of fonts... well... maybe not 'squillions' but there's a lot of them... lol  I will send it as soon as I ca. Let me know how you go with arial bold?

Ah yes, The Glow. Gimp has the ability to create 'Drop Shadows' of any colour and radius (to a point... lol) that can be applied to any object on the layer. Enhancing the glow is done by simply duplicating the layer... The blinking was an 'after thought' as I was finishing the first image... I figured that perhaps a little animation might be nice.

I visited the linked site... Nice walls... At the bottom of the page it states, "Do what you want." (in reference to image usage. But, I think you are correct in giving them a mention, after all they are creators of the images. It's only fair. I was not given a choice of sizes. The image was quite large, 6000x4000. I can scale to 1024x768 by scaling the image until the 'Y' dimension is 768. The 'X' will by greater than 1024 but can be cropped.

Neon the 'logo', the one on the table? I am surprised that you phrased your question, "I wonder IF you could..."... lol  Pick a colour and it will be done. Send the RGB() of the colour you want. That way there will be no 'guessing' on my part... lol

A 'blank' transparent button? No problem.

Title: Re: Blackjack
Post by: bplus on June 18, 2020, 09:42:53 pm
Hi @johnno56

Here is the brickwall image 1920 x 1280, 700 KB I got:

To give night look you will likely layer over with transparent Blacks. Cropping better than scaling to preserve the detail of image. It is 1024 x 740 max screen dimensions for me! (not 768)

Give Neon Logo same colors as Lettering. We are just going for a clone of first splash screen we had, unless you got some idea for better? like a door fading into view after we get the Player's name :-))

So how many files does it take to create the effect you have for splash screen?
Title: Re: Blackjack
Post by: johnno56 on June 18, 2020, 11:55:14 pm
Ok. Got the wall file. '740'? Unusual max size... Laptop? Not a problem '740' it is...

The 'night' look. Your method produces the same result as mine. You 'overlay' transparent 'black' to the image. I make the wall partially transparent and place it on top of the 'black' layer. How many files does it take? Only one. The effects are layered either upon or beneath the image then all layers are 'merged' into one layer. That final layer becomes the 'new' image.

"Give Neon Logo same colors as Lettering. We are just going for a clone of first splash screen we had, unless you got some idea for better? like a door fading into view after we get the Player's name :-))
".... This line left me a little confused... mind you, it's not hard to do... lol  "first splash"? I have made a lot of splash screen recently. I'm not sure which one you mean... I'm not sure what you mean by, "door fading into view"....  Isn't it funny that we both know English, but based on where we were raised, our understanding of it can be as dissimilar as cheese is from chalk... My apologies for my lack of understanding...
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 01:16:58 am
Quote
".... This line left me a little confused... mind you, it's not hard to do... lol  "first splash"? I have made a lot of splash screen recently. I'm not sure which one you mean... I'm not sure what you mean by, "door fading into view"....  Isn't it funny that we both know English, but based on where we were raised, our understanding of it can be as dissimilar as cheese is from chalk... My apologies for my lack of understanding...

Well it wasn't your first splash screen or was it? you did call it splash1.png, reply #50
https://www.qb64.org/forum/index.php?topic=1406.msg119254#msg119254

LOL my little door idea fading into view when the Player enters es name was just a little fantasy psuedo code, just playing around don't worry about it :)

Man have I got an update almost ready! Allot of things cleaned up.
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 01:27:11 am
Complete overhaul all new image files since last update, I think. It works the same except the bank is now for memory storage between games only. A cleaner set of graphics:

 


Update: OK download is tested and everything is working fine on my system, except the mouse seems to need to be clicked more carefully ie less movement across screen while mouse button is down..

Update: Check Best Answer for latest zip package of Blackjack Game




Title: Re: Blackjack
Post by: Ashish on June 19, 2020, 01:54:04 am
Nice graphics! Good interaction.
BTW, I had never played cards and never understood it. I just know some basic info about it, so that I can use them
in solving probability problems. :)
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 02:31:57 am
Nice graphics! Good interaction.
BTW, I had never played cards and never understood it. I just know some basic info about it, so that I can use them
in solving probability problems. :)

Thanks, absolutely no need to hurry to learn cards, what you are learning now is way better!

Cards will still be around when you're ready. :)
Title: Re: Blackjack
Post by: johnno56 on June 19, 2020, 08:11:01 am
Here is the slash screen using your wall (1024x740).  Neon sign rebuilt from scratch...
If you need any more changes just let me know....

I need more coffee...

Title: Re: Blackjack
Post by: SpriggsySpriggs on June 19, 2020, 08:15:43 am
Dang, that looks cool
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 11:44:45 am
Dang, that looks cool

+1 Very nice work! I guess the detail works better with transparent image on black layer(s) if I got it correctly.

@johnno56 we can replace the neon2.ttf and drop code for that.
Did you say you could make it flash a little? Even if not, this is the clone for splash!

Oh yes! even the Ace is Red! And what luck the splash of red paint on the brick wall!
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 07:13:35 pm
Here is the Game package updated with Johnno's newSplash.png

@johnno56 What's next on our To Do List?

I know we need a better method for setting different bets each round, a slider bar I think. I will get on that.

Audio would be nice, hint, hint ;)

I will brew up a fresh pot :)

See Best Answer for latest B+J Blackjack version.
Title: Re: Blackjack
Post by: bplus on June 19, 2020, 07:28:39 pm
Oh dang! I thought I was looking at an Ace of Hearts not Spades. I saw red, am seeing pinkish red... :P

I guess it's just a case of wishful seeing. Ha! maybe I will be only one to notice. :)
Title: Re: Blackjack
Post by: johnno56 on June 19, 2020, 07:38:40 pm
You are too kind...

Actually, I used a similar method to yours, for making the wall. Decreased the 'brightness' of the wall. Applied a multiplied black 'fog edge', Merged all the layers and bingo! The wall only took a few minutes to make. The neon lights... Everything done from scratch... Took considerably longer that a 'few minutes'... lol

When you stated, "we can replace the neon2.ttf and drop code for that.", what exactly did you mean? I have several 'neon' fonts. 'neon lights' (the same as 'your' wall. 'neon tubes 2' (the font used in my image) and a couple of others that didn't look so good... lol  In school, we were taught English Literature and English Expression, obviously English comprehension was, shall we say, somewhat missing... *sigh*

Animating the sign was just alternating images of two walls. One has a complete neon sign, the other will have missing letters... Random delay between the images... 'blink' in that way a few times... Use the 'complete' wall... then prompt the user...

Gimp has the ability to create animated gif's but I do not know if QB64 can play them...

Another alternative is to use separate images for the wall and the sign. 'blink' the sign 'on and off' for a fraction of a second a few times. Switch the sign 'on' and prompt the user. Blinking can be associated with an electrical buzz sound. Giving the effect of a dodgy connection.

Speaking of sound... I will grab an ambient sound track and shuffle....
Title: Re: Blackjack
Post by: johnno56 on June 20, 2020, 06:43:32 pm
Ok. I managed to locate some free audio clips from soundbible.com (Ambience, chips and shuffle.)

Ambience.wav is quite large (5.3mb stereo, 2.6mb mono)
Ambience.ogg (1.6mb stereo, 756kb mono)

I will post the 'ogg' files (including stereo AND mono ambience)

Attribution:
Chips - Daniel Simion
Ambience Casino - Stephan Schutze
Shuffling Cards - themfish

Title: Re: Blackjack
Post by: bplus on June 20, 2020, 07:15:03 pm
Thanks Johnno,

Almost done with slider bar for variable betting. I'm debating various scales for players who have millions or billions of chips. I can work these audios in before next post.
Title: Re: Blackjack
Post by: bplus on June 20, 2020, 11:28:50 pm
Slider bar turned out great once I figured out how to get good increments for the maximum bet range.

@johnno56  the ambience.ogg file is good until the freaking loud laugh and chips.ogg, I don't know sounds jiingly for felt cloth table, shuffle.ogg is fine. Man we need a Dealer talking.

So here is BJ v2020-06-20 with new slider bar and some audio.
 


2020-06-29:  see Best Answer for latest update of Blackjack Game
Title: Re: Blackjack
Post by: johnno56 on June 21, 2020, 05:03:34 am
Nicely done indeed... Cool...
Title: Re: Blackjack
Post by: johnno56 on June 21, 2020, 07:06:12 am
Hmm... I noticed the "peak" in the waveform whilst I had the file within Audacity... I suppose I could try to remove it or shorten the waveform... I will run a few tests and get back to you...

Yes. A dealers voice would be good. I will look for a descent online text to speech application... In the meantime, what sort of statements or comments, do you think will work?
Title: Re: Blackjack
Post by: bplus on June 21, 2020, 11:13:34 am
If we can't get text to speech for any OS, I can do text to speech in Windows, if you can do it in Linux, then we can get code to tell us which OS and then use the text to speech method for each OS, theoretically :)

More homework ;-)
Title: Re: Blackjack
Post by: johnno56 on June 21, 2020, 11:50:21 am
Um... There I go with my poor communication skills again... I was not suggesting that we install a TTS system, but using one, to create the speech audio files. So far, just about all of the 'free' TTS programs, produce 'mechanical' voices. This would be ok for space shooter and the like... Finding a TTS app that has 'natural' speech are usually cost prohibitive. I had used Cepstral in the past, when I was using 32 bit Linux, and the demo produced very good quality voices and would output to an audio file. So I checked out the latest Linux version. It installed and ran without issue, but because it was not registered, it will no longer output to an audio file. There are several TTS applications for Linux, but I wouldn't use them on blackjack. I will try to attach a sample just to give you an idea. If you search for Cepstral, you may be able to test some voices online...

Title: Re: Blackjack
Post by: Pete on June 21, 2020, 12:56:26 pm
Brings back memories. One of my earliest programs was a Black Jack simulation. I found the mathematically most sound betting program from books, and simulated play over millions of hands. What I concluded was that you needed to bet very large amounts to make any decent money, and if you made any mistakes, as humans do, a few would put a weeks work to no gains and a few more would put you in the poor house. That program was possibly responsible for my first practice. The money I saved up working while in high school and college would have gone straight to the casinos, had I not made that simulator, oh, and read a book that pretty clearly stated that if you believe the people who built Vegas on organized crime wouldn't cheat you at cards, think again. It only takes replacing a couple of 5s or 2s for 10-count cards in an entire shoe to tilt the odds back in the house's favor.

Anyway, long story longer.... beautiful background, neat layout, and it sounds like this baby will have all the bells and whistles of a first class made for prime time computer game. It's stuff like this that makes we wish Rob would have had a simple way to port the language to mobile device. Obviously I'm glad he didn't try with Windows phone, RIP, but it would be neat to see this game on tablets, Android phones and iphones, but I digress... In regard to the game, it's great that you included double down, insurance, surrender, etc. Very professional! I haven't read all the pages, so I'll ask. Did you consider a two version option, playing from a shoe, which is Vegas style, or playing from a 52 card deck, which is played in Reno?

Awesome project. Best wishes on its completion,

Pete
Title: Re: Blackjack
Post by: bplus on June 21, 2020, 02:02:29 pm
Hi @Pete,

I did put in Double Down but ruled out Insurance when I read advice from I assume professional player never to take insurance. It seems it only comes up when dealer has Ace showing, even if you win your Insurance Bet you still loose the original bet so WTH? it's not worth the trouble of coding or taking the option in Casino, unless I misunderstood something.

Surrender when I first read about it sounded interesting to cut your losses on a bad set of cards, then again is it worth coding the complex situation? I might put it in if someone can give me a good argument for it.

It is thanks to you I did do Double Down way back... I think it makes the game more interesting.

and way back, I think I did do multiple "dummy" players, I know I considered it, I'd have to read through the start of this thread too :P
Title: Re: Blackjack
Post by: Dav on June 21, 2020, 09:54:35 pm
Well this is coming along nicely!  Good work

I'm sorry that I haven't been able to locate the higher resolution card set that I once had somewhere.  I may have deleted it. 

- Dav
Title: Re: Blackjack
Post by: bplus on June 21, 2020, 11:13:26 pm
Thanks @Dav, I am not worried about cards. Lookup under Vector Playing Cards, I have an Open Source set 500 X 726 each card!

@johnno56  I don't mind a Dealer that sounds like a robot, we can work that to our advantage maybe but we need to understand what e says and offer sub-titles, but we were going to have to do that anyway. :)

You might record common speeches but what about saying total amounts?

I wonder if we could Shell to the Browser and have a site translate text?

Title: Re: Blackjack
Post by: johnno56 on June 22, 2020, 03:30:46 am
I had thought of something like that... But outputing specific phrases to audio would require a registered version of Cepstal. The application I used was Festival. It's free and can use various voices, but as you would have heard, a bit too much on the 'mechanical' side for my liking. But, as you have implied, it will do for now...

For Festival, or Cepstral for that matter, would have to be installed on each machine to enable producing 'live' comments. Making a list of some well known gambling phrases; card numbers and suites; regular and amusing dealer comments etc could be used to make a 'library' of sound bites...  I have never gambled before and would not be a good source of information. Perhaps we could crudely imitate Scratchjack comments? I will start with them and get back to you. If the files are too big I will post a link.
Title: Re: Blackjack
Post by: johnno56 on June 22, 2020, 06:33:06 am
Here are the converted ScratchJack voices. I still have to do a collection of 'smart mouth' comments.

Review these and let me know if they are any good? These will 'do in a pinch' but I will still research something better... fingers crossed...

Title: Re: Blackjack
Post by: johnno56 on June 22, 2020, 06:38:55 am
Try this modified version of ambience....

Title: Re: Blackjack
Post by: bplus on June 22, 2020, 09:55:55 am
@johnno56

I will check out your sounds and assimilate :)

You probably can't hear the jokes from robot voice (Windows only) but check out the jokes.

This is the Dealer (a combination of Steven Wright, Henny Youngman and Pete) who would get tips even from players who lose (well I might be tempted anyway with fake money). Might as well get entertained a little while emptying your fake wallet :)

This is fun to review every 6 months or so:
Title: Re: Blackjack
Post by: bplus on June 22, 2020, 10:13:59 am
@johnno56 ambiance 100% better! Thanks and those sound wavs are OK. I picked up a trick when writing text for jokes NOT to spell, punctuate, and space words and letters as you would in a book report to English teacher, it's more like writing lyrics to song, break words up space them out add or change letters for it to sound correctly when spoken and heard.

It is nice idea to have several different phrases for common things Dealer has to communicate.

I wonder if the Dealer might read the Help Screen for first time players or hyperlink snatches of it for regular players who want a refresher say on the special Blackjack or Terms... do it in cartoon bubbles with point going up as if coming from Dealer, I'm thinking in the center of screen over the Logo section. What would a robot version of a cartoon bubble look like?
Title: Re: Blackjack
Post by: johnno56 on June 22, 2020, 08:09:48 pm
Ok. For starters... You are correct. I cannot use your program to 'read' the jokes. SAPI seems to be part of the Windows speech utility. I could run it through 'Wine' but it will crash because of sapi... Oh. Well... The thought was there...

This TTS can be quite addictive... Although today's computers are more powerful, we will still have to be conscious of the fact that, the program may become 'bloated' with sound files... lol

With that being said... My TTS program (by the way... I have added a slightly better 'voice'. I will attach two samples.) can read text files and convert them to 'wav' files. For the 'help', I would convert the 'wav' to 'ogg', to reduce the file size. Other 'help' snippets can probably remain as 'wav'.

Cartoon bubble you say... Hmm... My suggestion would be and '8 bit' look... I will attach a large version as an example. Ideally, a subroutine would be needed to create a bubble to fit the text... I suppose similar to creating 'buttons with different lengths of text....

I will look up some dealer 'comments' and convert them to audio. Could be fun.
Title: Re: Blackjack
Post by: bplus on June 22, 2020, 09:46:52 pm
Thanks Johnno, might be able to draw bubbles like yours shown to the size of text. I was thinking something modern like gases coalescing into text ;-))

Oh I like new welcome.wav, e's got a formal Britash accent about em.
Title: Re: Blackjack
Post by: johnno56 on June 22, 2020, 10:52:14 pm
'Gases' sounds pretty cool... Can you find an image that looks like your 'gases' bubbles? Post it (them) and I will see if Gimp can do a reproduction...

Yeah... I added the 'mbrola en1' voice... British it is... the US voices were more like English with some other accent thrown in for good measure... lol  I will check out some more voices... At the moment, the British voice, seems to be the better one... I'll keep looking.
Title: Re: Blackjack
Post by: bplus on June 22, 2020, 11:01:58 pm
The gases coalescing thing was my imagination running wild and it would probably not be a still shot image but code.

Oh maybe like this:
https://www.shutterstock.com/image-illustration/glow-swirl-light-effect-circular-lens-525106498

Try different voices reading the jokes. Might have different players sitting next to you telling them.
Title: Re: Blackjack
Post by: bplus on June 22, 2020, 11:28:59 pm
Maybe something like this:
Code: QB64: [Select]
  1. _TITLE "Random light line" 'b+ 2020-01-28 mod 2020-06-22
  2.  
  3. CONST xmax = 1200, ymax = 700
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. REDIM SHARED x, y, dx, dy, a, da, d, dd, i
  6. resetWand
  7. WHILE _KEYDOWN(27) = 0
  8.     LINE (0, 0)-(xmax, ymax), &H01030003, BF
  9.     IF INKEY$ = " " THEN CLS: resetWand
  10.     wandsi x, y, a, d, 0, i
  11.     x = x + dx
  12.     IF x < 0 THEN x = 10: dx = -dx
  13.     IF x > xmax THEN x = xmax - 10: dx = -dx
  14.     y = y + dy
  15.     IF y < 0 THEN y = 10: dy = -dy
  16.     IF y > ymax THEN y = ymax - 10: dy = -dy
  17.     a = a + da
  18.     d = d + dd
  19.     IF d < 20 THEN d = 20: dd = -dd
  20.     IF d > 200 THEN d = 200: dd = -dd
  21.     i = i + 1
  22.     _DISPLAY
  23.     '_LIMIT 200
  24.  
  25. SUB resetWand
  26.     wandsi 0, 0, 0, 0, 1, 0 'this sets a coloring for wand  used in drawing the pointer inside the mouse
  27.     x = RND * xmax: y = RND * ymax: dx = RND * 2 - 1: dy = RND * 2 - 1: a = RND * _PI(2): da = _PI(2 / 720): d = 50 + RND * 50: dd = RND * 2 - 1
  28.  
  29. 'draw a colorful line from point x, y, at radianAngle for a distance and use new <> 0 to reset colors
  30. SUB wandsi (x1 AS SINGLE, y1 AS SINGLE, radianAngle AS SINGLE, distance AS SINGLE, new AS INTEGER, startIdx AS INTEGER)
  31.     STATIC r AS SINGLE, g AS SINGLE, b AS SINGLE 'hold present color settings until
  32.     IF new <> 0 THEN r = RND * RND * .5: g = RND * RND * .5: b = RND * RND * .5 'new is true
  33.     DIM dx AS SINGLE, dy AS SINGLE, i AS INTEGER, x AS SINGLE, y AS SINGLE
  34.     dx = COS(radianAngle): dy = SIN(radianAngle)
  35.     FOR i = 0 TO distance
  36.         x = x1 + i * dx: y = y1 + i * dy
  37.         LINE (x, y)-STEP(0, 0), _RGB32(127 + 127 * SIN(r * (i + startIdx)), 127 + 127 * SIN(g * (i + startIdx)), 127 + 127 * SIN(b * (i + startIdx)), 50), BF
  38.     NEXT
  39.  
  40.  
  41.  

Title: Re: Blackjack
Post by: johnno56 on June 23, 2020, 02:29:10 am
"Glow swirl light effect. Circular lens flare. Abstract rotational lines. Power energy element. Luminous sci-fi. Shining neon lights cosmic abstract frame. Magic round frame. Swirl trail effect" is quite a mouthful of a description.... My Gimp skills are not up to that level yet... But it is quite good... I would definitely be interested in a tutorial that could produce such an effect....

"Different voices" sounds like a great idea... but I'm not sure if people will be able to cope with 2+ other "robots" having conversations.... lol  So far, the voices that I have found, are all fairly similar...

The TTS that I am using is call 'espeak' and will run on Linux, Mac, Risc an Windows (requires SAPI5) and is free. (http://espeak.sourceforge.net/download.html)  On my system I can run espeak from the command line or through a GTK gui call Gespeaker. Gespeaker will require python2.7  The sound is not pretty (as you have heard) but can be fun to tinker with...

Your 'Random Light Line' reminds me of the old Win95/98 'Mystify' screen save... but better looking ;)
Title: Re: Blackjack
Post by: bplus on June 23, 2020, 02:13:12 pm
Quote
Your 'Random Light Line' reminds me of the old Win95/98 'Mystify' screen save... but better looking ;)

I forgot to mention how applying alpha to the drawing killed the heck out of the speed.
Title: Re: Blackjack
Post by: johnno56 on June 23, 2020, 04:05:54 pm
Curious. How does "step" work in line 42? I don't normally come across the use of 'step' in a 'line' command. How could this be re-coded to produce the same effect without the use of 'step'?

LINE (x, y)-STEP(0, 0), _RGB32(127 + 127 * SIN(r * (i + startIdx)), 127 + 127 * SIN(g * (i + startIdx)), 127 + 127 * SIN(b * (i + startIdx)), 50), BF
Title: Re: Blackjack
Post by: bplus on June 23, 2020, 04:16:32 pm
STEP means from last graphic coordinate used STEP(step x, step y)

so (100,100)-STEP(25, -50) = (100, 100)-(125, 50)

In the line you show the STEP(0,0) is effectively just drawing points like PSET. I think it was Steve who said LINE was optimized for that compared to PSET.
Title: Re: Blackjack
Post by: johnno56 on June 23, 2020, 05:42:31 pm
So... Step draws a line 'relative' to the origin point of the first two parameters? Cool...
Title: Re: Blackjack
Post by: bplus on June 23, 2020, 07:14:31 pm
Yes relative and yes cool, you don't have to add the step size to x and the step size to y... to get the Absolute coordinates at the endpoint of a line, let the code do the math ;-)
Title: Re: Blackjack
Post by: bplus on June 28, 2020, 06:00:34 am
@johnno56

How are the sound files for English accented dealer coming? Maybe forget the jokes??


I guess I better get back to the coalescing text bubble maker, myself.
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 08:13:59 am
I still haven't found a better voice for my TTS. We may have to use the 'English' voice or do it 'old school' and just use 'bubbles'. I'll keep looking...
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 08:42:04 am
Had a crazy idea... Scratch has a TTS addon module... The downside is that it does not export. Only plays. I use Audacity as my 'go to' audio editor. Dot get ahead of me.... Programmed Scratch to 'say' - 'Welcome to Blackjack. Take a seat and enter your name." and recorded the sound via my 'camera mic'. Filtered out a little of the background noise... The results could be better, but not too bad, for a cam/mic. What do you think?

Obviously, I will need to run a few more filters through it to 'clean it up', but not too bad for a first try?
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 10:25:54 am
Update.

I have managed to figure out how to allow Audacity to record directly from the PC audio. Bingo! No static or need of filtering.

Here is the new sample.

Best part... 'wav' file is 600kb+ and the 'ogg' is just over 30k... Cool
Title: Re: Blackjack
Post by: jack on June 28, 2020, 11:02:47 am
that sounds really good :)
Title: Re: Blackjack
Post by: bplus on June 28, 2020, 11:21:51 am
that sounds really good :)

+1  Wow! clear and human, it sounds like a winner! I was OK to go with English accent but this can't be any more clear.

So you are getting speech from text with one app and recording that with another and the file size is quite doable.

Good research @johnno56
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 12:02:56 pm
It's almost 2am. After I get some sleep, I will extract the individual tracks, pop them into folders, zip them up, them send them... Now to find the alarm clock... and hide it... lol
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 07:27:41 pm
Ok. At a more respectable time of almost 9:30am... Here is the revised collection of 'dealer comments'. Check them and make sure that they are ok? Any problems then let me know and I will fix it.

Title: Re: Blackjack
Post by: bplus on June 28, 2020, 07:48:30 pm
@johnno56  Just in time!

I just finished my Coalescing Text maker for more modern looking "bubbles" I think.

I am thinking we can play sound and run the Coalescing Text maker and they might finish around the same time?

Check it out:
Code: QB64: [Select]
  1. _TITLE "Coalescing text" 'B+ started 2020-06-23
  2. ' post 2020-06-28  https://www.qb64.org/forum/index.php?topic=1406.msg120007#msg120007
  3. ' using OPTION _EXPLICIT in Blackjack I found a crucial mistake now it coalesces even better!
  4.  
  5. CONST xmax = 1000, ymax = 500
  6.  
  7. DIM SHARED f40 AS LONG 'don't have to be shared
  8. SCREEN _NEWIMAGE(xmax, ymax, 32)
  9. _DELAY .25
  10. f60 = _LOADFONT("OpenSans-ExtraBold.ttf", 60)
  11. f40 = _LOADFONT("OpenSans-ExtraBold.ttf", 36)
  12. COLOR , &HFF880000
  13.  
  14. coalescingText f40, _WIDTH / 2, _HEIGHT / 2, "Testing 1, 2, 3... How much can we fit?"
  15. coalescingText f60, _WIDTH / 2, _HEIGHT / 4, "Bplus did it! Coalescing Text"
  16.  
  17. PRINT "test is done" 'check the font, autodisplay and color restoration
  18.  
  19. 'center the text at x, y  dimension of a white/black background space will depend on font height and width of print string
  20. SUB coalescingText (fh&, xc, yc, text AS STRING)
  21.     'should not change anything on main screen as we will be projecting images to it in empty area
  22.     DIM oldFont&, oldBC~&, oldFC~&, olddisplay, screenshot&, w, h, temp&, yy, xx, p, i, projX, projY, loopI
  23.  
  24.     oldFont& = _FONT '_printwidth(s$, desth&)
  25.     oldBC~& = _BACKGROUNDCOLOR
  26.     oldFC~& = _DEFAULTCOLOR
  27.     olddisplay = _AUTODISPLAY
  28.     screenshot& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  29.     _PUTIMAGE , 0, screenshot&
  30.     _FONT fh& 'get measures
  31.     w = _PRINTWIDTH(text) + 40 ' create margin 20 around text
  32.     h = _FONTHEIGHT(fh&) + 40
  33.     'PRINT w, h    'exactly right
  34.     temp& = _NEWIMAGE(w, h, 32)
  35.     _DEST temp&
  36.     _FONT fh&
  37.  
  38.     'initializing
  39.     COLOR _RGB32(255, 255, 200), 0
  40.     _PRINTSTRING (20, 20), text
  41.     _SOURCE temp&
  42.     FOR yy = 0 TO h - 1 'simply count particles
  43.         FOR xx = 0 TO w - 1
  44.             IF POINT(xx, yy) <> 0 THEN p = p + 1
  45.         NEXT
  46.     NEXT
  47.     DIM x(p), y(p), dx(p), dy(p)
  48.     FOR yy = 0 TO h - 1
  49.         FOR xx = 0 TO w - 1
  50.             IF POINT(xx, yy) <> 0 THEN
  51.                 i = i + 1
  52.                 x(i) = xx: y(i) = yy: dx(i) = RND * 6 - 3: dy(i) = RND * 6 - 3
  53.             END IF
  54.         NEXT
  55.     NEXT
  56.     projX = xc - .5 * w: projY = yc - .5 * h
  57.     DIM coal(95) AS LONG
  58.     coal(0) = _NEWIMAGE(w, h, 32)
  59.     _PUTIMAGE , temp&, coal(0)
  60.     'draw loop
  61.     FOR loopI = 1 TO 95
  62.         LINE (1, 1)-(w - 2, h - 2), _RGB32(0, 0, 0, 3 * loopI), BF
  63.         LINE (0, 0)-STEP(w - 1, h - 1), _RGB32(255 - 3 * loopI, 255 - 3 * loopI, 200, 3 * loopI), B
  64.         FOR i = 1 TO p
  65.             x(i) = x(i) + dx(i): y(i) = y(i) + dy(i)
  66.             IF x(i) < 1 OR x(i) > w - 3 OR y(i) < 1 OR y(i) > h - 3 THEN x(i) = RND * w - 1: y(i) = RND * h - 1
  67.             LINE (x(i), y(i))-STEP(0, 0), _RGB32(255 - 2 * loopI, 255 - 2 * loopI, 200)
  68.         NEXT
  69.         coal(loopI) = _NEWIMAGE(w, h, 32)
  70.         _PUTIMAGE , temp&, coal(loopI)
  71.     NEXT
  72.     _DEST 0
  73.     FOR i = 95 TO 0 STEP -1
  74.         'LINE (projx, projy)-STEP(w - 1, h - 1), &HFF000000, BF
  75.         _PUTIMAGE , screenshot&, 0
  76.         _PUTIMAGE (projX, projY)-STEP(w - 1, h - 1), coal(i), 0, (0, 0)-STEP(w - 1, h - 1)
  77.         _FREEIMAGE coal(i)
  78.         _DISPLAY
  79.         _LIMIT 30
  80.     NEXT
  81.     'restore
  82.     IF olddisplay THEN _AUTODISPLAY
  83.     _FREEIMAGE temp&
  84.     _FREEIMAGE screenshot&
  85.     _SOURCE 0
  86.     COLOR oldFC~&, oldBC~&
  87.     _FONT oldFont&
  88.  
  89.  
  90.  

EDIT: adding the SUB into Blackjack using OPTION _EXPLICIT found a critical miss, fixed, and now the effect is even better!

Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 08:11:34 pm
Well... I now have 'OpenSans-ExtraBold.ttf' installed on my system... lol

I have not seen text 'appear' like that before... Very cool...
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 08:23:11 pm
ps: Perhaps a slight mod of the 'limit' on line #79? Perhaps the speed of limit could be calculated from time length of each phrase? ie: The longer the phrase the quicker the 'limit'? I have no idea how to do that... just a rogue thought...
Title: Re: Blackjack
Post by: bplus on June 28, 2020, 08:30:59 pm
ps: Perhaps a slight mod of the 'limit' on line #79? Perhaps the speed of limit could be calculated from time length of each phrase? ie: The longer the phrase the quicker the 'limit'? I have no idea how to do that... just a rogue thought...

Great idea Johnno, It could easily be built into the sub from the text length, hopefully I will get a feel for timing from your latest audio's, thanks.

PS the font OpenSans-ExtraBold.ttf is same as used in last version of Blackjack same source as our Neon2.ttf. I really like that fat text!
Title: Re: Blackjack
Post by: bplus on June 28, 2020, 09:22:28 pm
Try Coalescing Code again if you checked it out already (2020-06-28 9:19 PM Ohio Time zone) found miss, fixed, and now the effect is even better!

https://www.qb64.org/forum/index.php?topic=1406.msg120007#msg120007
Title: Re: Blackjack
Post by: johnno56 on June 28, 2020, 10:31:18 pm
Ok. Tried the 'second' version. Actually nicer than the first... Cool.

The font was installed because I had upgraded Linux Mint 18.1 to 19.3 and all my previous 'manually' added fonts migrated to the ether... *sigh*
Title: Re: Blackjack
Post by: bplus on June 29, 2020, 01:53:46 am
Progress report: Bets, numbers and busts are installed and working, shaping up nicely with Dealer speaking.

Really good sound quality @johnno56

I am playing the Welcome from the splash screen and we are sort of still in the street, outside the building.

I wonder if the voice would not ask us to sit down but to write the Player name and enter.
Title: Re: Blackjack
Post by: johnno56 on June 29, 2020, 05:27:50 am
Consider it done.

Here is the basic 'Welcome' plus a few extra 'post-entry' responses.
Title: Re: Blackjack
Post by: bplus on June 29, 2020, 11:11:03 am
Thanks @johnno56  for quick return.

It turns out that the audio is faster than the coalescing text and I have to get it started before the audio.

I am wondering if I should even keep coalescing text in. Well I will leave it for now because it's nice signal for Dealer speech. I will fiddle around with it a bit.

As I understand it sound can play and graphics can continue while sound is playing but coalescing monopolizes execution flow until it's finished. Maybe I need to play sound from a timer, let coalescing get started and set timer for .5 sec delay to play sound.
Title: Re: Blackjack
Post by: bplus on June 29, 2020, 11:27:18 am
Hi @johnno56

Just played the new welcome, hate to be picky but I was hoping for a little play on the word Enter, "Please type in your name and enter" uses enter double meaning, as we need enter key to signal end of input and enter as in enter our fake building ;-))

LOL the quips about wallet!
Title: Re: Blackjack
Post by: johnno56 on June 29, 2020, 06:16:52 pm
Done!
Title: Re: Blackjack
Post by: bplus on June 29, 2020, 11:30:32 pm
OK here is an update with most of the sound files roughed in and fixes and changes:

see Best Answer for latest Blackjack version.
Title: Re: Blackjack
Post by: johnno56 on June 30, 2020, 01:18:06 am
Hey! The dealer starts with almost $73k... lol

I think we need more 'numbers'. One time I stayed and the dealer hit on 16. Dealt itself a picture card but 'said' 16. I will whip up numbers 22 to 31 and post them.

Other than that, a really good game. Nicely done!
Title: Re: Blackjack
Post by: johnno56 on June 30, 2020, 01:59:19 am
22 to 30 instead. Highly doubt that 31 would be needed... lol

Title: Re: Blackjack
Post by: bplus on June 30, 2020, 12:00:34 pm
Dealer is supposed to say, "Busted" or equivalent when ever either player goes over 21. I have checked that both get "busted" speech for going over 21.

I really like the audio for dealer and it is way clearer than I had expected (which is why I stuck in there with the .ogg files).

I have more to add and refinements to make. Like the option of setting the bet at the beginning, the coalescing text is on the chopping block as I was anticipating an older model computer voice. Working out the timing with sound may not be worth the trouble because numbers are so short there is no time now to see them before they disappear.

I like the fixed fINPUT now, you can see the brick wall behind the lettering, and will be reusable in other apps.

Update: oh maybe the last total is still showing when busted comes up, I will check that. I am looking at one place for errors, you might still be looking at where totals are showing.
Title: Re: Blackjack
Post by: bplus on June 30, 2020, 02:39:46 pm
Just had an idea to use that chip stack Johnno setup awhile back.

Move the chips image into "Bet area" at right bottom corner when you hear the sound of chips.

Clear that image (or double it) after hand accounting and then have it cleared when time to place new bet.

That would give more sense to the sound of chips chinging.

I was comparing our version to Scratch Jack when I had the idea. BTW I think we are doing pretty good in comparison.
Title: Re: Blackjack
Post by: Dav on June 30, 2020, 04:13:19 pm
Game is playing good.  I like the new enhancements.  I'm still loosing bad however....

Just a suggestion here from a user... if the project download size is ever a consideration, then I'd suggest lowering the ogg file quailty points a little bit more in Audacity when exporting some of those ogg files.  It can decrease file sizes a whole lot without hurting the sound quality very much.  Especially on the ambience ogg - with that one you could shave off nearly 800k before the average listener would notice anything different.  Also, maybe it would be interesting to put in a random sound assigned with a TIMER - like every 3 minutes a random noise or comment, perhaps laugh in the far left distance, or some jackpot sound on the far right, etc.  That could kind of mask the repetition of the ambience sound looping.

Good work on the game!

- Dav
Title: Re: Blackjack
Post by: bplus on June 30, 2020, 07:01:44 pm
Thanks @Dav  I did try to use the mono ambiance @700 KB but it had a loud annoying laugh at regular intervals.

Maybe @johnno56 can give us some random ambiance to toss in over regular ambiance, maybe something from Monty Python's flying circus (just joking, I think).

I am tired of losing too and have an idea to reward fans of this particular game ;-)

Stay tuned...
Title: Re: Blackjack
Post by: johnno56 on June 30, 2020, 08:40:58 pm
I have used the free chips from opengameart.org to create individual chips; Also two sets of two scattered stacks (first bet and DD). Included the individual chips in case you were wanting to produce random stacks.

Title: Re: Blackjack
Post by: bplus on July 01, 2020, 02:34:58 am
A little break in luck for longtime players, we are moving chips around now!

Update: See Best Answer for latest version of Blackjack

Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 06:32:52 am
Cool chip animation! Nice touch.
Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 06:45:26 am
Hmm... I noticed that you are using a cropped version of the reflected chips image... and I 'did' notice the reflection under the chips... lol
I will recreate then, without the reflection, then post them... It will take me a little while... The stack has to me 'created'... lol
Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 07:09:57 am
Ok. The reflection has been removed and I have slightly brightened the colour.
Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 07:29:32 am
Found another graphics anomaly. Please swap your cards.png for the attached.

Before you do. Restart the game and take a close look at the cards being displayed on the screen. Particularly look closely at the 'black' cards. All the club and spade symbols, as well as any black in the 'picture' cards. Can you see the table cloth pattern?

Reason: All the cards have a 2 to 4 pixel black border. I am going to assume that, qb64 like other programs, assumes that the top left pixel of the image, unless specified, will interpret 'that' pixel, as a consequence all other pixels of the same colour, as the 'transparent' colour.

Most images that require a 'transparent' colour usually choose magenta. In our case... It's 'black'.

I have attached the same card-set but have used are darkish grey as transparent. Ran it on my machine and all the black cards are indeed black. Mind you, with my eyesight, I had to use a magnifying glass... lol
Title: Re: Blackjack
Post by: bplus on July 01, 2020, 09:47:05 am
Thanks @johnno56

I was noticing the chips were a little funky at the bottom, totally missed the thing with the cards.

Are cards exact same size? well I will find out ;-))
Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 12:01:32 pm
Exact same size. All I changed was the colour of the black "borders" to dark grey.
Title: Re: Blackjack
Post by: bplus on July 01, 2020, 12:36:13 pm
Great! I haven't tried swapping chip images yet, but I  can't wait until someone gets one of these (see attached).

Update: new images loaded in and just a little adjustment to Y's by 15 pixels for chips with 0 reflections.

:-)) my avatar updated to same.



Title: Re: Blackjack
Post by: bplus on July 01, 2020, 10:21:29 pm
@johnno56

Would it be too difficult to change the Ace of Spades to Ace of Hearts on Splash screen neon light. Turn the spade upside down and remove the stem? That is Our table Logo and the special Blackjack that pays 50 X's the bet.

I have a notion to try drawing it from card outline.
Title: Re: Blackjack
Post by: johnno56 on July 01, 2020, 11:33:30 pm
Good pickup! Consistency. I will see what I can do...
Title: Re: Blackjack
Post by: johnno56 on July 02, 2020, 12:23:59 am
Try this one...
Title: Re: Blackjack
Post by: bplus on July 02, 2020, 09:10:26 am
@johnno56

By George! I think you've got it! Very Good!

(Been awhile since I said, "By George," maybe never, who is George? some clever guy?)

Update: the images swapped with only minor change to chips Y values.

Getting close to final version, is there anything you'd like to see?

I know more chips in your total but if you play long enough that should happen. Note to Pete, chips are fake, not even eatable, no cash value ;-))

I like Dav's suggestion of some occasional random ambiance sound to break up the continuous background loop.
Title: Re: Blackjack
Post by: johnno56 on July 02, 2020, 12:46:16 pm
I've done some searching for ambient sounds for blackjack poker and casinos but most of the sounds are chips and card shuffling etc. Other voices are usually found in those long ambience loops. I am more at home with a graphics editor than a sound editor. So 'creating' or 'extracting' voices are a bit beyond me at the moment... But I will keep 'looking'....

ps: Q: Who's George in the expression “By George!”? A: The phrase is a mild oath or exclamation that had its beginnings in the late 1500s. The word “George” here is a substitute for “God,” as are words like “golly,” “ginger,” “gosh,” “gum,” and so on in other similar euphemistic oaths.

Thought you might like the trivia...
Title: Re: Blackjack
Post by: bplus on July 02, 2020, 02:28:08 pm
By George, I think any short little sound effect < 1 sec will work to break the monotony of the ambient loop. I will check SoundBible, can you play .wav files on Linux?, no, come to think of it, that's Windows, but MP3 should be OK?

I've been putting on a YouTube track of music and turn down volume to that while playing Blackjack. That dealer's voice is so clear! Lately it's been mixes featuring Snow Patrol.

The trivia note is appreciated because as Dimster and Cobalt know we are nerds! ;-))
Title: Re: Blackjack
Post by: SMcNeill on July 02, 2020, 02:29:25 pm
I've done some searching for ambient sounds for blackjack poker and casinos but most of the sounds are chips and card shuffling etc.

What you need to add is the chance of the sound of someone coughing at random, followed by somebody yelling, "Cover your mouth, dude!", and someone else yelling, "What the hell?!!  You just spittered on me!!"  Follow that with gunshots, shouting, and then a calm announcer's voice coming across an intercom telling everyone, "I'm sorry.  Due to the recent rioting, our casino is now closing to the public.  All games will now shut down.  Please head for the nearest exit in a calm, respectful manner."  Repeat once more.  Then go to system and make the poor player lose all their winnings!   
Title: Re: Blackjack
Post by: bplus on July 02, 2020, 02:39:05 pm
What you need to add is the chance of the sound of someone coughing at random, followed by somebody yelling, "Cover your mouth, dude!", and someone else yelling, "What the hell?!!  You just spittered on me!!"  Follow that with gunshots, shouting, and then a calm announcer's voice coming across an intercom telling everyone, "I'm sorry.  Due to the recent rioting, our casino is now closing to the public.  All games will now shut down.  Please head for the nearest exit in a calm, respectful manner."  Repeat once more.  Then go to system and make the poor player lose all their winnings!

LOL!
Title: Re: Blackjack
Post by: johnno56 on July 02, 2020, 06:21:05 pm
Steve,

You have a wicked sense of humour... Funny. But wicked... lol
Title: Re: Blackjack
Post by: johnno56 on July 03, 2020, 11:29:00 am
bplus,

Searched soundbible and opengameart for some 'vocal' effects. Pickings were slim but managed to find a few samples. I don't know how many sound channels QB64 can play or how to control the volume of each channel. I'm going to assume that timers, in concert with each channel, would be the way to 'overlay' the background track. They are all a bit loud. I can use Audacity to modify the volume of each sound if needs be.

I will keep looking...
Title: Re: Blackjack
Post by: bplus on July 03, 2020, 12:35:38 pm
Hey @johnno56  I will check them out after lunch.

Yeah, I was looking for sounds last night too. Something's happened to soundbible, impossible to use, for me anyway.

I did manage to get a couple of MP3's to throw in some excitement like somebody did well close or far from you (according to vol I hope). Planning the first final cut today or tonight, any last minute ideas?

Pete's idea about showing other players too, I will save for another time, well maybe throw in a bot or two to try out AI strategies. That would probably only mean showing players names? more than that.... cards... eh?

I had not heard or seen any arguments for Insurance Option so I will leave it simple and without that complexity.
Title: Re: Blackjack
Post by: bplus on July 03, 2020, 05:08:05 pm
OK we have the neon sign with our BJ Logo, some background random noise, an ICON image, and better chips and cards images for this first final cut version:

Updated: See Best Answer with latest and greatest version and download zip package.
Title: Re: Blackjack
Post by: johnno56 on July 03, 2020, 08:40:08 pm
Obviously soundbible worked for me... lol

I ran the new version... Heard a 'yahoo'... while I was losing... lol

Speaking of losing... I noticed a slight speech problem with, "To bad you lose"... "you" sounds like it is slightly off. Not sure how better to explain it.

I experimented and found a better way of pronouncing 'you'. I used the word 'Ewe' in stead. Compare them and let me know what Ewe think. (Sorry. Couldn't resist... lol)

Oh. My second 'test' of the new version... Two blackjacks in a row followed by a twenty... Made a bucket load of money... Four hands later and it was all gone... *sigh*
Title: Re: Blackjack
Post by: bplus on July 03, 2020, 08:46:02 pm
Thanks Johnno, I will try out the new sound.

You have a 1 in 169 chance of getting the super Jackpot Blackjack so hang in there. :)
That's sort of like 50 free games.
Title: Re: Blackjack
Post by: bplus on July 04, 2020, 11:03:21 am
Yeah OK the too_bad.ogg sounds less American 😂 and might be easier to understand.

It is easy to swap the two files, File Explorer had no problems with that.

Man! @johnno56 you are picking very fine points, good that you can find something and offer a change.

It just occurred to me talking to TempodiBasic about Italian card games that no one has mentioned the Split option in Blackjack!?! Of course it'd be a bit of a mod, as would multiple players ie bots.
Title: Re: Blackjack
Post by: bplus on July 04, 2020, 05:26:50 pm
OK, I have the 2nd final cut ready with an EXEICON and an improved ICON image and Johnno's you changed to ewe ;-))

This time I remembered to update the bas source with the version number:

Update: The Best Answer contains an updated version with more or better comments. The code has not been changed since the post of July 4th version.
Title: Re: Blackjack
Post by: johnno56 on July 04, 2020, 07:11:58 pm
Nicely done.

Oh. Tested this version; My first Blackjack filled the screen with chip stacks and added $52,000 to my score!! So, I quit the game, made a copy of the 'memory bank' as proof... Cool... Woo Hoo!
Title: Re: Blackjack
Post by: bplus on July 04, 2020, 10:46:29 pm
That must be THE keeper version then!

I've already put a Shortcut on my desktop for something to play while listening to tunes. Love the EXEICON.
Title: Re: Blackjack
Post by: johnno56 on July 04, 2020, 10:48:19 pm
Cool...
Title: Re: Blackjack
Post by: bplus on July 05, 2020, 03:08:26 pm
SOMETHING VERY ODD HAS HAPPENED TO VERY FIRST POST. SUPPOSEDLY MY BEST BJ MOD TO THAT POINT DOESN'T EVEN WORK IN QB64 1.4 ? WHAT HAPPENED?

STAY TUNED...

PS I AM HOPING TO TRY SOME SIMPLE CODE TO RUN AI EXPERIMENTS. LAST NIGHT I CONFESS GETTING BORED AS HELL PLAYING, GIVING UP ON ANY 'FEEL' FOR MAGIC MOMENT MY LUCK WILL CHANGE AND I WANT TO TRY DIFFERENT AI STRATEGIES, THERE IS THE BUILT-IN ENCOURAGEMENT OF 50 X'S BET JACKPOT BUT THAT IS NOT ENOUGH INCENTIVE TO KEEP PLAYING. THINKING I HAVE A LONG TERM WINNING STRATEGY IS!

WE ARE SHUFFLING DECK BEFORE EACH ROUND SO CARD COUNTING IS NOT A MAJOR FACTOR IN PLAY, I THINK...


Update: a very simple fix but odd that it should go wrong between QB64 versions?
I am updating SCREEN 0 version to play like it's Big Brother without full audio and graphics for AI tests.
Title: Re: Blackjack
Post by: johnno56 on July 05, 2020, 07:06:46 pm
I am a little confused. I know... only a 'little'..... lol

QBv1.3 was either released on 19th Jan 2019 or 8th Apr 2019 (please correct me if I am in error). The first BJ posting, on this forum, was 7th June 2019.

QBv1.4 was released on 13th Feb 2020.

Assumption #1. BJ was developed originally using 1.3 and later updated to 1.4
Assumption #2. BJ has always been developed with 1.3
Assumption #3. BJ has always been developed using 1.4

If either assumptions #1 or #2 are true then I would assume that the problem would be 'version' related. But that argument may not hold as the current problem would have presented itself earlier.

If assumption #3 is true then the problem is, more than likely, not version related.

I have to conclude that assumption #1 is correct as your opening statement says, "DOESN'T EVEN WORK IN QB64 1.4"

To be able to assist, assuming that I can, I would need a few more details of the issue apart from, "something odd'... lol
If you can describe the problem and how it is presenting itself, I may be able to see if that problem exists within the Linux version of 1.4

Oh. Quick question. I updated to 1.4 a while ago... I'm not sure if I installed the development version or not. How can I tell? Are you using the 'normal' or 'dev' version? Ok. My math abilities are shot.... I know... That was two questions... lol
Title: Re: Blackjack
Post by: FellippeHeitor on July 05, 2020, 07:17:09 pm
What doesn't work in the latest version?
Title: Re: Blackjack
Post by: bplus on July 05, 2020, 07:29:34 pm
What doesn't work in the latest version?

Well this afternoon I was testing the old code and when I tried keypress h to hit it wasn't.
Then I downloaded the code from forum to see if it were any better, it wasn't.

But tonight I try the same thing again before this reply, and all is OK.

Now I wonder if I had caps lock on.  :P
Title: Re: Blackjack
Post by: FellippeHeitor on July 05, 2020, 07:36:58 pm
Oh 🤣
Title: Re: Blackjack
Post by: johnno56 on July 05, 2020, 07:48:16 pm
I will hardly tell anyone...
Title: Re: Blackjack
Post by: bplus on July 05, 2020, 08:02:49 pm
Oh @johnno56  I missed your post applying logic to what might have happened.

I developed the old code in QB64 v1.3 last year July, and never looked at it again until today using QB64. (Our version of this June and July started from a later version with card images.) It wasn't working so the first thing I ask myself is what is different. The QB64 version number was the first thought that came to mind.

I hardly ever type with caps lock on unless I am screwing around effected by Pete's comment about the men in caps.
So of course, this whole thing is Pete's fault. 😜

Quote
Oh. Quick question. I updated to 1.4 a while ago... I'm not sure if I installed the development version or not. How can I tell? Are you using the 'normal' or 'dev' version? Ok. My math abilities are shot.... I know... That was two questions... lol

 If you have the approved and tested QB64 version it will say "Stable Release" in the "About" Menu Item under "Help" in the IDE.  I am using Stable Release.
Title: Re: Blackjack
Post by: johnno56 on July 05, 2020, 08:31:37 pm
1.4 'stable' it is... Thank you.
Title: Re: Blackjack
Post by: bplus on July 05, 2020, 11:14:34 pm
Here is that first version in SCREEN 0 with same functions as Big Brother Graphics versions ready to replace bplus participation with AI:
Code: QB64: [Select]
  1. OPTION _EXPLICIT ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. DEFINT A-Z '       Player's Blackjack pays double the bet set at the beginning of the game
  3. '2020-07-05 fix hit (it wasn't brolen), delete line card$ = inkey$ before loop
  4. ' force dealer to hit on 16 stay 17
  5. ' ties are push
  6. ' bring in double down option
  7. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  8. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  9.  
  10.  
  11. _TITLE "Blackjack Best B+ mod" ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics.
  12. CONST rank$ = "A23456789XJQK"
  13. CONST Player = 1
  14. CONST Dealer = 2
  15.  
  16. TYPE PlayerType
  17.     ID AS STRING
  18.     Hand AS STRING
  19.     Ace AS INTEGER
  20.     Total AS INTEGER
  21.     chips AS _INTEGER64
  22.     setBet AS _INTEGER64
  23.     bet AS _INTEGER64
  24.  
  25. DIM SHARED deck$(1 TO 52), Players(1 TO 2) AS PlayerType, deckIndex
  26.  
  27. DIM i, r, card$
  28. Players(Player).ID = "Player"
  29. Players(Dealer).ID = "Dealer"
  30. FOR i = 1 TO 52
  31.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  32. Players(Dealer).chips = -100
  33. Players(Player).chips = 100
  34. cp 8, "For this Blackjack Game, you start with 100 chips"
  35. cp 9, "and can bet any amount of them for each game."
  36. cp 10, "If you'd like to set your bet for each game now"
  37. cp 11, "enter that amount otherwise enter 0 "
  38. cp 12, "Dealer must hit on 16 or less."
  39. cp 13, "Blackjack pays 1.5 X the bet."
  40. cp 14, "Double down option available when you get 2 cards."
  41. cp 15, "It Doubles the bet and you get one more card."
  42.  
  43. LOCATE 17, 38: INPUT ""; Players(Player).setBet
  44.     IF Players(Player).setBet = 0 THEN
  45.         CLS
  46.         cp 10, "You have" + STR$(Players(Player).chips) + "."
  47.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", Players(Player).bet
  48.         IF Players(Player).bet = 0 THEN EXIT DO
  49.         IF Players(Player).bet >= Players(Player).chips THEN Players(Player).bet = Players(Player).chips
  50.     ELSE
  51.         IF Players(Player).chips < Players(Player).setBet THEN Players(Player).bet = Players(Player).chips ELSE Players(Player).bet = Players(Player).setBet
  52.     END IF
  53.     clearPlayers 'clears screen too
  54.     cp 4, "BLACKJACK    chips:" + STR$(Players(Player).chips) + "   betting:" + STR$(Players(Player).bet) + " chips."
  55.     FOR i = 52 TO 2 STEP -1 'shuffle
  56.         r = INT(RND * i) + 1
  57.         SWAP deck$(r), deck$(i)
  58.     NEXT
  59.     deckIndex = 0
  60.     FOR i = 1 TO 2 'each Player is dealt 2 cards
  61.         PlayerAddCard Player
  62.         IF i = 1 THEN cp 10, playerShow$(Player)
  63.         _DELAY 2
  64.         PlayerAddCard Dealer
  65.         IF i = 1 THEN cp 7, playerShow$(Dealer)
  66.         _DELAY 2
  67.     NEXT
  68.     cp 10, playerShow$(Player)
  69.     _DELAY 2
  70.     cp 7, Players(Dealer).ID + ": " + MID$(Players(Dealer).Hand, 1, 1) + " ?  Total = ??"
  71.     _DELAY 2
  72.     '   BJ  debug players having BJ
  73.     'Players(Dealer).Total = 21
  74.     'Players(Player).Total = 21
  75.     IF Players(Player).Total = 21 AND Players(Dealer).Total = 21 THEN
  76.         cp 7, playerShow$(Dealer) + " Blackjack!"
  77.         cp 10, playerShow$(Player) + " Blackjack!"
  78.         cp 13, "Push"
  79.         GOTO BJskip
  80.     ELSEIF Players(Player).Total = 21 THEN
  81.         cp 10, playerShow$(Player) + " Blackjack!"
  82.         Players(Player).chips = Players(Player).chips + 1.5 * Players(Player).bet
  83.         Players(Dealer).chips = Players(Dealer).chips - 1.5 * Players(Player).bet
  84.         cp 13, "You won" + STR$(2 * Players(Player).bet)
  85.         GOTO BJskip
  86.     ELSEIF Players(Dealer).Total = 21 THEN
  87.         cp 7, playerShow$(Dealer) + " Blackjack!"
  88.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  89.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  90.         cp 13, "You lost" + STR$(Players(Player).bet)
  91.         _DELAY 2
  92.         GOTO BJskip
  93.     END IF
  94.     WHILE Players(Player).Total < 21
  95.         IF LEN(Players(Player).Hand) = 2 THEN
  96.             cp 15, "Press h for Hit,   d for Double Down,   or any other to stay..."
  97.         ELSE
  98.             cp 15, "Press h for Hit, any other to stay..."
  99.         END IF
  100.         card$ = ""
  101.         WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND
  102.         cp 15, SPACE$(70) 'erase line
  103.         IF card$ = "h" THEN
  104.             PlayerAddCard Player
  105.             cp 11, SPACE$(50)
  106.             cp 10, playerShow$(Player)
  107.             _DELAY 2
  108.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'busted! skip dealer expose 2nd and play
  109.         ELSEIF card$ = "d" AND LEN(Players(Player).Hand) = 2 THEN
  110.             Players(Player).bet = 2 * Players(Player).bet
  111.             PlayerAddCard Player
  112.             cp 11, SPACE$(50)
  113.             cp 10, playerShow$(Player)
  114.             _DELAY 2
  115.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'bustest! skip dealer expose 2nd and play
  116.             EXIT WHILE
  117.         ELSE 'stayed
  118.             cp 11, SPACE$(50)
  119.             EXIT WHILE
  120.         END IF
  121.     WEND
  122.     cp 7, playerShow$(Dealer)
  123.     _DELAY 1
  124.     WHILE Players(Player).Total < 22 AND Players(Dealer).Total < 17
  125.         cp 8, "Dealer takes a card."
  126.         _DELAY 2
  127.         PlayerAddCard Dealer
  128.         cp 7, playerShow$(Dealer)
  129.         cp 8, SPACE$(50)
  130.         _DELAY 2
  131.     WEND
  132.     finalReckoning:
  133.     IF Players(Player).Total > 21 OR (Players(Player).Total < Players(Dealer).Total AND Players(Dealer).Total < 22) THEN
  134.         cp 13, "You lose" + STR$(Players(Player).bet)
  135.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  136.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  137.     ELSEIF Players(Player).Total = Players(Dealer).Total THEN
  138.         cp 13, "Push"
  139.     ELSE
  140.         cp 13, "You win!" + STR$(Players(Player).bet)
  141.         Players(Player).chips = Players(Player).chips + Players(Player).bet
  142.         Players(Dealer).chips = Players(Dealer).chips - Players(Player).bet
  143.     END IF
  144.  
  145.     BJskip:
  146.     IF Players(Player).chips = 0 THEN cp 15, "Out of chips!"
  147.     _DELAY 5
  148. LOOP UNTIL Players(Player).chips = 0
  149. cp 17, "Goodbye"
  150.  
  151. SUB clearPlayers
  152.     DIM i
  153.     CLS
  154.     FOR i = 1 TO 2
  155.         Players(i).Hand = ""
  156.         Players(i).Ace = 0
  157.         Players(i).Total = 0
  158.     NEXT
  159.  
  160. SUB PlayerAddCard (receiver) 'updates player's hand and total
  161.     DIM i AS INTEGER, cv AS INTEGER
  162.     deckIndex = deckIndex + 1
  163.     Players(receiver).Hand = Players(receiver).Hand + deck$(deckIndex)
  164.     IF deck$(deckIndex) = "A" THEN Players(receiver).Ace = -1
  165.     Players(receiver).Total = 0
  166.     FOR i = 1 TO LEN(Players(receiver).Hand)
  167.         IF INSTR(rank, MID$(Players(receiver).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(Players(receiver).Hand, i, 1))
  168.         Players(receiver).Total = Players(receiver).Total + cv
  169.     NEXT
  170.     IF Players(receiver).Total < 12 AND Players(receiver).Ace THEN Players(receiver).Total = Players(receiver).Total + 10
  171.  
  172. FUNCTION playerShow$ (shower) 'creates string with player name: hand Total = xx and "Busted!" if so.
  173.     DIM i AS INTEGER, S$
  174.     S$ = Players(shower).ID + ": "
  175.     FOR i = 1 TO LEN(Players(shower).Hand)
  176.         S$ = S$ + MID$(Players(shower).Hand, i, 1) + " "
  177.     NEXT
  178.     S$ = S$ + "Total =" + STR$(Players(shower).Total)
  179.     IF Players(shower).Total > 21 THEN S$ = S$ + " Busted!"
  180.     playerShow$ = S$
  181.  
  182. SUB cp (row, s AS STRING) 'print centered on row the string
  183.     LOCATE row, 1: PRINT SPACE$(80); 'clear row of text
  184.     LOCATE row, (80 - LEN(s)) / 2: PRINT s;
  185.  
Title: Re: Blackjack
Post by: johnno56 on July 05, 2020, 11:43:16 pm
Aww man... Two hands and I'm cleaned out... lol
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 12:20:16 am
I am now phoning it in with AI:
Code: QB64: [Select]
  1. OPTION _EXPLICIT ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. DEFINT A-Z '       Player's Blackjack pays double the bet set at the beginning of the game
  3. '2020-07-05 fix hit (it wasn't brolen), delete line card$ = inkey$ before loop
  4. ' force dealer to hit on 16 stay 17
  5. ' ties are push
  6. ' bring in double down option
  7. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  8. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  9. ' 2020-07-06 Installed AI and mods for it
  10.  
  11. _TITLE "Blackjack Best with AI" ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics.
  12. CONST rank$ = "A23456789XJQK"
  13. CONST Player = 1
  14. CONST Dealer = 2
  15.  
  16. TYPE PlayerType
  17.     ID AS STRING
  18.     Hand AS STRING
  19.     Ace AS INTEGER
  20.     Total AS INTEGER
  21.     chips AS _INTEGER64
  22.     setBet AS _INTEGER64
  23.     bet AS _INTEGER64
  24.  
  25. DIM SHARED deck$(1 TO 52), Players(1 TO 2) AS PlayerType, deckIndex, round
  26.  
  27. DIM i, r, card$
  28. Players(Player).ID = "Player"
  29. Players(Dealer).ID = "Dealer"
  30. FOR i = 1 TO 52
  31.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  32. Players(Dealer).chips = -100
  33. Players(Player).chips = 100
  34. cp 8, "For this Blackjack Game, you start with 100 chips"
  35. cp 9, "and can bet any amount of them for each game."
  36. cp 10, "If you'd like to set your bet for each game now"
  37. cp 11, "enter that amount otherwise enter 0, AI is setting at 2."
  38. cp 12, "Dealer must hit on 16 or less."
  39. cp 13, "Blackjack pays 1.5 X the bet."
  40. cp 14, "Double down option available when you get 2 cards."
  41. cp 15, "It Doubles the bet and you get one more card."
  42. cp 17, "press any to continue..."
  43. Players(Player).setBet = 2
  44. 'LOCATE 17, 38: INPUT ""; Players(Player).setBet
  45.     IF Players(Player).setBet = 0 THEN
  46.         CLS
  47.         cp 10, "You have" + STR$(Players(Player).chips) + "."
  48.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", Players(Player).bet
  49.         IF Players(Player).bet = 0 THEN EXIT DO
  50.         IF Players(Player).bet >= Players(Player).chips THEN Players(Player).bet = Players(Player).chips
  51.     ELSE
  52.         IF Players(Player).chips < Players(Player).setBet THEN Players(Player).bet = Players(Player).chips ELSE Players(Player).bet = Players(Player).setBet
  53.     END IF
  54.     clearPlayers 'clears screen too
  55.     cp 4, "BLACKJACK    chips:" + STR$(Players(Player).chips) + "   betting:" + STR$(Players(Player).bet) + " chips."
  56.     FOR i = 52 TO 2 STEP -1 'shuffle
  57.         r = INT(RND * i) + 1
  58.         SWAP deck$(r), deck$(i)
  59.     NEXT
  60.     deckIndex = 0
  61.     FOR i = 1 TO 2 'each Player is dealt 2 cards
  62.         PlayerAddCard Player
  63.         IF i = 1 THEN cp 10, playerShow$(Player)
  64.         _DELAY 1
  65.         PlayerAddCard Dealer
  66.         IF i = 1 THEN cp 7, playerShow$(Dealer)
  67.         _DELAY 1
  68.     NEXT
  69.     cp 10, playerShow$(Player)
  70.     _DELAY 1
  71.     cp 7, Players(Dealer).ID + ": " + MID$(Players(Dealer).Hand, 1, 1) + " ?  Total = ??"
  72.     _DELAY 1
  73.     '   BJ  debug players having BJ
  74.     'Players(Dealer).Total = 21
  75.     'Players(Player).Total = 21
  76.     IF Players(Player).Total = 21 AND Players(Dealer).Total = 21 THEN
  77.         cp 7, playerShow$(Dealer) + " Blackjack!"
  78.         cp 10, playerShow$(Player) + " Blackjack!"
  79.         cp 13, "Push"
  80.         GOTO BJskip
  81.     ELSEIF Players(Player).Total = 21 THEN
  82.         cp 10, playerShow$(Player) + " Blackjack!"
  83.         Players(Player).chips = Players(Player).chips + 1.5 * Players(Player).bet
  84.         Players(Dealer).chips = Players(Dealer).chips - 1.5 * Players(Player).bet
  85.         cp 13, "You won" + STR$(2 * Players(Player).bet)
  86.         GOTO BJskip
  87.     ELSEIF Players(Dealer).Total = 21 THEN
  88.         cp 7, playerShow$(Dealer) + " Blackjack!"
  89.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  90.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  91.         cp 13, "You lost" + STR$(Players(Player).bet)
  92.         _DELAY 1
  93.         GOTO BJskip
  94.     END IF
  95.     WHILE Players(Player).Total < 21
  96.         IF LEN(Players(Player).Hand) = 2 THEN
  97.             cp 15, "Press h for Hit,   d for Double Down,   or any other to stay..."
  98.         ELSE
  99.             cp 15, "Press h for Hit, any other to stay..."
  100.         END IF
  101.         'card$ = ""
  102.         'WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND   ' bplus calling it in now!
  103.         card$ = bplusAI$
  104.         IF card$ = "h" THEN cp 17, "Hit"
  105.         IF card$ = "d" THEN cp 17, "Double Down"
  106.         IF card$ <> "h" AND card$ <> "d" THEN cp 17, "Stay"
  107.         cp 15, SPACE$(70) 'erase line
  108.         _DELAY 2
  109.         cp 17, SPACE$(50)
  110.         IF card$ = "h" THEN
  111.             PlayerAddCard Player
  112.             'cp 11, SPACE$(50)
  113.             cp 10, playerShow$(Player)
  114.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'busted! skip dealer expose 2nd and play
  115.         ELSEIF card$ = "d" AND LEN(Players(Player).Hand) = 2 THEN
  116.             Players(Player).bet = 2 * Players(Player).bet
  117.             PlayerAddCard Player
  118.             'cp 11, SPACE$(50)
  119.             cp 10, playerShow$(Player)
  120.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'bustest! skip dealer expose 2nd and play
  121.             EXIT WHILE
  122.         ELSE 'stayed
  123.             ' cp 11, SPACE$(50)
  124.             EXIT WHILE
  125.         END IF
  126.     WEND
  127.     cp 7, playerShow$(Dealer)
  128.     _DELAY 1
  129.     WHILE Players(Player).Total < 22 AND Players(Dealer).Total < 17
  130.         cp 8, "Dealer takes a card."
  131.         _DELAY 1
  132.         PlayerAddCard Dealer
  133.         cp 7, playerShow$(Dealer)
  134.         cp 8, SPACE$(50)
  135.         _DELAY 1
  136.     WEND
  137.     finalReckoning:
  138.     IF Players(Player).Total > 21 OR (Players(Player).Total < Players(Dealer).Total AND Players(Dealer).Total < 22) THEN
  139.         cp 13, "You lose" + STR$(Players(Player).bet)
  140.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  141.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  142.     ELSEIF Players(Player).Total = Players(Dealer).Total THEN
  143.         cp 13, "Push"
  144.     ELSE
  145.         cp 13, "You win!" + STR$(Players(Player).bet)
  146.         Players(Player).chips = Players(Player).chips + Players(Player).bet
  147.         Players(Dealer).chips = Players(Dealer).chips - Players(Player).bet
  148.     END IF
  149.  
  150.     BJskip:
  151.     IF Players(Player).chips = 0 THEN cp 15, "Out of chips!"
  152.     _DELAY 2
  153. LOOP UNTIL Players(Player).chips = 0
  154. cp 17, "Goodbye"
  155.  
  156. SUB clearPlayers
  157.     DIM i
  158.     CLS
  159.     round = round + 1
  160.     cp 2, "Round:" + STR$(round)
  161.     FOR i = 1 TO 2
  162.         Players(i).Hand = ""
  163.         Players(i).Ace = 0
  164.         Players(i).Total = 0
  165.     NEXT
  166.  
  167. FUNCTION bplusAI$
  168.     SELECT CASE Players(Player).Total
  169.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  170.         CASE 10, 11
  171.             IF LEN(Players(Player).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  172.         CASE IS < 15
  173.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  174.         CASE ELSE: bplusAI$ = "Show me the money!"
  175.     END SELECT
  176.  
  177. SUB PlayerAddCard (receiver) 'updates player's hand and total
  178.     DIM i AS INTEGER, cv AS INTEGER
  179.     deckIndex = deckIndex + 1
  180.     Players(receiver).Hand = Players(receiver).Hand + deck$(deckIndex)
  181.     IF deck$(deckIndex) = "A" THEN Players(receiver).Ace = -1
  182.     Players(receiver).Total = 0
  183.     FOR i = 1 TO LEN(Players(receiver).Hand)
  184.         IF INSTR(rank, MID$(Players(receiver).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(Players(receiver).Hand, i, 1))
  185.         Players(receiver).Total = Players(receiver).Total + cv
  186.     NEXT
  187.     IF Players(receiver).Total < 12 AND Players(receiver).Ace THEN Players(receiver).Total = Players(receiver).Total + 10
  188.  
  189. FUNCTION playerShow$ (shower) 'creates string with player name: hand Total = xx and "Busted!" if so.
  190.     DIM i AS INTEGER, S$
  191.     S$ = Players(shower).ID + ": "
  192.     FOR i = 1 TO LEN(Players(shower).Hand)
  193.         S$ = S$ + MID$(Players(shower).Hand, i, 1) + " "
  194.     NEXT
  195.     S$ = S$ + "Total =" + STR$(Players(shower).Total)
  196.     IF Players(shower).Total > 21 THEN S$ = S$ + " Busted!"
  197.     playerShow$ = S$
  198.  
  199. SUB cp (row, s AS STRING) 'print centered on row the string
  200.     LOCATE row, 1: PRINT SPACE$(80); 'clear row of text
  201.     LOCATE row, (80 - LEN(s)) / 2: PRINT s;
  202.  

Started at 100 chips and always 2 chip bets. Currently: dang! I lost the screen at 60 Rounds I was ahead!

Nuts 2nd Session and I  am down a bits...
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 01:13:56 am
Session 3 is hanging in there.

Made a compact version for when watching YouTube.
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 11:09:13 am
There is something spooky between running the code in SCREEN 0 (just default) and using tiny graphics screen.

True I have only tested a long run once but the SCREEN 0 code holds it's own for a long time, watching it play I can't tell if if will loose in long run.

Running the code in a small graphics screen and it is easy to see the AI is loser and can't last the night.

And that's what happened.


I am getting superstitious! Today
 


BTW you start with 100 chips, plus or minus from that is how to judge progress in the session.


To all,

I am writing a program to test several AI's together against Dealer, if you'd like to be included I just need your AI$ sub routine:

my first as example:
Code: QB64: [Select]
  1. FUNCTION bplusAI$
  2.     SELECT CASE Players(Player).Total
  3.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  4.         CASE 10, 11
  5.             IF LEN(Players(Player).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  6.         CASE IS < 15
  7.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  8.         CASE ELSE: bplusAI$ = "Show me the money!"
  9.     END SELECT

Each player has a name or number in the Players() array to track their cards, total, setbet, current bet... so Players(player).Total is your current total for the hand you hold. Just use Players(Player).Total

You can check the Dealer's first card with something like DealerFirst$ =  LEFT$(Players(Dealer).hand, 1) - not allowed to peak at 2nd card. If you are holding an Ace there is a flag for that and be careful how Total is calculated (it assumes the first ace is 11 unless total goes over 21).

So your AI$ function has to return an "h" to hit, an "d" to double down when you have 2 cards that option is open, anything else is equivalent to Stay.


yep opposite from last night!
 
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 02:25:45 pm
Here is my compact AI tester with my 2nd AI, a mod of first that decreases probability to hit between 12 and 14 and refusing to Double Down if Dealer shows an Ace:
Code: QB64: [Select]
  1. OPTION _EXPLICIT ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. DEFINT A-Z '       Player's Blackjack pays double the bet set at the beginning of the game
  3. '2020-07-05 fix hit (it wasn't brolen), delete line card$ = inkey$ before loop
  4. ' force dealer to hit on 16 stay 17
  5. ' ties are push
  6. ' bring in double down option
  7. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  8. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  9. ' 2020-07-06 Installed AI and mods for it
  10. ' 2020-07-06 new Compact Tester with 2nd AI
  11.  
  12. _TITLE "Blackjack AI Tester" ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics.
  13. CONST rank$ = "A23456789XJQK"
  14. CONST Player = 1
  15. CONST Dealer = 2
  16.  
  17. TYPE PlayerType
  18.     ID AS STRING
  19.     Hand AS STRING
  20.     Ace AS INTEGER
  21.     Total AS INTEGER
  22.     chips AS _INTEGER64
  23.     setBet AS _INTEGER64
  24.     bet AS _INTEGER64
  25.  
  26. DIM SHARED deck$(1 TO 52), Players(1 TO 2) AS PlayerType, deckIndex, round
  27. SCREEN _NEWIMAGE(400, 300, 32)
  28. DIM i, r, card$
  29. Players(Player).ID = "Player"
  30. Players(Dealer).ID = "Dealer"
  31. FOR i = 1 TO 52
  32.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  33. Players(Dealer).chips = -100
  34. Players(Player).chips = 100
  35. 'bbbbb"1234567890123456789012345678901234567890
  36. cp 4, "*** BJ Compact AI Tester ***"
  37. cp 6, "You start with 100 chips."
  38. cp 7, "AI sets bet amount to 2."
  39. cp 8, "Dealer must hit on 16 or less."
  40. cp 9, "Blackjack pays 1.5 X the bet."
  41. cp 10, "Double down option available"
  42. cp 11, "when you get 2 cards."
  43. cp 12, "It Doubles the bet and you get one"
  44. cp 13, "more card."
  45. cp 17, "press any to continue..."
  46. Players(Player).setBet = 2
  47. 'LOCATE 17, 38: INPUT ""; Players(Player).setBet
  48.     IF Players(Player).setBet = 0 THEN
  49.         CLS
  50.         cp 10, "You have" + STR$(Players(Player).chips) + "."
  51.         LOCATE 11, 25: INPUT "(0 quits) Enter your bet > ", Players(Player).bet
  52.         IF Players(Player).bet = 0 THEN EXIT DO
  53.         IF Players(Player).bet >= Players(Player).chips THEN Players(Player).bet = Players(Player).chips
  54.     ELSE
  55.         IF Players(Player).chips < Players(Player).setBet THEN Players(Player).bet = Players(Player).chips ELSE Players(Player).bet = Players(Player).setBet
  56.     END IF
  57.     clearPlayers 'clears screen too
  58.     cp 4, "Chips:" + STR$(Players(Player).chips) + "   betting:" + STR$(Players(Player).bet) + " chips."
  59.     FOR i = 52 TO 2 STEP -1 'shuffle
  60.         r = INT(RND * i) + 1
  61.         SWAP deck$(r), deck$(i)
  62.     NEXT
  63.     deckIndex = 0
  64.     FOR i = 1 TO 2 'each Player is dealt 2 cards
  65.         PlayerAddCard Player
  66.         IF i = 1 THEN cp 10, playerShow$(Player)
  67.         _DELAY 1
  68.         PlayerAddCard Dealer
  69.         IF i = 1 THEN cp 7, playerShow$(Dealer)
  70.         _DELAY 1
  71.     NEXT
  72.     cp 10, playerShow$(Player)
  73.     _DELAY 1
  74.     cp 7, Players(Dealer).ID + ": " + MID$(Players(Dealer).Hand, 1, 1) + " ?  Total = ??"
  75.     _DELAY 1
  76.     '   BJ  debug players having BJ
  77.     'Players(Dealer).Total = 21
  78.     'Players(Player).Total = 21
  79.     IF Players(Player).Total = 21 AND Players(Dealer).Total = 21 THEN
  80.         cp 7, playerShow$(Dealer) + " Blackjack!"
  81.         cp 10, playerShow$(Player) + " Blackjack!"
  82.         cp 13, "Push"
  83.         GOTO BJskip
  84.     ELSEIF Players(Player).Total = 21 THEN
  85.         cp 10, playerShow$(Player) + " Blackjack!"
  86.         Players(Player).chips = Players(Player).chips + 1.5 * Players(Player).bet
  87.         Players(Dealer).chips = Players(Dealer).chips - 1.5 * Players(Player).bet
  88.         cp 13, "You won" + STR$(2 * Players(Player).bet)
  89.         GOTO BJskip
  90.     ELSEIF Players(Dealer).Total = 21 THEN
  91.         cp 7, playerShow$(Dealer) + " Blackjack!"
  92.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  93.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  94.         cp 13, "You lost" + STR$(Players(Player).bet)
  95.         _DELAY 1
  96.         GOTO BJskip
  97.     END IF
  98.     WHILE Players(Player).Total < 21
  99.         IF LEN(Players(Player).Hand) = 2 THEN
  100.             cp 15, "Hit Double or Stay"
  101.         ELSE
  102.             cp 15, "Hit or Stay"
  103.         END IF
  104.         'card$ = ""
  105.         'WHILE LEN(card$) = 0: card$ = INKEY$: _LIMIT 60: WEND   ' bplus calling it in now!
  106.         card$ = bplusAI$
  107.         IF card$ = "h" THEN cp 17, "Hit"
  108.         IF card$ = "d" THEN cp 17, "Double Down"
  109.         IF card$ <> "h" AND card$ <> "d" THEN cp 17, "Stay"
  110.         cp 15, SPACE$(39) 'erase line
  111.         _DELAY 2
  112.         cp 17, SPACE$(39)
  113.         IF card$ = "h" THEN
  114.             PlayerAddCard Player
  115.             'cp 11, SPACE$(50)
  116.             cp 10, playerShow$(Player)
  117.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'busted! skip dealer expose 2nd and play
  118.         ELSEIF card$ = "d" AND LEN(Players(Player).Hand) = 2 THEN
  119.             Players(Player).bet = 2 * Players(Player).bet
  120.             PlayerAddCard Player
  121.             'cp 11, SPACE$(50)
  122.             cp 10, playerShow$(Player)
  123.             IF Players(Player).Total > 21 THEN GOTO finalReckoning 'bustest! skip dealer expose 2nd and play
  124.             EXIT WHILE
  125.         ELSE 'stayed
  126.             ' cp 11, SPACE$(50)
  127.             EXIT WHILE
  128.         END IF
  129.     WEND
  130.     cp 7, playerShow$(Dealer)
  131.     _DELAY 1
  132.     WHILE Players(Player).Total < 22 AND Players(Dealer).Total < 17
  133.         cp 8, "Dealer takes a card."
  134.         _DELAY 1
  135.         PlayerAddCard Dealer
  136.         cp 7, playerShow$(Dealer)
  137.         cp 8, SPACE$(39)
  138.         _DELAY 1
  139.     WEND
  140.     finalReckoning:
  141.     IF Players(Player).Total > 21 OR (Players(Player).Total < Players(Dealer).Total AND Players(Dealer).Total < 22) THEN
  142.         cp 13, "You lose" + STR$(Players(Player).bet)
  143.         Players(Player).chips = Players(Player).chips - Players(Player).bet
  144.         Players(Dealer).chips = Players(Dealer).chips + Players(Player).bet
  145.     ELSEIF Players(Player).Total = Players(Dealer).Total THEN
  146.         cp 13, "Push"
  147.     ELSE
  148.         cp 13, "You win!" + STR$(Players(Player).bet)
  149.         Players(Player).chips = Players(Player).chips + Players(Player).bet
  150.         Players(Dealer).chips = Players(Dealer).chips - Players(Player).bet
  151.     END IF
  152.  
  153.     BJskip:
  154.     IF Players(Player).chips = 0 THEN cp 15, "Out of chips!"
  155.     _DELAY 2
  156. LOOP UNTIL Players(Player).chips = 0
  157. cp 17, "Goodbye"
  158.  
  159. SUB clearPlayers
  160.     DIM i
  161.     CLS
  162.     round = round + 1
  163.     cp 2, "Round:" + STR$(round)
  164.     FOR i = 1 TO 2
  165.         Players(i).Hand = ""
  166.         Players(i).Ace = 0
  167.         Players(i).Total = 0
  168.     NEXT
  169.  
  170. 'FUNCTION bplusAI$     ' first try
  171. '    SELECT CASE Players(Player).Total
  172. '        CASE IS < 10: bplusAI$ = "h" 'no caps!
  173. '        CASE 10, 11
  174. '            IF LEN(Players(Player).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  175. '        CASE IS < 15
  176. '            IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  177. '        CASE ELSE: bplusAI$ = "Show me the money!"
  178. '    END SELECT
  179. 'END FUNCTION
  180.  
  181. FUNCTION bplusAI$ 'after trying first want to try this make it more likely to hit on 12 than 13, 14...
  182.     SELECT CASE Players(Player).Total
  183.         CASE IS < 9: bplusAI$ = "h" 'no caps!
  184.         CASE 9, 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer
  185.             IF LEN(Players(Player).Hand) = 2 AND LEFT$(Players(Dealer).Hand, 1) <> "A" THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  186.         CASE 12: IF RND < .75 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  187.         CASE 13: IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  188.         CASE 14: IF RND < .25 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  189.         CASE ELSE: bplusAI$ = "Show me the money!"
  190.     END SELECT
  191.  
  192. SUB PlayerAddCard (receiver) 'updates player's hand and total
  193.     DIM i AS INTEGER, cv AS INTEGER
  194.     deckIndex = deckIndex + 1
  195.     Players(receiver).Hand = Players(receiver).Hand + deck$(deckIndex)
  196.     IF deck$(deckIndex) = "A" THEN Players(receiver).Ace = -1
  197.     Players(receiver).Total = 0
  198.     FOR i = 1 TO LEN(Players(receiver).Hand)
  199.         IF INSTR(rank, MID$(Players(receiver).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(Players(receiver).Hand, i, 1))
  200.         Players(receiver).Total = Players(receiver).Total + cv
  201.     NEXT
  202.     IF Players(receiver).Total < 12 AND Players(receiver).Ace THEN Players(receiver).Total = Players(receiver).Total + 10
  203.  
  204. FUNCTION playerShow$ (shower) 'creates string with player name: hand Total = xx and "Busted!" if so.
  205.     DIM i AS INTEGER, S$
  206.     S$ = Players(shower).ID + ": "
  207.     FOR i = 1 TO LEN(Players(shower).Hand)
  208.         S$ = S$ + MID$(Players(shower).Hand, i, 1) + " "
  209.     NEXT
  210.     S$ = S$ + "Total =" + STR$(Players(shower).Total)
  211.     IF Players(shower).Total > 21 THEN S$ = S$ + " Bust"
  212.     playerShow$ = S$
  213.  
  214. SUB cp (row, s AS STRING) 'print centered on row the string
  215.     LOCATE row, 1: PRINT SPACE$(50); 'clear row of text
  216.     LOCATE row, (50 - LEN(s)) / 2: PRINT s;
  217.  

Update 250 Rounds one of 4 still winning:


Final Results, Rounds lasted: 327, 410, 649, 899.
Title: Re: Blackjack
Post by: johnno56 on July 06, 2020, 06:48:30 pm
Umm... 252 rounds? Can I assume that one round is equivalent to one hand? If so, 'that' is a lot of card games... With such devotion to a specific task, may I suggest either a pastime of jigsaws or golf ball dimple counting?  I could probably attempt 50 rounds, but unfortunately, I do not have enough coffee stockpiled to get me through it... lol

With your coloured version, may I suggest a background of rgb(31,45,80) (a kind of slate-blue) with either white or light blue text? Pure blue, for me anyway, is quite bright on 'pre-coffee' eyes... lol

I would be happy to help but I'm not that familiar with coding AI. Crumbs, I have enough trouble with my 'I'... lol
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 07:13:09 pm
Hi @johnno56

Here is my first AI, all I need to know is when to hit = "h", when to double down (after first 2 cards) = "d" else the code assumes you want to stay = CASE ELSE neither "h" or "d"

Players(Player).Total = current card total in your hand
IF LEFT$(Players(Dealer).Cards, 1) = "A" THEN ' Dealer is showing an Ace
IF LEN(Players(Player).Hand) = 2 THEN ' player only has 2 cards so Double Down Option is available

Code: QB64: [Select]
  1. 'FUNCTION bplusAI$     ' first try
  2. '    SELECT CASE Players(Player).Total
  3. '        CASE IS < 10: bplusAI$ = "h" 'no caps!  == If my Total < 10 the hit me!
  4. '        CASE 10, 11 '=================== If my Total is 10 or 11 then Double down if I have only 2 cards else hit me!
  5. '            IF LEN(Players(Player).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  6. '        CASE IS < 15 ' ================== If my Total < 15 toss a coin to hit or stay
  7. '            IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  8. '        CASE ELSE: bplusAI$ = "Show me the money!"   "If my Total > 14 just Stay! maybe the Dealer will Bust
  9. '    END SELECT
  10. 'END FUNCTION
  11.  
Title: Re: Blackjack
Post by: johnno56 on July 06, 2020, 08:25:38 pm
I am no card player, but if it was me and I could see the dealers' card is less than say 6, I would stay on 15 because the odds are good that the dealers' next card would be less than 9. If the dealer's card is closer to 9 then I would probably reconsider staying. eg: If the dealer's first card is 6, then yes, stay. If 7 or 8, may be not stay - toss coin 50/50. If 9 or more, definitely not stay - hit.

But that's me...  I hope that I have explained all that properly?
Title: Re: Blackjack
Post by: bplus on July 06, 2020, 08:33:30 pm
OK I can code that for you. Do you ever try Double Down?

Also do you know Aces are little insurance agents? That is the first one is taken as 11 until or unless you go over 21 then it's 1 and you get a 2nd chance with another hit.

So Double Down when you have an Ace might be a waste of it and not wise if Dealer shows an Ace.
Title: Re: Blackjack
Post by: SMcNeill on July 06, 2020, 08:43:21 pm
I'd go with some simple kid style logic for a random AI:  "If the dealer stays at 17, then as long as I stay at 18+, I have a good chance to beat them."
Title: Re: Blackjack
Post by: johnno56 on July 06, 2020, 09:48:18 pm
I think Steve may be right, in respect to keeping it simple. My idea may not be the best to use... lol  I have used DD in the past. Usually if both cards add up to either 10 or 11. That didn't happen all that often, but when it did, DD was the way to go...
Title: Re: Blackjack
Post by: bplus on July 07, 2020, 02:21:37 am
Thanks for input on AI guys! For Steve I used the absolutely simplest thing I could think of. Ha! it did pretty good on first round of tests.

AI multi Tester:
Code: QB64: [Select]
  1. ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. '2020-07-05 fix hit (it wasn't broken), delete line card$ = inkey$ before loop
  3. ' force dealer to hit on 16 stay 17
  4. ' ties are push
  5. ' bring in double down option
  6. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  7. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  8. ' 2020-07-06 Installed AI and mods for it
  9. ' 2020-07-06 new Compact Tester with 2nd AI
  10. ' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester
  11. '            add in allot of code worked out in Blackjack with Bots 2019-06-07
  12. '            Yes, major overhaul of last year bot code which was/is neat!
  13. '            Thanks Johnno and Steve for some interesting AI ideas to try!
  14.  
  15.  
  16. DEFINT A-Z
  17.  
  18. _TITLE "Blackjack Multi AI Tester" ' started 2019-06-06, revisit and match functions with B+J Balckjack with audio and graphics.
  19.  
  20. CONST nPlayers = 5 'dealer counts as the last player   this number depends on how many AI's to test
  21. CONST xmax = 800, ymax = 500, margin = 4
  22. CONST rank$ = "A23456789XJQK" 'for building deck and figuring Totals
  23. CONST bH = 14, bW = 20 ' box height and box width in rows and columns
  24. CONST white = &HFFFFFFFF, black = &HFF000000, bc = &HFF008822, fc = &HFFCCCCFF
  25.  
  26. TYPE PlayerType
  27.     ID AS STRING '        name of bot including dealer bot
  28.     Col AS INTEGER '      left corner column
  29.     Row AS INTEGER '      top row
  30.     FC AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White
  31.     BC AS _UNSIGNED LONG 'random light and dark opposite print FC
  32.     Hand AS STRING '      cards are 1 char strings 10 is X
  33.     Ace AS INTEGER '      flag has ace for totalling hand
  34.     Bust AS INTEGER '     flag for final reckoning
  35.     BJ AS INTEGER '       flag for final reckoning
  36.     Total AS INTEGER '    card total of hand
  37.     Chips AS _INTEGER64 ' players status
  38.     SetBet AS _INTEGER64 'regular bet amount
  39.     Bet AS _INTEGER64 '   players bet each round
  40.  
  41. DIM SHARED deck$(1 TO 52), p(1 TO nPlayers) AS PlayerType, deckIndex, round, allOut, player, blockDealer
  42. SCREEN _NEWIMAGE(xmax, ymax, 32)
  43. DIM i, card$
  44. initGame
  45. 'FOR i = 1 TO nPlayers
  46. '    showPlayer i
  47. 'NEXT
  48.     clearPlayers 'clears screen too and shuffles deck
  49.  
  50.     FOR i = 1 TO 2
  51.         FOR player = 1 TO nPlayers 'each Player is dealt 2 cards
  52.             IF player <> nPlayers THEN
  53.                 IF p(player).Chips > 0 THEN
  54.                     allOut = 0 'signal everyone is out of chips is false
  55.                     PlayerAddCard player
  56.                     showPlayer player
  57.                     _DELAY .5
  58.                 END IF
  59.             ELSE
  60.                 IF allOut THEN
  61.                     EXIT DO
  62.                 ELSE
  63.                     PlayerAddCard player
  64.                     showPlayer player
  65.                     _DELAY .5
  66.                 END IF
  67.             END IF
  68.         NEXT
  69.     NEXT
  70.  
  71.     IF p(nPlayers).BJ = 0 THEN 'dealer does not have BJ
  72.         FOR player = 1 TO nPlayers - 1
  73.             showPlayer player
  74.             _DELAY 1
  75.             WHILE p(player).Total < 21
  76.                 SELECT CASE player ' this has to be coded for exactly all nPlayers - 1
  77.                     CASE 1: card$ = Johnno$(player)
  78.                     CASE 2: card$ = Steve$(player)
  79.                     CASE 3: card$ = bplusAI$(player)
  80.                     CASE 4: card$ = bplusAI2$(player)
  81.                 END SELECT
  82.                 IF card$ = "h" THEN cp player, 13, "Hit"
  83.                 IF card$ = "d" THEN cp player, 13, "Double Down"
  84.                 IF card$ <> "h" AND card$ <> "d" THEN cp player, 13, "Stay"
  85.                 _DELAY 2
  86.                 IF card$ = "h" THEN
  87.                     PlayerAddCard player
  88.                     showPlayer player
  89.                     _DELAY 1
  90.                 ELSEIF card$ = "d" AND LEN(p(player).Hand) = 2 THEN
  91.                     p(player).Bet = 2 * p(player).Bet
  92.                     PlayerAddCard player
  93.                     showPlayer player
  94.                     _DELAY 1
  95.                     EXIT WHILE
  96.                 ELSE 'stayed
  97.                     showPlayer player
  98.                     _DELAY 1
  99.                     EXIT WHILE
  100.                 END IF
  101.             WEND
  102.         NEXT
  103.     END IF
  104.  
  105.     blockDealer = 0
  106.     showPlayer nPlayers
  107.     _DELAY 1
  108.     WHILE p(nPlayers).Total < 17
  109.         cp nPlayers, 11, "Dealer takes a card."
  110.         _DELAY 1
  111.         PlayerAddCard nPlayers
  112.         showPlayer nPlayers
  113.         _DELAY 1
  114.     WEND
  115.  
  116.     '    final Reckoning
  117.     FOR player = 1 TO nPlayers - 1
  118.         showPlayer player
  119.         IF p(player).Total > 21 OR (p(player).Total < p(nPlayers).Total AND p(nPlayers).Total < 22) THEN
  120.             cp player, 13, "Lost" + STR$(p(player).Bet)
  121.             p(player).Chips = p(player).Chips - p(player).Bet
  122.             p(nPlayers).Chips = p(nPlayers).Chips + p(player).Bet
  123.         ELSEIF p(player).Total = p(nPlayers).Total AND p(player).BJ = 0 THEN
  124.             cp player, 13, "Push"
  125.         ELSE
  126.             IF p(player).BJ THEN
  127.                 cp player, 13, "Win!" + STR$(p(player).Bet + .5 * p(player).Bet)
  128.                 p(player).Chips = p(player).Chips + p(player).Bet + .5 * p(player).Bet
  129.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet - .5 * p(player).Bet
  130.             ELSE
  131.                 cp player, 13, "Win!" + STR$(p(player).Bet)
  132.                 p(player).Chips = p(player).Chips + p(player).Bet
  133.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet
  134.             END IF
  135.         END IF
  136.         IF p(player).Chips = 0 THEN cp player, 14, "Out of chips!"
  137.         _DELAY 3
  138.     NEXT
  139. LOOP UNTIL allOut
  140.  
  141. SUB clearPlayers
  142.     DIM i
  143.     COLOR fc, bc: CLS
  144.     round = round + 1: allOut = -1
  145.     FOR i = 1 TO nPlayers
  146.         p(i).Hand = ""
  147.         p(i).Ace = 0
  148.         p(i).Total = 0
  149.         p(i).BJ = 0
  150.         p(i).Bust = 0
  151.         'because of double down option I have to reset bet during play and set it back at each new round
  152.         'make sure we aren't betting more than our chips count at least to start
  153.         IF p(i).Chips < p(i).SetBet THEN p(i).Bet = p(i).Chips ELSE p(i).Bet = p(i).SetBet
  154.     NEXT
  155.     FOR i = 52 TO 2 STEP -1 'shuffle
  156.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  157.     NEXT
  158.     'deck$(5) = "A": deck$(10) = "J"  'check immediate show of Blackjack for dealer
  159.     deckIndex = 0: blockDealer = -1
  160.  
  161. FUNCTION bplusAI$ (pn) ' first try
  162.     SELECT CASE p(pn).Total
  163.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  164.         CASE 10, 11
  165.             IF LEN(p(pn).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  166.         CASE IS < 15
  167.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  168.         CASE ELSE: bplusAI$ = "Show me the money!"
  169.     END SELECT
  170.  
  171. FUNCTION bplusAI2$ (pN) 'after trying first want to try this make it more likely to hit on 12 than 13, 14...
  172.     SELECT CASE p(pN).Total
  173.         CASE IS < 10: bplusAI2$ = "h" 'no caps!
  174.         CASE 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer
  175.             IF LEN(p(pN).Hand) = 2 AND LEFT$(p(nPlayers).Hand, 1) <> "A" THEN bplusAI2$ = "d" ELSE bplusAI2$ = "h"
  176.         CASE 12: IF RND < .75 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  177.         CASE 13: IF RND < .5 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  178.         CASE 14: IF RND < .25 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  179.         CASE ELSE: bplusAI2$ = "Show me the money!"
  180.     END SELECT
  181.  
  182. FUNCTION Johnno$ (pN)
  183.     IF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) = 2 THEN
  184.         Johnno$ = "d"
  185.     ELSEIF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) <> 2 THEN
  186.         Johnno$ = "h"
  187.     ELSEIF 12 <= p(pN).Total AND p(pN).Total <= 15 THEN
  188.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  189.             CASE "A", "K", "Q", "J", "X", "9": Johnno$ = "h"
  190.             CASE "7", "8": IF RND < .5 THEN Johnno$ = "h"
  191.             CASE ELSE: Johnno$ = "Hope to Bust em"
  192.         END SELECT
  193.     ELSEIF p(pN).Total < 12 THEN
  194.         Johnno$ = "h"
  195.     ELSE
  196.         Johnno$ = "Stay"
  197.     END IF
  198.  
  199. FUNCTION Steve$ (pN) 'how simple is this! never bust make dealer work for it
  200.     IF p(pN).Total < 12 THEN Steve$ = "h"
  201.  
  202. SUB PlayerAddCard (rec) 'updates player's hand and total
  203.     DIM i AS INTEGER, cv AS INTEGER
  204.     deckIndex = deckIndex + 1
  205.     p(rec).Hand = p(rec).Hand + deck$(deckIndex)
  206.     IF deck$(deckIndex) = "A" THEN p(rec).Ace = -1
  207.     p(rec).Total = 0
  208.     FOR i = 1 TO LEN(p(rec).Hand)
  209.         IF INSTR(rank$, MID$(p(rec).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank$, MID$(p(rec).Hand, i, 1))
  210.         p(rec).Total = p(rec).Total + cv
  211.     NEXT
  212.     IF p(rec).Total < 12 AND p(rec).Ace THEN p(rec).Total = p(rec).Total + 10
  213.     IF LEN(p(rec).Hand) = 2 AND p(rec).Total = 21 THEN p(rec).BJ = -1
  214.     IF p(rec).Total > 21 THEN p(rec).Bust = -1
  215.  
  216. SUB showPlayer (nPlayer)
  217.     DIM i AS INTEGER, S$
  218.     COLOR p(nPlayer).FC, p(nPlayer).BC
  219.     FOR i = 0 TO bH - 1 'clear our block
  220.         'PRINT p(nPlayer).Row + i, p(nPlayer).Col
  221.         LOCATE p(nPlayer).Row + i, p(nPlayer).Col: PRINT SPACE$(bW);
  222.     NEXT
  223.     cp nPlayer, 1, "Round:" + STR$(round)
  224.     cp nPlayer, 3, p(nPlayer).ID
  225.     cp nPlayer, 5, "Chips:" + STR$(p(nPlayer).Chips)
  226.     IF nPlayer <> nPlayers THEN cp nPlayer, 6, "Bet:" + STR$(p(nPlayer).Bet)
  227.     FOR i = 1 TO LEN(p(nPlayer).Hand) 'with 12 aces could get very long hands
  228.         S$ = S$ + MID$(p(nPlayer).Hand, i, 1) + " "
  229.     NEXT
  230.     cp nPlayer, 8, "___Hand___"
  231.     IF nPlayer = nPlayers AND LEN(p(nPlayer).Hand) = 2 AND p(nPlayer).Total <> 21 AND blockDealer THEN
  232.         S$ = LEFT$(S$, 2) + "?"
  233.         cp nPlayer, 9, S$
  234.         cp nPlayer, 10, "Total: ??"
  235.     ELSE
  236.         cp nPlayer, 9, S$
  237.         cp nPlayer, 10, "Total:" + STR$(p(nPlayer).Total)
  238.     END IF
  239.  
  240.     IF p(nPlayer).Bust THEN cp nPlayer, 11, "Busted"
  241.     IF p(nPlayer).BJ THEN cp nPlayer, 11, "Blackjack"
  242.  
  243. SUB initGame 'the stuff that never changes
  244.     DIM i, spacer
  245.     FOR i = 1 TO 52 'get deck ready
  246.         deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  247.     NEXT
  248.  
  249.     'for printing in each players window area of screen = blackjack table
  250.     'xmax/8 =  2*margin + bW *(nplayers -1) + spacer *(nplayer-2)
  251.     spacer = ((xmax / 8) - margin - bW * (nPlayers - 1)) / (nPlayers - 2)
  252.  
  253.     FOR i = 1 TO nPlayers
  254.         IF i <> nPlayers THEN
  255.             SELECT CASE i
  256.                 CASE 1: p(i).ID = "Johnno"
  257.                 CASE 2: p(i).ID = "Steve"
  258.                 CASE 3: p(i).ID = "bplus AI"
  259.                 CASE 4: p(i).ID = "bplus AI2"
  260.             END SELECT
  261.             p(i).Col = margin + (i - 1) * (spacer + bW)
  262.             p(i).Row = 18
  263.             p(i).Chips = 100
  264.             p(i).SetBet = 2
  265.             IF i MOD 2 THEN
  266.                 p(i).BC = _RGB32(RND * 128, RND * 128, RND * 128)
  267.             ELSE
  268.                 p(i).BC = _RGB32(RND * 128 + 127, RND * 128 + 127, RND * 128 + 127)
  269.             END IF
  270.         ELSE
  271.             p(i).ID = "Dealer"
  272.             p(i).Col = (xmax / 8 - bW) / 2
  273.             p(i).Row = 2
  274.             p(i).Chips = -100 * (nPlayers - 1)
  275.             IF i MOD 2 THEN p(i).BC = &HFF000000 ELSE p(i).BC = &HFFFFFFFF
  276.         END IF
  277.         IF i MOD 2 THEN p(i).FC = &HFFFFFFFF ELSE p(i).FC = &HFF000000
  278.     NEXT
  279.  
  280.     'ask the user / YOU what e prefers for betting
  281.     COLOR fc, bc: CLS
  282.     cp 0, 10, "*** Blackjack Multi AI Tester ***"
  283.     cp 0, 12, "Each AI bot starts with 100 chips and bets 2 each round."
  284.     cp 0, 13, "Dealer must hit on 16 or less."
  285.     cp 0, 14, "Blackjack pays 1.5 X the bet."
  286.     cp 0, 15, "Double down option available when you get 2 cards."
  287.     cp 0, 16, "It Doubles the bet and you get one more card."
  288.     cp 0, 20, "press any to continue..."
  289.     SLEEP
  290.  
  291. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  292.     IF nPlayer THEN
  293.         COLOR p(nPlayer).FC, p(nPlayer).BC
  294.         LOCATE p(nPlayer).Row + row, p(nPlayer).Col + (bW - LEN(s)) / 2: PRINT s;
  295.     ELSE
  296.         COLOR fc, bc
  297.         LOCATE row, (xmax / 8 - LEN(s)) / 2: PRINT s;
  298.     END IF
  299.  
  300.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Blackjack
Post by: johnno56 on July 07, 2020, 08:46:21 am
I know. I know. I'm not a fan of Star Wars but... Darth Vader. Episode IV: A New Hope. "Impressive. Most impressive."
Title: Re: Blackjack
Post by: George McGinn on July 07, 2020, 11:15:45 am
Over on my iPad, I have a deck shuffling program which is very simple. I create a random array with numbers from 1 to 52, and these numbers serve as an index to another table that holds the card number and suit. I use graphics (UNICODE or the iPad's expanded ASCII Code) and the suit is the same size as the number.

I can bring it over to QB64 and get it to work if you are interested in it. I can even create options where you can create a shuffled array with 4 to 8 decks if you can use it.
Title: Re: Blackjack
Post by: bplus on July 07, 2020, 11:20:19 am
Over on my iPad, I have a deck shuffling program which is very simple. I create a random array with numbers from 1 to 52, and these numbers serve as an index to another table that holds the card number and suit. I use graphics (UNICODE or the iPad's expanded ASCII Code) and the suit is the same size as the number.

I can bring it over to QB64 and get it to work if you are interested in it. I can even create options where you can create a shuffled array with 4 to 8 decks if you can use it.

Can shuffle be simpler than this from my last code post, from all my code that needs shuffle)?
Code: QB64: [Select]
  1.     FOR i = 52 TO 2 STEP -1 'shuffle
  2.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  3.     NEXT
  4.  

Welcome aboard George!
Title: Re: Blackjack
Post by: Cobalt on July 07, 2020, 12:16:13 pm
So is this like an  official  group project or what? how many different people have added actual material for this? 4-5? or am I just skim reading the wrong parts?
Title: Re: Blackjack
Post by: bplus on July 07, 2020, 12:44:42 pm
So is this like an  official  group project or what? how many different people have added actual material for this? 4-5? or am I just skim reading the wrong parts?

Hi @Cobalt

Currently I am running code in which you can test your own AI. Started around reply #195. I think we have finished for awhile the beautiful graphics and audio game. (Check Best Answer for the latest on that.)

The AI should be fairly easy to write, just make a Function that returns "h" for hit or "d" for double down anything else is signal to stay.

The players() array name has been changed to p() array and the Dealers player number = nPlayers check code in next reply.

Love to get your input, if you have an idea you can just describe it and I can write it up or take a shot at your own Function.


Title: Re: Blackjack
Post by: bplus on July 07, 2020, 12:49:29 pm
I have updated my AI tester for more AI players. Now they overlap when AI players exceed 4 or 5 but we are OK, you can mouse over a certain player and see how they are doing while the Dealer is running the game. Do try and stay out of way of the updating with your mouse.

Code: QB64: [Select]
  1. ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. '2020-07-05 fix hit (it wasn't broken), delete line card$ = inkey$ before loop
  3. ' force dealer to hit on 16 stay 17
  4. ' ties are push
  5. ' bring in double down option
  6. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  7. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  8. ' 2020-07-06 Installed AI and mods for it
  9. ' 2020-07-06 new Compact Tester with 2nd AI
  10. ' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester
  11. '            add in allot of code worked out in Blackjack with Bots 2019-06-07
  12. '            Yes, major overhaul of last year bot code which was/is neat!
  13. '            Thanks Johnno and Steve for some interesting AI ideas to try!
  14. ' 2020-07-07 for Blackjack Multi AI Tester #2, I hope to do something kind of interesting with displaying players
  15. '            Yes Mouse over a player you want to check on but try and stay out of way of updating.
  16.  
  17. DEFINT A-Z
  18.  
  19. _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.
  20.  
  21. CONST nPlayers = 9 'dealer counts as the last player   this number depends on how many AI's to test
  22. CONST xmax = 800, ymax = 500, margin = 4
  23. CONST rank$ = "A23456789XJQK" 'for building deck and figuring Totals
  24. CONST bH = 14, bW = 20 ' box height and box width in rows and columns
  25. CONST white = &HFFFFFFFF, black = &HFF000000, bc = &HFF008822, fc = &HFFCCCCFF
  26.  
  27. TYPE PlayerType
  28.     ID AS STRING '        name of bot including dealer bot
  29.     Col AS INTEGER '      left corner column
  30.     Row AS INTEGER '      top row
  31.     FC AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White
  32.     BC AS _UNSIGNED LONG 'random light and dark opposite print FC
  33.     Hand AS STRING '      cards are 1 char strings 10 is X
  34.     Ace AS INTEGER '      flag has ace for totalling hand
  35.     Bust AS INTEGER '     flag for final reckoning
  36.     BJ AS INTEGER '       flag for final reckoning
  37.     Total AS INTEGER '    card total of hand
  38.     Chips AS _INTEGER64 ' players status
  39.     SetBet AS _INTEGER64 'regular bet amount
  40.     Bet AS _INTEGER64 '   players bet each round
  41.  
  42. DIM SHARED deck$(1 TO 52), p(1 TO nPlayers) AS PlayerType, deckIndex, round, allOut, player, blockDealer, tN AS LONG
  43. SCREEN _NEWIMAGE(xmax, ymax, 32)
  44. DIM i, card$
  45. ON TIMER(tN, .5) checkMouseOver
  46.  
  47. initGame
  48. 'FOR i = 1 TO nPlayers
  49. '    showPlayer i
  50. 'NEXT
  51. TIMER(tN) ON
  52.     clearPlayers 'clears screen too and shuffles deck
  53.  
  54.     FOR i = 1 TO 2
  55.         FOR player = 1 TO nPlayers 'each Player is dealt 2 cards
  56.             IF player <> nPlayers THEN
  57.                 IF p(player).Chips > 0 THEN
  58.                     allOut = 0 'signal everyone is out of chips is false
  59.                     PlayerAddCard player
  60.                     showPlayer player
  61.                     _DELAY .5
  62.                 END IF
  63.             ELSE
  64.                 IF allOut THEN
  65.                     EXIT DO
  66.                 ELSE
  67.                     PlayerAddCard player
  68.                     showPlayer player
  69.                     _DELAY .5
  70.                 END IF
  71.             END IF
  72.         NEXT
  73.     NEXT
  74.  
  75.     IF p(nPlayers).BJ = 0 THEN 'dealer does not have BJ
  76.         FOR player = 1 TO nPlayers - 1
  77.             showPlayer player
  78.             _DELAY 1
  79.             WHILE p(player).Total < 21
  80.                 SELECT CASE player ' this has to be coded for exactly all nPlayers - 1
  81.                     CASE 1: card$ = Johnno$(player)
  82.                     CASE 2: card$ = Johnno$(player)
  83.                     CASE 3: card$ = Steve$(player)
  84.                     CASE 4: card$ = Steve$(player)
  85.                     CASE 5: card$ = bplusAI$(player)
  86.                     CASE 6: card$ = bplusAI$(player)
  87.                     CASE 7: card$ = bplusAI2$(player)
  88.                     CASE 8: card$ = bplusAI2$(player)
  89.                 END SELECT
  90.                 IF card$ = "h" THEN cp player, 13, "Hit"
  91.                 IF card$ = "d" THEN cp player, 13, "Double Down"
  92.                 IF card$ <> "h" AND card$ <> "d" THEN cp player, 13, "Stay"
  93.                 _DELAY 2
  94.                 IF card$ = "h" THEN
  95.                     PlayerAddCard player
  96.                     showPlayer player
  97.                     _DELAY 1
  98.                 ELSEIF card$ = "d" AND LEN(p(player).Hand) = 2 THEN
  99.                     p(player).Bet = 2 * p(player).Bet
  100.                     PlayerAddCard player
  101.                     showPlayer player
  102.                     _DELAY 1
  103.                     EXIT WHILE
  104.                 ELSE 'stayed
  105.                     showPlayer player
  106.                     _DELAY 1
  107.                     EXIT WHILE
  108.                 END IF
  109.             WEND
  110.         NEXT
  111.     END IF
  112.  
  113.     blockDealer = 0
  114.     showPlayer nPlayers
  115.     _DELAY 1
  116.     WHILE p(nPlayers).Total < 17
  117.         cp nPlayers, 11, "Dealer takes a card."
  118.         _DELAY 1
  119.         PlayerAddCard nPlayers
  120.         showPlayer nPlayers
  121.         _DELAY 1
  122.     WEND
  123.  
  124.     '    final Reckoning
  125.     FOR player = 1 TO nPlayers - 1
  126.         showPlayer player
  127.         IF p(player).Total > 21 OR (p(player).Total < p(nPlayers).Total AND p(nPlayers).Total < 22) THEN
  128.             cp player, 13, "Lost" + STR$(p(player).Bet)
  129.             p(player).Chips = p(player).Chips - p(player).Bet
  130.             p(nPlayers).Chips = p(nPlayers).Chips + p(player).Bet
  131.         ELSEIF p(player).Total = p(nPlayers).Total AND p(player).BJ = 0 THEN
  132.             cp player, 13, "Push"
  133.         ELSE
  134.             IF p(player).BJ THEN
  135.                 cp player, 13, "Win!" + STR$(p(player).Bet + .5 * p(player).Bet)
  136.                 p(player).Chips = p(player).Chips + p(player).Bet + .5 * p(player).Bet
  137.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet - .5 * p(player).Bet
  138.             ELSE
  139.                 cp player, 13, "Win!" + STR$(p(player).Bet)
  140.                 p(player).Chips = p(player).Chips + p(player).Bet
  141.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet
  142.             END IF
  143.         END IF
  144.         IF p(player).Chips = 0 THEN cp player, 14, "Out of chips!"
  145.         _DELAY 3
  146.     NEXT
  147. LOOP UNTIL allOut
  148.  
  149. SUB checkMouseOver
  150.     DIM mx, my, i
  151.     mx = _MOUSEX / 8 - .5 * bW: my = _MOUSEY / 16
  152.     IF my >= 18 THEN
  153.         FOR i = 1 TO nPlayers - 1
  154.             IF ABS(mx - p(i).Col) <= .5 * bW - 1 THEN showPlayer i
  155.         NEXT
  156.     END IF
  157.  
  158. SUB clearPlayers
  159.     DIM i
  160.     COLOR fc, bc: CLS
  161.     round = round + 1: allOut = -1
  162.     FOR i = 1 TO nPlayers
  163.         p(i).Hand = ""
  164.         p(i).Ace = 0
  165.         p(i).Total = 0
  166.         p(i).BJ = 0
  167.         p(i).Bust = 0
  168.         'because of double down option I have to reset bet during play and set it back at each new round
  169.         'make sure we aren't betting more than our chips count at least to start
  170.         IF p(i).Chips < p(i).SetBet THEN p(i).Bet = p(i).Chips ELSE p(i).Bet = p(i).SetBet
  171.     NEXT
  172.     FOR i = 52 TO 2 STEP -1 'shuffle
  173.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  174.     NEXT
  175.     'deck$(5) = "A": deck$(10) = "J"  'check immediate show of Blackjack for dealer
  176.     deckIndex = 0: blockDealer = -1
  177.  
  178. FUNCTION bplusAI$ (pn) ' first try
  179.     SELECT CASE p(pn).Total
  180.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  181.         CASE 10, 11
  182.             IF LEN(p(pn).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  183.         CASE IS < 15
  184.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  185.         CASE ELSE: bplusAI$ = "Show me the money!"
  186.     END SELECT
  187.  
  188. FUNCTION bplusAI2$ (pN) 'after trying first want to try this make it more likely to hit on 12 than 13, 14...
  189.     SELECT CASE p(pN).Total
  190.         CASE IS < 10: bplusAI2$ = "h" 'no caps!
  191.         CASE 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer
  192.             IF LEN(p(pN).Hand) = 2 AND LEFT$(p(nPlayers).Hand, 1) <> "A" THEN bplusAI2$ = "d" ELSE bplusAI2$ = "h"
  193.         CASE 12: IF RND < .75 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  194.         CASE 13: IF RND < .5 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  195.         CASE 14: IF RND < .25 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  196.         CASE ELSE: bplusAI2$ = "Show me the money!"
  197.     END SELECT
  198.  
  199. FUNCTION Johnno$ (pN)
  200.     IF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) = 2 THEN
  201.         Johnno$ = "d"
  202.     ELSEIF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) <> 2 THEN
  203.         Johnno$ = "h"
  204.     ELSEIF 12 <= p(pN).Total AND p(pN).Total <= 15 THEN
  205.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  206.             CASE "A", "K", "Q", "J", "X", "9": Johnno$ = "h"
  207.             CASE "7", "8": IF RND < .5 THEN Johnno$ = "h"
  208.             CASE ELSE: Johnno$ = "Hope to Bust em"
  209.         END SELECT
  210.     ELSEIF p(pN).Total < 12 THEN
  211.         Johnno$ = "h"
  212.     ELSE
  213.         Johnno$ = "Stay"
  214.     END IF
  215.  
  216. FUNCTION Steve$ (pN) 'how simple is this! never bust make dealer work for it
  217.     IF p(pN).Total < 12 THEN Steve$ = "h"
  218.  
  219. SUB PlayerAddCard (rec) 'updates player's hand and total
  220.     DIM i AS INTEGER, cv AS INTEGER
  221.     deckIndex = deckIndex + 1
  222.     p(rec).Hand = p(rec).Hand + deck$(deckIndex)
  223.     IF deck$(deckIndex) = "A" THEN p(rec).Ace = -1
  224.     p(rec).Total = 0
  225.     FOR i = 1 TO LEN(p(rec).Hand)
  226.         IF INSTR(rank$, MID$(p(rec).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank$, MID$(p(rec).Hand, i, 1))
  227.         p(rec).Total = p(rec).Total + cv
  228.     NEXT
  229.     IF p(rec).Total < 12 AND p(rec).Ace THEN p(rec).Total = p(rec).Total + 10
  230.     IF LEN(p(rec).Hand) = 2 AND p(rec).Total = 21 THEN p(rec).BJ = -1
  231.     IF p(rec).Total > 21 THEN p(rec).Bust = -1
  232.  
  233. SUB showPlayer (nPlayer)
  234.     DIM i AS INTEGER, S$
  235.     COLOR p(nPlayer).FC, p(nPlayer).BC
  236.     FOR i = 0 TO bH - 1 'clear our block
  237.         'PRINT p(nPlayer).Row + i, p(nPlayer).Col
  238.         LOCATE p(nPlayer).Row + i, p(nPlayer).Col: PRINT SPACE$(bW);
  239.     NEXT
  240.     cp nPlayer, 1, "Round:" + STR$(round)
  241.     cp nPlayer, 3, p(nPlayer).ID
  242.     cp nPlayer, 5, "Chips:" + STR$(p(nPlayer).Chips)
  243.     IF nPlayer <> nPlayers THEN cp nPlayer, 6, "Bet:" + STR$(p(nPlayer).Bet)
  244.     FOR i = 1 TO LEN(p(nPlayer).Hand) 'with 12 aces could get very long hands
  245.         S$ = S$ + MID$(p(nPlayer).Hand, i, 1) + " "
  246.     NEXT
  247.     cp nPlayer, 8, "___Hand___"
  248.     IF nPlayer = nPlayers AND LEN(p(nPlayer).Hand) = 2 AND p(nPlayer).Total <> 21 AND blockDealer THEN
  249.         S$ = LEFT$(S$, 2) + "?"
  250.         cp nPlayer, 9, S$
  251.         cp nPlayer, 10, "Total: ??"
  252.     ELSE
  253.         cp nPlayer, 9, S$
  254.         cp nPlayer, 10, "Total:" + STR$(p(nPlayer).Total)
  255.     END IF
  256.  
  257.     IF p(nPlayer).Bust THEN cp nPlayer, 11, "Busted"
  258.     IF p(nPlayer).BJ THEN cp nPlayer, 11, "Blackjack"
  259.  
  260. SUB initGame 'the stuff that never changes
  261.     DIM i, spacer
  262.     FOR i = 1 TO 52 'get deck ready
  263.         deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  264.     NEXT
  265.  
  266.     'for printing in each players window area of screen = blackjack table
  267.     'xmax/8 =  2*margin + bW *(nplayers -1) + spacer *(nplayer-2)
  268.     spacer = ((xmax / 8) - margin - bW * (nPlayers - 1)) / (nPlayers - 2)
  269.  
  270.     FOR i = 1 TO nPlayers
  271.         IF i <> nPlayers THEN
  272.             SELECT CASE i
  273.                 CASE 1: p(i).ID = "Johnno 1"
  274.                 CASE 2: p(i).ID = "Johnno 2"
  275.                 CASE 3: p(i).ID = "Steve 1"
  276.                 CASE 4: p(i).ID = "Steve 2"
  277.                 CASE 5: p(i).ID = "bplus First AI 1"
  278.                 CASE 6: p(i).ID = "bplus First AI 2"
  279.                 CASE 7: p(i).ID = "bplus 2nd AI 1"
  280.                 CASE 8: p(i).ID = "bplus 2nd AI 2"
  281.             END SELECT
  282.             p(i).Col = margin + (i - 1) * (spacer + bW)
  283.             p(i).Row = 18
  284.             p(i).Chips = 100
  285.             p(i).SetBet = 2
  286.             IF i MOD 2 THEN
  287.                 p(i).BC = _RGB32(RND * 128, RND * 128, RND * 128)
  288.             ELSE
  289.                 p(i).BC = _RGB32(RND * 128 + 127, RND * 128 + 127, RND * 128 + 127)
  290.             END IF
  291.         ELSE
  292.             p(i).ID = "Dealer"
  293.             p(i).Col = (xmax / 8 - bW) / 2
  294.             p(i).Row = 2
  295.             p(i).Chips = -100 * (nPlayers - 1)
  296.             IF i MOD 2 THEN p(i).BC = &HFF000000 ELSE p(i).BC = &HFFFFFFFF
  297.         END IF
  298.         IF i MOD 2 THEN p(i).FC = &HFFFFFFFF ELSE p(i).FC = &HFF000000
  299.     NEXT
  300.  
  301.     'ask the user / YOU what e prefers for betting
  302.     COLOR fc, bc: CLS
  303.     cp 0, 10, "*** Blackjack Multi AI Tester ***"
  304.     cp 0, 12, "Each AI bot starts with 100 chips and bets 2 each round."
  305.     cp 0, 13, "Dealer must hit on 16 or less."
  306.     cp 0, 14, "Blackjack pays 1.5 X the bet."
  307.     cp 0, 15, "Double down option available when you get 2 cards."
  308.     cp 0, 16, "It Doubles the bet and you get one more card."
  309.     cp 0, 20, "press any to continue..."
  310.     SLEEP
  311.  
  312. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  313.     IF nPlayer THEN
  314.         COLOR p(nPlayer).FC, p(nPlayer).BC
  315.         LOCATE p(nPlayer).Row + row, p(nPlayer).Col + (bW - LEN(s)) / 2: PRINT s;
  316.     ELSE
  317.         COLOR fc, bc
  318.         LOCATE row, (xmax / 8 - LEN(s)) / 2: PRINT s;
  319.     END IF
  320.  
  321.  

Can't mouse over while getting a screen shot but here is a game with 8 AI bots + Dealer bot
 
Title: Re: Blackjack
Post by: johnno56 on July 07, 2020, 06:57:35 pm
Nine hands playing from one deck. That would mean a serious amount of shuffling... lol  Ah, but then, The Dealer is supposed to perform miracles... lol

Suggestion: Increase the screen size. Place the Dealer top centre. Three players from top to bottom on both the left and right sides. The remaining two in the 'gap' along the bottom. Another layout: Dealer in the center of screen. Two players left and right and above and below the Dealer.

My other guess would be that this version is a 'concept' of controlling multiple AI and 'layout' is not relevant.... lol

I'm curious. In 'real' Blackjack, how many players can actually play, and how does the dealer determine how many 'decks' to use?
Title: Re: Blackjack
Post by: bplus on July 07, 2020, 07:52:02 pm
My other guess would be that this version is a 'concept' of controlling multiple AI and 'layout' is not relevant.... lol

Yeah pretty much that, an experiment. I did like how well the mouse over thing did work off a timer but...

Yeah! you know it's nice to see all the hands clearly. I could probably fit 8 comfortably or go bigger screen as you say. I've also noticed that it is nice for cards to layout from left to right without a centering function shifting them left and right.

What do you think about the dealer down at the bottom right corner, then we just work left to right, top to bottom?


You know, think about it, the dealer has to keep hitting until has at least 17. 17 to 21 is a window of... oh it's 5 cards. I've been thinking 4 because 21-17 but it is 5 cards. And yet it just drains chips from players, there must be some better strategy. The tip about looking at dealers up card was interesting intelligence and I am beginning to think double down is only good on 11 and only if dealer has lower card.

I will play around with layout and AI options.

BTW in real Blackjack the casinos set their own standards and I am pretty sure no one uses only one deck which means its possible to get a huge number of aces.
Title: Re: Blackjack
Post by: johnno56 on July 07, 2020, 08:45:59 pm
Position of the Dealer... Traditionally the Dealer is at the 'head' of the table... I assume that to be the 'top' with all players within reach at the 'bottom'. The 'reach' could explain the shape of the table... The problem with 'that' layout, for the screen, would be that all the player would be side-by-side. Did you have any plans on a limit to player numbers? Knowing the limit would help in  determining the layout.

But, then again, who says that the game has to be 'traditional'? lol

I remember, during lunch breaks at work, we used to play Pontoon (or 21), and betting was a little different. There was the initial bet then if the player had 11 or less in two cards, the player could 'buy' an extra card and choose to 'hit' if more than 11. If you are after 'bleeding a player dry' then that might be the way to go... lol  Just recalled that... I know. I'm shocked as well..!! Remembering something from 4 decades ago... Shocked!

The mouse is a great idea... But, with the right kind of surgery, a neural interface could be developed for that 'hands free' feeling... But... mouse will do in a pinch... lol

Logic dictates that, if artificial intelligence can be programmed into a game, then so can artificial stupidity... It's funny but not meant as a joke. "Humor. It is a difficult concept." Star Trek: Wrath of Khan (1982)  People make 'stupid' decisions and make foolish mistakes. Then why not configure the AI to replicate the same behaviour? (throwing in a typical "Doh!" after the event) Just a thought...
Title: Re: Blackjack
Post by: Qwerkey on July 08, 2020, 07:39:18 am
Congratulations @bplus & @johnno56 , what a collaboration.  In forum stats, this post is way ahead of anything else in Replies.  This will shortly be arriving in Games.
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 12:06:15 pm
Thanks Qwerkey,

The number of replies is most probably just chit-chat between me and Johnno, but I appreciate encouragement and help offered by Dav, Pete, Steve, George and Pete & Steve's jokes to break monotony and all positive comments QBExile, Old Moses, Ken, Ashish, Spriggsy, jack, Cobalt all showing some sort of interest even Fellippe when I mention a possible glitch between QB64 versions. 😊

I actually considered the cough and gunshots sounds for background, I already had the sounds, funny!

Special thanks to Johnno, like with Battleship, he can sure dress up my code and keep the ideas flowing for me. Really liked the splash screen specially with our Logo in the neon sign and the Dealer voice. Good eye too, I still don't know if there is difference in card set images? ha! I just used what he provided on faith.
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 01:12:27 pm
@Qwerkey 

I will go over code and write in some more comments for myself and others for future reference. Should be ready tonight, I've got chores in afternoon.

I have already made the main loop play more efficient with the Mult-players code by setting flags for Blackjacks and Busts handling them in Final Reckoning section instead of separately right after first 2 cards.
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 07:15:28 pm
I have become intensely curious about Dealer Stats, the distribution of Totals 17 to 21 and over 21 Busts:
Code: QB64: [Select]
  1. _TITLE "BJ Dealer Test - stats" 'b+ 2020-07-08
  2. '  on distribution 17 to 21 in and 22 plus out
  3.  
  4. CONST rank = "A23456789XJQK"
  5. TYPE PlayerType
  6.     ID AS STRING
  7.     Hand AS STRING
  8.     Ace AS INTEGER
  9.     Total AS INTEGER
  10.     chips AS _INTEGER64
  11.     setBet AS _INTEGER64
  12.     bet AS _INTEGER64
  13. DIM SHARED dealer AS PlayerType, deck$(1 TO 52), deckIndex AS INTEGER, stats(17 TO 22)
  14.  
  15. FOR i = 1 TO 52 'get deck ready
  16.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  17.  
  18. WHILE _KEYDOWN(27) = 0
  19.     FOR i = 52 TO 2 STEP -1 'shuffle
  20.         r = INT(RND * i) + 1
  21.         SWAP deck$(r), deck$(i)
  22.     NEXT
  23.     deckIndex = 0: dealer.Total = 0: rounds = rounds + 1: dealer.Hand = "": noBusts = 0: dealer.Ace = 0
  24.     CLS
  25.     PRINT "Round:"; rounds
  26.     WHILE dealer.Total < 17
  27.         PlayerAddCard
  28.         PRINT RIGHT$(dealer.Hand, 1);
  29.         _LIMIT 100
  30.     WEND
  31.     PRINT , dealer.Total: PRINT
  32.     IF dealer.Total > 21 THEN stats(22) = stats(22) + 1 ELSE stats(dealer.Total) = stats(dealer.Total) + 1
  33.     FOR i = 17 TO 22
  34.         PRINT i, stats(i), INT(stats(i) * 10000 / rounds) / 100; "%"
  35.         IF i < 22 THEN noBusts = noBusts + stats(i)
  36.     NEXT
  37.     PRINT
  38.     PRINT "     No Busts:"; noBusts, INT(noBusts * 10000 / rounds) / 100; "%"
  39.     _DISPLAY
  40.     _LIMIT 10
  41.  
  42.  
  43. SUB PlayerAddCard 'updates player's hand and total
  44.     DIM i AS INTEGER, cv AS INTEGER
  45.     deckIndex = deckIndex + 2
  46.     dealer.Hand = dealer.Hand + deck$(deckIndex)
  47.     IF deck$(deckIndex) = "A" THEN dealer.Ace = -1
  48.     dealer.Total = 0
  49.     FOR i = 1 TO LEN(dealer.Hand)
  50.         IF INSTR(rank, MID$(dealer.Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(dealer.Hand, i, 1))
  51.         dealer.Total = dealer.Total + cv
  52.     NEXT
  53.     IF dealer.Total < 12 AND dealer.Ace THEN dealer.Total = dealer.Total + 10
  54.  
  55.  
Title: Re: Blackjack
Post by: George McGinn on July 08, 2020, 07:35:08 pm
Thank you.

The one I have a little bit longer, but it’s written for the techBASIC on iPad which does not have a SWAP statement.

However, I have noticed playing your blackjack game that it doesn’t quite follow basic play. I’ve noticed where the dealer has a 10 value showing, Everybody’s up to 16 should be hitting, yeah I’ve seen players stand on 13. I never a few other little things but I do understand what you’re trying to do with the AI. And it’s working pretty well so far.

I would however, chance a bust with a dealer showing a 10 value card as an up card, as I do in real life at casinos and do pretty well playing the basic strategy with some of my personal modifications.

Otherwise, you have done a great job on the coding.


Can shuffle be simpler than this from my last code post, from all my code that needs shuffle)?
Code: QB64: [Select]
  1.     FOR i = 52 TO 2 STEP -1 'shuffle
  2.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  3.     NEXT
  4.  

Welcome aboard George!
Title: Re: Blackjack
Post by: George McGinn on July 08, 2020, 07:50:13 pm
Bbplus,

Here is the code that I have on techBASIC on my iPad. I basically do a manual swap.

The print statements are there so that when I tested it I could see what it was doing and making sure that it was not duplicating any numbers.

Near the technique is just about the same, but what I do is I first preload an array And then swap the numbers around.

The following code is NOT QB64, but it is simple enough that it it will probably run in QB64:

Code: Text: [Select]
  1.  
  2. ! Shuffle a deck of cards, represented by an array contiaining the
  3. ! ordinal number of each card.
  4.  
  5. DIM cards(52) AS INTEGER
  6.  
  7. FOR i = 1 TO 52
  8.     cards(i) = i
  9. NEXT
  10.  
  11. j=0
  12.  
  13. FOR i = 1 to 52
  14.     PRINT "i: ";i
  15.     j = INT(1 + Math.rand*52) ! This generates the random number to swap from
  16.     PRINT "j: ";j
  17.     temp = cards(i)                  ! Saves the card number currently at i
  18.     PRINT "temp=cards(i): ";temp
  19.     cards(i) = cards(j)              ! This swaps position j into i
  20.     PRINT "cards(i)=cards(j): ";cards(i)
  21.     cards(j) = temp                  ! This moves the value that was in i into j
  22.     PRINT "cards(j)=temp: ";cards(j)
  23.     PRINT
  24. NEXT
  25.  
  26. ! Print out the new deck just shuffled
  27. FOR i = 1 TO 52
  28.     PRINT cards(i)
  29. NEXT
  30.  
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 08:06:13 pm
Hi @George McGinn

I see you come from Steve McNeill's camp of swapping each card with any of the other 52 cards.

There is a math proof that this is not ideal and leaves slightly less than perfect random distribution (given perfect random generator but who has that?)

"https://en.wikipedia.org/wiki/Fisher–Yates_shuffle"  <<copy/paste between quotes this in browser because underline link usually fails.

Look under Naive Shuffle:
 


EDIT: 2 l's in Steve's last name, I noticed I missed one in George's quote. Sorry Steve.
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 08:15:22 pm
Thank you.

The one I have a little bit longer, but it’s written for the techBASIC on iPad which does not have a SWAP statement.

However, I have noticed playing your blackjack game that it doesn’t quite follow basic play. I’ve noticed where the dealer has a 10 value showing, Everybody’s up to 16 should be hitting, yeah I’ve seen players stand on 13. I never a few other little things but I do understand what you’re trying to do with the AI. And it’s working pretty well so far.

I would however, chance a bust with a dealer showing a 10 value card as an up card, as I do in real life at casinos and do pretty well playing the basic strategy with some of my personal modifications.

Otherwise, you have done a great job on the coding.

Yeah I am testing different Stay Strategies now and 16 looks very good! A slight mod of my previous post:
Code: QB64: [Select]
  1. _TITLE "BJ Dealer Test - stats" 'b+ 2020-07-08
  2. '  on distribution 17 to 21 in and 22 plus out
  3.  
  4. CONST rank = "A23456789XJQK"
  5. TYPE PlayerType
  6.     ID AS STRING
  7.     Hand AS STRING
  8.     Ace AS INTEGER
  9.     Total AS INTEGER
  10.     chips AS _INTEGER64
  11.     setBet AS _INTEGER64
  12.     bet AS _INTEGER64
  13.  
  14. DIM SHARED stay: stay = 18 'compare stay statss 16, 17 (Dealer's), 18
  15.  
  16. DIM SHARED dealer AS PlayerType, deck$(1 TO 52), deckIndex AS INTEGER, stats(stay TO 22)
  17.  
  18. FOR i = 1 TO 52 'get deck ready
  19.     deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  20.  
  21. WHILE _KEYDOWN(27) = 0
  22.     FOR i = 52 TO 2 STEP -1 'shuffle
  23.         r = INT(RND * i) + 1
  24.         SWAP deck$(r), deck$(i)
  25.     NEXT
  26.     deckIndex = 0: dealer.Total = 0: rounds = rounds + 1: dealer.Hand = "": noBusts = 0: dealer.Ace = 0
  27.     CLS
  28.     PRINT "Round:"; rounds
  29.     WHILE dealer.Total < stay
  30.         PlayerAddCard
  31.         PRINT RIGHT$(dealer.Hand, 1);
  32.         _LIMIT 100
  33.     WEND
  34.     PRINT , dealer.Total: PRINT
  35.     IF dealer.Total > 21 THEN stats(22) = stats(22) + 1 ELSE stats(dealer.Total) = stats(dealer.Total) + 1
  36.     FOR i = stay TO 22
  37.         PRINT i, stats(i), INT(stats(i) * 10000 / rounds) / 100; "%"
  38.         IF i < 22 THEN noBusts = noBusts + stats(i)
  39.     NEXT
  40.     PRINT
  41.     PRINT "     No Busts:"; noBusts, INT(noBusts * 10000 / rounds) / 100; "%"
  42.     _DISPLAY
  43.     _LIMIT 10
  44.  
  45.  
  46. SUB PlayerAddCard 'updates player's hand and total
  47.     DIM i AS INTEGER, cv AS INTEGER
  48.     IF LEN(dealer.Hand) <= 2 THEN deckIndex = deckIndex + 2 ELSE deckIndex = deckIndex + 1
  49.     dealer.Hand = dealer.Hand + deck$(deckIndex)
  50.     IF deck$(deckIndex) = "A" THEN dealer.Ace = -1
  51.     dealer.Total = 0
  52.     FOR i = 1 TO LEN(dealer.Hand)
  53.         IF INSTR(rank, MID$(dealer.Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank, MID$(dealer.Hand, i, 1))
  54.         dealer.Total = dealer.Total + cv
  55.     NEXT
  56.     IF dealer.Total < 12 AND dealer.Ace THEN dealer.Total = dealer.Total + 10
  57.  
  58.  

I am running stay at 18 now:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

You are right! 16 looked very good compared to 17, a NO Bust rate a little over 80% compared to 72% for Stay at 17 and the percent of Totals 20 or 21 is just slightly lower for Stay at 16 (31%) than it is for stay at 17(32%) based on about 3000 trials which is a pittance I suppose.

As you can see, Stay at 18 has significantly worse Bust Rate!
Title: Re: Blackjack
Post by: bplus on July 08, 2020, 08:27:00 pm
By the way @George McGinn  if you want to try your hand at an AI, I'd be glad to test it in my Tester #3

Here is a snap of a current run:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Hi @johnno56  I have gone a full loop at testing layouts and decided one row of players with Dealer at top, pretty much as you said ;-))

To all,  Still have openings for AI Functions to test, here is current Tester:
Code: QB64: [Select]
  1. ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. '2020-07-05 fix hit (it wasn't broken), delete line chose$ = inkey$ before loop
  3. ' force dealer to hit on 16 stay 17
  4. ' ties are push
  5. ' bring in double down option
  6. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  7. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  8. ' 2020-07-06 Installed AI and mods for it
  9. ' 2020-07-06 new Compact Tester with 2nd AI
  10. ' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester
  11. '            add in allot of code worked out in Blackjack with Bots 2019-06-07
  12. '            Yes, major overhaul of last year bot code which was/is neat!
  13. '            Thanks Johnno and Steve for some interesting AI ideas to try!
  14. ' 2020-07-07 for Blackjack Multi AI Tester #2, I hope to do something kind of interesting with displaying players
  15. '            Yes Mouse over a player you want to check on but try and stay out of way of updating.
  16. ' 2020-07-08 No overlapping players, sucks, get rid of timer stuff, removed.
  17. '            Screen Size depends on how many players go against Dealer from 1 to 6 maximum.
  18. '            1 row of players with screen width < 1024, Dealer at top.
  19. '            Added more items to Player type  to display status solely from it's array contents.
  20. '            Also forbid player to double down if es chips can't cover loss.
  21. '            Display round number in Title Bar
  22.  
  23. '=================================================================================================================
  24. ' Blackjack Multi-Tester Notes: (removed from screening at start)
  25.  
  26. '                              *** Blackjack Multi AI Tester #3 ***
  27. '
  28. '                     Each AI bot starts with 100 chips and bets 2 each round.
  29. '                                Dealer must hit on 16 or less.
  30. '                                 Blackjack pays 1.5 X the bet.
  31. '                       Double down option available when you get 2 cards.
  32. '                         It Doubles the bet and you get one more card.
  33. '
  34. '====================================================================================================================
  35.  
  36. DEFINT A-Z
  37.  
  38. CONST nPlayers = 7 '            2 to 7 only! Dealer counts as the last player Screen size is adjusted to this!
  39. CONST rank$ = "A23456789XJQK" ' for building deck and figuring Totals
  40. CONST bH = 12, bW = 20 '        box height and box width in rows and columns
  41. CONST bc = &HFF008822, fc = &HFFCCCCFF ' screen back and fore colors , no printing though
  42.  
  43. TYPE PlayerType
  44.     ID AS STRING '        name of bot including dealer bot
  45.     Col AS INTEGER '      left corner column
  46.     Row AS INTEGER '      top row
  47.     FC AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White
  48.     BC AS _UNSIGNED LONG 'random light and dark opposite print FC
  49.     Hand AS STRING '      cards are 1 char strings 10 is X
  50.     Ace AS INTEGER '      flag has ace for totalling hand
  51.     Bust AS INTEGER '     flag for final reckoning
  52.     BJ AS INTEGER '       flag for final reckoning
  53.     Total AS INTEGER '    card total of hand
  54.     Chips AS _INTEGER64 ' players status
  55.     SetBet AS _INTEGER64 'regular bet amount
  56.     Bet AS _INTEGER64 '   players bet each round
  57.     Tell AS STRING '      Hit, Stay Double or Win Push Loss Amt goal to put everything in PlayerType that showPlayer needs for display
  58.  
  59. DIM SHARED xmax, deck$(1 TO 52), p(1 TO nPlayers) AS PlayerType, deckIndex, round, allOut, player, blockDealer
  60.  
  61. DIM i, chose$
  62. initGame
  63. 'FOR i = 1 TO nPlayers
  64. '    showPlayer i
  65. 'NEXT
  66. 'SLEEP
  67. 'END
  68. DO 'start a round
  69.     startRound 'clears screen too and shuffles deck
  70.  
  71.     FOR i = 1 TO 2
  72.         FOR player = 1 TO nPlayers 'each Player is dealt 2 cards
  73.             IF player <> nPlayers THEN
  74.                 IF p(player).Chips > 0 THEN
  75.                     allOut = 0 'signal everyone is out of chips is false
  76.                     PlayerAddCard player
  77.                 END IF
  78.             ELSE
  79.                 IF allOut THEN
  80.                     EXIT DO
  81.                 ELSE
  82.                     PlayerAddCard player
  83.                 END IF
  84.             END IF
  85.         NEXT
  86.     NEXT
  87.  
  88.     IF p(nPlayers).BJ = 0 THEN 'dealer does not have BJ
  89.         FOR player = 1 TO nPlayers - 1
  90.             showPlayer player
  91.             WHILE p(player).Total < 21
  92.                 SELECT CASE player ' this has to be coded for exactly all nPlayers - 1
  93.                     CASE 1: chose$ = Johnno$(player)
  94.                     CASE 2: chose$ = Steve$(player)
  95.                     CASE 3: chose$ = bplusAI$(player)
  96.                     CASE 4: chose$ = bplusAI$(player)
  97.                     CASE 5: chose$ = bplusAI2$(player)
  98.                     CASE 6: chose$ = bplusAI2$(player) 'no more than 6 bots
  99.                 END SELECT
  100.                 IF chose$ = "h" THEN p(player).Tell = "Hit"
  101.                 IF chose$ = "d" THEN p(player).Tell = "Double Down"
  102.                 IF chose$ <> "h" AND chose$ <> "d" THEN p(player).Tell = "Stay"
  103.                 showPlayer player
  104.                 _DELAY 2
  105.                 IF chose$ = "h" THEN
  106.                     PlayerAddCard player
  107.                 ELSEIF chose$ = "d" AND LEN(p(player).Hand) = 2 THEN
  108.                     p(player).Bet = 2 * p(player).Bet
  109.                     PlayerAddCard player
  110.                     EXIT WHILE
  111.                 ELSE 'stayed
  112.                     EXIT WHILE
  113.                 END IF
  114.             WEND
  115.         NEXT
  116.     END IF
  117.  
  118.     blockDealer = 0
  119.     showPlayer nPlayers
  120.     WHILE p(nPlayers).Total < 17
  121.         p(nPlayers).Tell = "Dealer takes a card."
  122.         showPlayer nPlayers
  123.         PlayerAddCard nPlayers
  124.     WEND
  125.     p(nPlayers).Tell = "Reckoning"
  126.     showPlayer nPlayers
  127.  
  128.     '    final Reckoning
  129.     FOR player = 1 TO nPlayers - 1
  130.         showPlayer player
  131.         IF p(player).BJ AND p(nPlayers).BJ THEN
  132.             p(player).Tell = "Push"
  133.         ELSEIF p(player).Total > 21 OR (p(player).Total < p(nPlayers).Total AND p(nPlayers).Total < 22) THEN
  134.             p(player).Tell = "Lost" + STR$(p(player).Bet)
  135.             p(player).Chips = p(player).Chips - p(player).Bet
  136.             p(nPlayers).Chips = p(nPlayers).Chips + p(player).Bet
  137.         ELSEIF p(player).Total = p(nPlayers).Total AND p(player).BJ = 0 THEN
  138.             p(player).Tell = "Push"
  139.         ELSE
  140.             IF p(player).BJ THEN
  141.                 p(player).Tell = "Win!" + STR$(p(player).Bet + .5 * p(player).Bet)
  142.                 p(player).Chips = p(player).Chips + p(player).Bet + .5 * p(player).Bet
  143.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet - .5 * p(player).Bet
  144.             ELSE
  145.                 p(player).Tell = "Win!" + STR$(p(player).Bet)
  146.                 p(player).Chips = p(player).Chips + p(player).Bet
  147.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet
  148.             END IF
  149.         END IF
  150.         showPlayer player
  151.         _DELAY 1 'an extra delay
  152.         IF p(player).Chips = 0 THEN
  153.             p(player).Tell = "Out of chips!":
  154.             showPlayer player
  155.             _DELAY 2 ' an extra delay
  156.         END IF
  157.     NEXT
  158. LOOP UNTIL allOut
  159.  
  160. SUB startRound
  161.     DIM i
  162.     COLOR fc, bc: CLS
  163.     round = round + 1: allOut = -1
  164.     FOR i = 1 TO nPlayers
  165.         p(i).Hand = ""
  166.         p(i).Ace = 0
  167.         p(i).Total = 0
  168.         p(i).BJ = 0
  169.         p(i).Bust = 0
  170.         p(i).Tell = ""
  171.         'because of double down option I have to reset bet during play and set it back at each new round
  172.         'make sure we aren't betting more than our chips count at least to start
  173.         IF p(i).Chips < p(i).SetBet THEN p(i).Bet = p(i).Chips ELSE p(i).Bet = p(i).SetBet
  174.     NEXT
  175.     FOR i = 52 TO 2 STEP -1 'shuffle
  176.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  177.     NEXT
  178.     'deck$(5) = "A": deck$(10) = "J"  'check immediate show of Blackjack for dealer
  179.     deckIndex = 0: blockDealer = -1
  180.     _TITLE "BJ AI Tester Round:" + STR$(round)
  181.  
  182. FUNCTION bplusAI$ (pn) ' first try
  183.     SELECT CASE p(pn).Total
  184.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  185.         CASE 10, 11
  186.             IF LEN(p(pn).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  187.         CASE IS < 15
  188.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  189.         CASE ELSE: bplusAI$ = "Show me the money!"
  190.     END SELECT
  191.  
  192. FUNCTION bplusAI2$ (pN) 'after trying first want to try this make it more likely to hit on 12 than 13, 14...
  193.     SELECT CASE p(pN).Total
  194.         CASE IS < 10: bplusAI2$ = "h" 'no caps!
  195.         CASE 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer
  196.             IF LEN(p(pN).Hand) = 2 AND LEFT$(p(nPlayers).Hand, 1) <> "A" THEN bplusAI2$ = "d" ELSE bplusAI2$ = "h"
  197.         CASE 12: IF RND < .75 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  198.         CASE 13: IF RND < .5 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  199.         CASE 14: IF RND < .25 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  200.         CASE ELSE: bplusAI2$ = "Show me the money!"
  201.     END SELECT
  202.  
  203. FUNCTION Johnno$ (pN)
  204.     IF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) = 2 THEN
  205.         Johnno$ = "d"
  206.     ELSEIF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) <> 2 THEN
  207.         Johnno$ = "h"
  208.     ELSEIF 12 <= p(pN).Total AND p(pN).Total <= 15 THEN
  209.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  210.             CASE "A", "K", "Q", "J", "X", "9": Johnno$ = "h"
  211.             CASE "7", "8": IF RND < .5 THEN Johnno$ = "h"
  212.             CASE ELSE: Johnno$ = "Hope to Bust em"
  213.         END SELECT
  214.     ELSEIF p(pN).Total < 12 THEN
  215.         Johnno$ = "h"
  216.     ELSE
  217.         Johnno$ = "Stay"
  218.     END IF
  219.  
  220. FUNCTION Steve$ (pN) 'how simple is this! never bust make dealer work for it
  221.     IF p(pN).Total < 12 THEN Steve$ = "h"
  222.  
  223. SUB PlayerAddCard (rec) 'updates player's hand and total
  224.     DIM i AS INTEGER, cv AS INTEGER
  225.     deckIndex = deckIndex + 1
  226.     p(rec).Hand = p(rec).Hand + deck$(deckIndex)
  227.     IF deck$(deckIndex) = "A" THEN p(rec).Ace = -1
  228.     p(rec).Total = 0
  229.     FOR i = 1 TO LEN(p(rec).Hand)
  230.         IF INSTR(rank$, MID$(p(rec).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank$, MID$(p(rec).Hand, i, 1))
  231.         p(rec).Total = p(rec).Total + cv
  232.     NEXT
  233.     IF p(rec).Total < 12 AND p(rec).Ace THEN p(rec).Total = p(rec).Total + 10
  234.     IF LEN(p(rec).Hand) = 2 AND p(rec).Total = 21 THEN p(rec).BJ = -1
  235.     IF p(rec).Total > 21 THEN p(rec).Bust = -1
  236.     showPlayer rec 'when ever add card show update
  237.  
  238. SUB showPlayer (nPlayer) '
  239.     DIM i AS INTEGER, S$
  240.     COLOR p(nPlayer).FC, p(nPlayer).BC
  241.     FOR i = 0 TO bH - 1 'clear our block
  242.         LOCATE p(nPlayer).Row + i, p(nPlayer).Col: PRINT SPACE$(bW);
  243.     NEXT
  244.     cp nPlayer, 1, p(nPlayer).ID
  245.     cp nPlayer, 3, "Chips:" + STR$(p(nPlayer).Chips)
  246.     IF nPlayer <> nPlayers THEN cp nPlayer, 4, "Bet:" + STR$(p(nPlayer).Bet)
  247.     FOR i = 1 TO LEN(p(nPlayer).Hand)
  248.         S$ = S$ + MID$(p(nPlayer).Hand, i, 1) + " "
  249.     NEXT
  250.     IF nPlayer = nPlayers AND LEN(p(nPlayer).Hand) = 2 AND p(nPlayer).Total <> 21 AND blockDealer THEN
  251.         S$ = LEFT$(S$, 2) + "?"
  252.         cp nPlayer, 6, S$
  253.         cp nPlayer, 7, "Total: ??"
  254.     ELSE
  255.         cp nPlayer, 6, S$
  256.         cp nPlayer, 7, "Total:" + STR$(p(nPlayer).Total)
  257.     END IF
  258.     IF p(nPlayer).Bust THEN cp nPlayer, 8, "Busted"
  259.     IF p(nPlayer).BJ THEN cp nPlayer, 8, "Blackjack"
  260.     cp nPlayer, 10, p(nPlayer).Tell ' last action of player or dealer or final win lost push
  261.     _DELAY 1 'when ever showPlayer  need a delay to read
  262.  
  263. SUB initGame 'the stuff that never changes
  264.     DIM i
  265.     ' 1+13*2 rows = 27*16 = 432 ymax
  266.     xmax = ((nPlayers - 1) * 21 + 1) * 8
  267.     SCREEN _NEWIMAGE(xmax, 432, 32)
  268.     _DELAY .25
  269.  
  270.     'dealer on top row then max 2 rows of 5 players
  271.     FOR i = 1 TO nPlayers
  272.         IF i <> nPlayers THEN
  273.             SELECT CASE i 'vvvvvvvvvvvvvvvvvvvvvvvvvvvv plug in ai names here
  274.                 CASE 1: p(i).ID = "Johnno"
  275.                 CASE 2: p(i).ID = "Steve"
  276.                 CASE 3: p(i).ID = "AI 1"
  277.                 CASE 4: p(i).ID = "AI 2"
  278.                 CASE 5: p(i).ID = "2nd AI 1"
  279.                 CASE 6: p(i).ID = "2nd AI 2"
  280.             END SELECT
  281.             p(i).Col = 2 + (i - 1) * 21
  282.             p(i).Row = 15
  283.             p(i).Chips = 100
  284.             p(i).SetBet = 2
  285.             IF i MOD 2 THEN
  286.                 p(i).BC = _RGB32(RND * 128, RND * 60, RND * 128)
  287.             ELSE
  288.                 p(i).BC = _RGB32(RND * 128 + 127, 255 - RND * 95, RND * 128 + 127)
  289.             END IF
  290.             IF i MOD 2 THEN p(i).FC = &HFFFFFFFF ELSE p(i).FC = &HFF000000
  291.         ELSE
  292.             p(i).ID = "Dealer"
  293.             p(i).Col = (xmax \ 8 - 20) \ 2 + 1
  294.             p(i).Row = 2
  295.             p(i).Chips = -100 * (nPlayers - 1)
  296.             p(i).BC = &HFF000000
  297.             p(i).FC = &HFFFFFFFF
  298.         END IF
  299.     NEXT
  300.     FOR i = 1 TO 52 'get deck ready
  301.         deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  302.     NEXT
  303.  
  304.     COLOR fc, bc: CLS
  305.  
  306. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  307.     IF nPlayer THEN
  308.         COLOR p(nPlayer).FC, p(nPlayer).BC
  309.         LOCATE p(nPlayer).Row + row, p(nPlayer).Col + (bW - LEN(s)) / 2: PRINT s;
  310.     ELSE
  311.         COLOR fc, bc
  312.         PRINT s, row, (xmax \ 8 - LEN(s)) / 2 + 1
  313.         LOCATE row, (xmax \ 8 - LEN(s)) / 2 + 1: PRINT s;
  314.     END IF
  315.  
  316.  


Title: Re: Blackjack
Post by: George McGinn on July 08, 2020, 09:28:07 pm
When I run the BJ Dealer Test program on macOS, I get the following errors (I'm running v1.4 of QB64:



In file included from qbx.cpp:2226:
./../temp/main.txt:100:33: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_new_txt_len("",0));
                  ~~~~~~~~~~~~~~^
./../temp/main.txt:135:46: error: arithmetic on a pointer to void
qbs_set(tqbs,qbs_right(*((qbs**)(__UDT_DEALER+(8))), 1 ));
                                 ~~~~~~~~~~~~^
./../temp/main.txt:304:33: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                  ~~~~~~~~~~~~~~^
./../temp/main.txt:304:70: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                                                         ~~~~~~~~~~~~^
./../temp/main.txt:337:116: error: arithmetic on a pointer to void
if ((qbs_cleanup(qbs_tmp_base,-(func_instr(NULL,qbs_new_txt_len("A23456789XJQK",13),func_mid(*((qbs**)(__UDT_DEALER+(8))),*_SUB_PLAYERADDCARD_INTEGER_I, 1 ,1),0)> 10 )))||new_error){
                                                                                                       ~~~~~~~~~~~~^
./../temp/main.txt:344:115: error: arithmetic on a pointer to void
*_SUB_PLAYERADDCARD_INTEGER_CV=func_instr(NULL,qbs_new_txt_len("A23456789XJQK",13),func_mid(*((qbs**)(__UDT_DEALER+(8))),*_SUB_PLAYERADDCARD_INTEGER_I, 1 ,1),0);
                                                                                                      ~~~~~~~~~~~~^
6 errors generated.
Title: Re: Blackjack
Post by: George McGinn on July 08, 2020, 09:32:57 pm
@bplus - I might take you up on creating a playing AI.

Give me about a month. I'm waiting to hear if I have been approved to buy a house, and may have to move quickly, by July 31. This means I'll be spending my time packing most of July.
Title: Re: Blackjack
Post by: George McGinn on July 08, 2020, 09:46:08 pm
WOW!

Who Knew? I sure didn't. I just thought it was the most expedient way to do a random sort without having a SWAP statement.

I tested it with 8 decks (without all the print statements) and it still finished in hundreds or milliseconds.

I guess you should add my name to the WIKI, as I just co-invented it!!!

George

Hi @George McGinn

I see you come from Steve McNeil's camp of swapping each card with any of the other 52 cards.

There is a math proof that this is not ideal and leaves slightly less than perfect random distribution (given perfect random generator but who has that?)

"https://en.wikipedia.org/wiki/Fisher–Yates_shuffle"  <<copy/paste between quotes this in browser because underline link usually fails.

Look under Naive Shuffle:
 

Title: Re: Blackjack
Post by: bplus on July 08, 2020, 10:25:18 pm
Quote
When I run the BJ Dealer Test program on macOS, I get the following errors (I'm running v1.4 of QB64:

@George McGinn

Copy Paste test of code from forum to double check in my Windows 10 laptop, works fine!

Looks like macOS doesn't like QB64 so much?
Title: Re: Blackjack
Post by: FellippeHeitor on July 08, 2020, 11:33:33 pm
The bug with variable width strings in UDTs on macOS is already under investigation: https://github.com/QB64Team/qb64/issues/64
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 12:00:22 am
@Qwerkey

As promised the Blackjack Game, BJ v2020-07-08 updated with more or better comments:
(Nothing has been changed in the code, for those who have already downloaded the July 4th version.)

I have updated this game with a more enjoyable playing game, not exactly casino rules...

see Best answer for download.

Title: Re: Blackjack
Post by: bplus on July 09, 2020, 12:25:58 am
Here is another little update to the Multi-AI Tester #3, I moved all the AI's to the bottom of the subs area and added a bunch of simple ones to test different Stay numbers side by side, I suppose it'd take a very, very long run to actually distinguish the different Stay strategies and just plain luck of the cards.

I named the Stay 16 limit after George because he spoke of it sorta, and I named Stay 18 after Steve2 because he might have been meaning to Stay one more card over what the Dealer has to stay at, preliminary tests suggest they are all better than Stay 12 (so you can never be busted). B3 is Stay 16 plus Double Down only at 11.

Code: QB64: [Select]
  1. ' No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  2. '2020-07-05 fix hit (it wasn't broken), delete line chose$ = inkey$ before loop
  3. ' force dealer to hit on 16 stay 17
  4. ' ties are push
  5. ' bring in double down option
  6. ' fix dealer has Blackjack should tell also fix exposing 2nd card
  7. ' work this towards converting to multiple AI players, so players stats are all located in PlayerType
  8. ' 2020-07-06 Installed AI and mods for it
  9. ' 2020-07-06 new Compact Tester with 2nd AI
  10. ' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester
  11. '            add in allot of code worked out in Blackjack with Bots 2019-06-07
  12. '            Yes, major overhaul of last year bot code which was/is neat!
  13. '            Thanks Johnno and Steve for some interesting AI ideas to try!
  14. ' 2020-07-07 for Blackjack Multi AI Tester #2, I hope to do something kind of interesting with displaying players
  15. '            Yes Mouse over a player you want to check on but try and stay out of way of updating.
  16. ' 2020-07-08 No overlapping players, sucks, get rid of timer stuff, removed.
  17. '            Screen Size depends on how many players go against Dealer from 1 to 6 maximum.
  18. '            1 row of players with screen width < 1024, Dealer at top.
  19. '            Added more items to Player type  to display status solely from it's array contents.
  20. '            Also forbid player to double down if es chips can't cover loss.
  21. '            Display round number in Title Bar
  22. ' 2020-07-08 added some basic stay strategies
  23. '=================================================================================================================
  24. ' Blackjack Multi-Tester Notes: (removed from screening at start)
  25.  
  26. '                              *** Blackjack Multi AI Tester #3 ***
  27. '
  28. '                     Each AI bot starts with 100 chips and bets 2 each round.
  29. '                                Dealer must hit on 16 or less.
  30. '                                 Blackjack pays 1.5 X the bet.
  31. '                       Double down option available when you get 2 cards.
  32. '                         It Doubles the bet and you get one more card.
  33. '
  34. '====================================================================================================================
  35.  
  36. DEFINT A-Z
  37.  
  38. CONST nPlayers = 7 '            2 to 7 only! Dealer counts as the last player Screen size is adjusted to this!
  39. CONST rank$ = "A23456789XJQK" ' for building deck and figuring Totals
  40. CONST bH = 12, bW = 20 '        box height and box width in rows and columns
  41. CONST bc = &HFF008822, fc = &HFFCCCCFF ' screen back and fore colors , no printing though
  42.  
  43. TYPE PlayerType
  44.     ID AS STRING '        name of bot including dealer bot
  45.     Col AS INTEGER '      left corner column
  46.     Row AS INTEGER '      top row
  47.     FC AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White
  48.     BC AS _UNSIGNED LONG 'random light and dark opposite print FC
  49.     Hand AS STRING '      cards are 1 char strings 10 is X
  50.     Ace AS INTEGER '      flag has ace for totalling hand
  51.     Bust AS INTEGER '     flag for final reckoning
  52.     BJ AS INTEGER '       flag for final reckoning
  53.     Total AS INTEGER '    card total of hand
  54.     Chips AS _INTEGER64 ' players status
  55.     SetBet AS _INTEGER64 'regular bet amount
  56.     Bet AS _INTEGER64 '   players bet each round
  57.     Tell AS STRING '      Hit, Stay Double or Win Push Loss Amt goal to put everything in PlayerType that showPlayer needs for display
  58.  
  59. DIM SHARED xmax, deck$(1 TO 52), p(1 TO nPlayers) AS PlayerType, deckIndex, round, allOut, player, blockDealer
  60.  
  61. DIM i, chose$
  62. initGame
  63. 'FOR i = 1 TO nPlayers
  64. '    showPlayer i
  65. 'NEXT
  66. 'SLEEP
  67. 'END
  68. DO 'start a round
  69.     startRound 'clears screen too and shuffles deck
  70.  
  71.     FOR i = 1 TO 2
  72.         FOR player = 1 TO nPlayers 'each Player is dealt 2 cards
  73.             IF player <> nPlayers THEN
  74.                 IF p(player).Chips > 0 THEN
  75.                     allOut = 0 'signal everyone is out of chips is false
  76.                     PlayerAddCard player
  77.                 END IF
  78.             ELSE
  79.                 IF allOut THEN
  80.                     EXIT DO
  81.                 ELSE
  82.                     PlayerAddCard player
  83.                 END IF
  84.             END IF
  85.         NEXT
  86.     NEXT
  87.  
  88.     IF p(nPlayers).BJ = 0 THEN 'dealer does not have BJ
  89.         FOR player = 1 TO nPlayers - 1
  90.             showPlayer player
  91.             WHILE p(player).Total < 21
  92.                 SELECT CASE player ' this has to be coded for exactly all nPlayers - 1
  93.                     CASE 1: chose$ = Johnno$(player)
  94.                     CASE 2: chose$ = Steve$(player)
  95.                     CASE 3: chose$ = stay16$(player)
  96.                     CASE 4: chose$ = stay17$(player)
  97.                     CASE 5: chose$ = stay18$(player)
  98.                     CASE 6: chose$ = bplusAI3$(player) 'no more than 6 bots
  99.                 END SELECT
  100.                 IF chose$ = "h" THEN p(player).Tell = "Hit"
  101.                 IF chose$ = "d" THEN p(player).Tell = "Double Down"
  102.                 IF chose$ <> "h" AND chose$ <> "d" THEN p(player).Tell = "Stay"
  103.                 showPlayer player
  104.                 _DELAY 2
  105.                 IF chose$ = "h" THEN
  106.                     PlayerAddCard player
  107.                 ELSEIF chose$ = "d" AND LEN(p(player).Hand) = 2 THEN
  108.                     p(player).Bet = 2 * p(player).Bet
  109.                     PlayerAddCard player
  110.                     EXIT WHILE
  111.                 ELSE 'stayed
  112.                     EXIT WHILE
  113.                 END IF
  114.             WEND
  115.         NEXT
  116.     END IF
  117.  
  118.     blockDealer = 0
  119.     showPlayer nPlayers
  120.     WHILE p(nPlayers).Total < 17
  121.         p(nPlayers).Tell = "Dealer takes a card."
  122.         showPlayer nPlayers
  123.         PlayerAddCard nPlayers
  124.     WEND
  125.     p(nPlayers).Tell = "Reckoning"
  126.     showPlayer nPlayers
  127.  
  128.     '    final Reckoning
  129.     FOR player = 1 TO nPlayers - 1
  130.         showPlayer player
  131.         IF p(player).BJ AND p(nPlayers).BJ THEN
  132.             p(player).Tell = "Push"
  133.         ELSEIF p(player).Total > 21 OR (p(player).Total < p(nPlayers).Total AND p(nPlayers).Total < 22) THEN
  134.             p(player).Tell = "Lost" + STR$(p(player).Bet)
  135.             p(player).Chips = p(player).Chips - p(player).Bet
  136.             p(nPlayers).Chips = p(nPlayers).Chips + p(player).Bet
  137.         ELSEIF p(player).Total = p(nPlayers).Total AND p(player).BJ = 0 THEN
  138.             p(player).Tell = "Push"
  139.         ELSE
  140.             IF p(player).BJ THEN
  141.                 p(player).Tell = "Win!" + STR$(p(player).Bet + .5 * p(player).Bet)
  142.                 p(player).Chips = p(player).Chips + p(player).Bet + .5 * p(player).Bet
  143.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet - .5 * p(player).Bet
  144.             ELSE
  145.                 p(player).Tell = "Win!" + STR$(p(player).Bet)
  146.                 p(player).Chips = p(player).Chips + p(player).Bet
  147.                 p(nPlayers).Chips = p(nPlayers).Chips - p(player).Bet
  148.             END IF
  149.         END IF
  150.         showPlayer player
  151.         _DELAY 1 'an extra delay
  152.         IF p(player).Chips = 0 THEN
  153.             p(player).Tell = "Out of chips!":
  154.             showPlayer player
  155.             _DELAY 2 ' an extra delay
  156.         END IF
  157.     NEXT
  158. LOOP UNTIL allOut
  159.  
  160. SUB startRound
  161.     DIM i
  162.     COLOR fc, bc: CLS
  163.     round = round + 1: allOut = -1
  164.     FOR i = 1 TO nPlayers
  165.         p(i).Hand = ""
  166.         p(i).Ace = 0
  167.         p(i).Total = 0
  168.         p(i).BJ = 0
  169.         p(i).Bust = 0
  170.         p(i).Tell = ""
  171.         'because of double down option I have to reset bet during play and set it back at each new round
  172.         'make sure we aren't betting more than our chips count at least to start
  173.         IF p(i).Chips < p(i).SetBet THEN p(i).Bet = p(i).Chips ELSE p(i).Bet = p(i).SetBet
  174.     NEXT
  175.     FOR i = 52 TO 2 STEP -1 'shuffle
  176.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  177.     NEXT
  178.     'deck$(5) = "A": deck$(10) = "J"  'check immediate show of Blackjack for dealer
  179.     deckIndex = 0: blockDealer = -1
  180.     _TITLE "BJ AI Tester Round:" + STR$(round)
  181.  
  182. SUB PlayerAddCard (rec) 'updates player's hand and total
  183.     DIM i AS INTEGER, cv AS INTEGER
  184.     deckIndex = deckIndex + 1
  185.     p(rec).Hand = p(rec).Hand + deck$(deckIndex)
  186.     IF deck$(deckIndex) = "A" THEN p(rec).Ace = -1
  187.     p(rec).Total = 0
  188.     FOR i = 1 TO LEN(p(rec).Hand)
  189.         IF INSTR(rank$, MID$(p(rec).Hand, i, 1)) > 10 THEN cv = 10 ELSE cv = INSTR(rank$, MID$(p(rec).Hand, i, 1))
  190.         p(rec).Total = p(rec).Total + cv
  191.     NEXT
  192.     IF p(rec).Total < 12 AND p(rec).Ace THEN p(rec).Total = p(rec).Total + 10
  193.     IF LEN(p(rec).Hand) = 2 AND p(rec).Total = 21 THEN p(rec).BJ = -1
  194.     IF p(rec).Total > 21 THEN p(rec).Bust = -1
  195.     showPlayer rec 'when ever add card show update
  196.  
  197. SUB showPlayer (nPlayer) '
  198.     DIM i AS INTEGER, S$
  199.     COLOR p(nPlayer).FC, p(nPlayer).BC
  200.     FOR i = 0 TO bH - 1 'clear our block
  201.         LOCATE p(nPlayer).Row + i, p(nPlayer).Col: PRINT SPACE$(bW);
  202.     NEXT
  203.     cp nPlayer, 1, p(nPlayer).ID
  204.     cp nPlayer, 3, "Chips:" + STR$(p(nPlayer).Chips)
  205.     IF nPlayer <> nPlayers THEN cp nPlayer, 4, "Bet:" + STR$(p(nPlayer).Bet)
  206.     FOR i = 1 TO LEN(p(nPlayer).Hand)
  207.         S$ = S$ + MID$(p(nPlayer).Hand, i, 1) + " "
  208.     NEXT
  209.     IF nPlayer = nPlayers AND LEN(p(nPlayer).Hand) = 2 AND p(nPlayer).Total <> 21 AND blockDealer THEN
  210.         S$ = LEFT$(S$, 2) + "?"
  211.         cp nPlayer, 6, S$
  212.         cp nPlayer, 7, "Total: ??"
  213.     ELSE
  214.         cp nPlayer, 6, S$
  215.         cp nPlayer, 7, "Total:" + STR$(p(nPlayer).Total)
  216.     END IF
  217.     IF p(nPlayer).Bust THEN cp nPlayer, 8, "Busted"
  218.     IF p(nPlayer).BJ THEN cp nPlayer, 8, "Blackjack"
  219.     cp nPlayer, 10, p(nPlayer).Tell ' last action of player or dealer or final win lost push
  220.     _DELAY 1 'when ever showPlayer  need a delay to read
  221.  
  222. SUB initGame 'the stuff that never changes
  223.     DIM i
  224.     ' 1+13*2 rows = 27*16 = 432 ymax
  225.     xmax = ((nPlayers - 1) * 21 + 1) * 8
  226.     SCREEN _NEWIMAGE(xmax, 432, 32)
  227.     _DELAY .25
  228.  
  229.     'dealer on top row then max 2 rows of 5 players
  230.     FOR i = 1 TO nPlayers
  231.         IF i <> nPlayers THEN
  232.             SELECT CASE i 'vvvvvvvvvvvvvvvvvvvvvvvvvvvv plug in ai names here
  233.                 CASE 1: p(i).ID = "Johnno"
  234.                 CASE 2: p(i).ID = "Steve Stay 12"
  235.                 CASE 3: p(i).ID = "George Stay 16"
  236.                 CASE 4: p(i).ID = "Dealer Stay 17"
  237.                 CASE 5: p(i).ID = "Steve2 Stay 18"
  238.                 CASE 6: p(i).ID = "b3 stay16 dd11"
  239.             END SELECT
  240.             p(i).Col = 2 + (i - 1) * 21
  241.             p(i).Row = 15
  242.             p(i).Chips = 100
  243.             p(i).SetBet = 2
  244.             IF i MOD 2 THEN
  245.                 p(i).BC = _RGB32(RND * 128, RND * 60, RND * 128)
  246.             ELSE
  247.                 p(i).BC = _RGB32(RND * 128 + 127, 255 - RND * 95, RND * 128 + 127)
  248.             END IF
  249.             IF i MOD 2 THEN p(i).FC = &HFFFFFFFF ELSE p(i).FC = &HFF000000
  250.         ELSE
  251.             p(i).ID = "Dealer"
  252.             p(i).Col = (xmax \ 8 - 20) \ 2 + 1
  253.             p(i).Row = 2
  254.             p(i).Chips = -100 * (nPlayers - 1)
  255.             p(i).BC = &HFF000000
  256.             p(i).FC = &HFFFFFFFF
  257.         END IF
  258.     NEXT
  259.     FOR i = 1 TO 52 'get deck ready
  260.         deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  261.     NEXT
  262.  
  263.     COLOR fc, bc: CLS
  264.  
  265. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  266.     IF nPlayer THEN
  267.         COLOR p(nPlayer).FC, p(nPlayer).BC
  268.         LOCATE p(nPlayer).Row + row, p(nPlayer).Col + (bW - LEN(s)) / 2: PRINT s;
  269.     ELSE
  270.         COLOR fc, bc
  271.         PRINT s, row, (xmax \ 8 - LEN(s)) / 2 + 1
  272.         LOCATE row, (xmax \ 8 - LEN(s)) / 2 + 1: PRINT s;
  273.     END IF
  274.  
  275. ' ======================================= AI storage Area #51
  276.  
  277. FUNCTION bplusAI$ (pn) ' first try
  278.     SELECT CASE p(pn).Total
  279.         CASE IS < 10: bplusAI$ = "h" 'no caps!
  280.         CASE 10, 11
  281.             IF LEN(p(pn).Hand) = 2 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  282.         CASE IS < 15
  283.             IF RND < .5 THEN bplusAI$ = "h" ELSE bplusAI$ = "whatever"
  284.         CASE ELSE: bplusAI$ = "Show me the money!"
  285.     END SELECT
  286.  
  287. FUNCTION bplusAI2$ (pN) 'after trying first want to try this make it more likely to hit on 12 than 13, 14...
  288.     SELECT CASE p(pN).Total
  289.         CASE IS < 10: bplusAI2$ = "h" 'no caps!
  290.         CASE 10, 11 'double down unless dealer showing an Ace which is like insurance for dealer
  291.             IF LEN(p(pN).Hand) = 2 AND LEFT$(p(nPlayers).Hand, 1) <> "A" THEN bplusAI2$ = "d" ELSE bplusAI2$ = "h"
  292.         CASE 12: IF RND < .75 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  293.         CASE 13: IF RND < .5 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  294.         CASE 14: IF RND < .25 THEN bplusAI2$ = "h" ELSE bplusAI2$ = "whatever"
  295.         CASE ELSE: bplusAI2$ = "Show me the money!"
  296.     END SELECT
  297.  
  298. FUNCTION bplusAI3$ (pn) ' first try modified to stay 16 plus dd on 11 only
  299.     SELECT CASE p(pn).Total
  300.         CASE 11
  301.             IF LEN(p(pn).Hand) = 2 THEN bplusAI3$ = "d" ELSE bplusAI3$ = "h"
  302.         CASE IS < 16: bplusAI3$ = "h"
  303.     END SELECT
  304.  
  305. FUNCTION Johnno$ (pN)
  306.     IF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) = 2 THEN
  307.         Johnno$ = "d"
  308.     ELSEIF p(pN).Total = 10 OR p(pN).Total = 11 AND LEN(p(pN).Hand) <> 2 THEN
  309.         Johnno$ = "h"
  310.     ELSEIF 12 <= p(pN).Total AND p(pN).Total <= 15 THEN
  311.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  312.             CASE "A", "K", "Q", "J", "X", "9": Johnno$ = "h"
  313.             CASE "7", "8": IF RND < .5 THEN Johnno$ = "h"
  314.             CASE ELSE: Johnno$ = "Hope to Bust em"
  315.         END SELECT
  316.     ELSEIF p(pN).Total < 12 THEN
  317.         Johnno$ = "h"
  318.     ELSE
  319.         Johnno$ = "Stay"
  320.     END IF
  321.  
  322. FUNCTION Steve$ (pN) 'how simple is this! never bust make dealer work for it
  323.     IF p(pN).Total < 12 THEN Steve$ = "h"
  324.  
  325. FUNCTION stay16$ (pN) ' calling this George because he seems to agree, might want to do more about what Dealer is showing
  326.     IF p(pN).Total < 16 THEN stay16$ = "h"
  327. FUNCTION stay17$ (pN)
  328.     IF p(pN).Total < 17 THEN stay17$ = "h"
  329. FUNCTION stay18$ (pN) 'this might have been what Steve was talking about so calling it Steve2
  330.     IF p(pN).Total < 18 THEN stay18$ = "h"
  331.  
  332.  
  333.  
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 01:12:22 am
The bug with variable width strings in UDTs on macOS is already under investigation: https://github.com/QB64Team/qb64/issues/64

Hey it's not one of those CHR$(0) at the end of the string things is it?
Title: Re: Blackjack
Post by: codeguy on July 09, 2020, 03:16:08 am
I would choose Knuth Shuffle for shuffling cards or for any randomization of order.
Code: QB64: [Select]
  1. TYPE card
  2.     cardVAL AS _UNSIGNED _BYTE
  3.     CARDsuit AS STRING * 7
  4. DIM NSUITSMIN AS _UNSIGNED INTEGER: NSUITSMIN = 1
  5. DIM NSUITSMAX AS _UNSIGNED INTEGER: NSUITSMAX = 4
  6. DIM NCARDSMIN AS _UNSIGNED INTEGER: NCARDSMIN = 1
  7. DIM NCARDSMAX AS _UNSIGNED INTEGER: NCARDSMAX = 13
  8. REDIM Deck(1 TO (NSUITSMAX - NSUITSMIN + 1) * (NCARDSMAX - NCARDSMIN + 1)) AS card
  9.  
  10. FOR S = NSUITSMIN TO NSUITSMAX
  11.     READ SUIT
  12.     FOR T = NCARDSMIN TO NCARDSMAX
  13.         Deck(X).CARDsuit = SUIT
  14.         Deck(X).cardVAL = T
  15.         X = X + 1
  16.     NEXT
  17. DATA DIAMOND,SPADE,HEART,CLUB
  18. KnuthShuffle Deck(), LBOUND(DECK), UBOUND(DECK)
  19. SUB KnuthShuffle (a() AS card, start AS _INTEGER64, finish AS _INTEGER64)
  20.     DIM KNUTHSHUFFLE_AX AS _INTEGER64
  21.     DIM KNUTHSHUFFLE_BX AS _INTEGER64
  22.     KNUTHSHUFFLE_BX = start
  23.     DO
  24.         KNUTHSHUFFLE_AX = KNUTHSHUFFLE_BX
  25.         KNUTHSHUFFLE_BX = KNUTHSHUFFLE_AX + 1
  26.         SWAP a(KNUTHSHUFFLE_AX), a(KNUTHSHUFFLE_BX + INT(RND * (finish - KNUTHSHUFFLE_BX)))
  27.     LOOP UNTIL KNUTHSHUFFLE_AX > finish - 1
  28.  
Title: Re: Blackjack
Post by: FellippeHeitor on July 09, 2020, 08:12:42 am
Hey it's not one of those CHR$(0) at the end of the string things is it?
No, it isn't.
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 11:16:53 am
Quote
I would choose Knuth Shuffle for shuffling cards or for any randomization of order.

Yep! AKA Fisher-Yates shuffle, don't leave home without it 👍
Title: Re: Blackjack
Post by: George McGinn on July 09, 2020, 11:41:05 am
Are there any specific coding for windows?

Since I have been coded in windows since the mid-1990s, plus one project I did in 2000–2001, I very rarely use windows because it always bothered to down my computer where macOS and Linux does not.

In macOS and Linux I very rarely get errors, unless there’s code for a specific operation system.


@George McGinn

Copy Paste test of code from forum to double check in my Windows 10 laptop, works fine!

Looks like macOS doesn't like QB64 so much?
Title: Re: Blackjack
Post by: George McGinn on July 09, 2020, 11:52:08 am
That makes sense. I do not think macOS can handle CHR$(0) at end–of–line. Internally only requires a linefeed character which I believe is CHR$(13).

Later on today I’m gonna fire up my Linux machine and give it a try on that (I have Linux Mint LMDE4 version installed, with version 1.4 of QB64)

Also there is another area that may not be related to this and I like someone else to check it Because I’m now cross side trying to count all the open and closing brackets, but this error that happened I believe is a separate bug in QB64 in that there is not enough closing brackets in the statement generated below:

./../temp/main.txt:304:70: error: arithmetic on a pointer to void
qbs_set(*((qbs**)((__UDT_DEALER)+(8))),qbs_add(*((qbs**)(__UDT_DEALER+(8))),((qbs*)(((uint64*)(__ARRAY_STRING_DECK[0]))[array_check((*__INTEGER_DECKINDEX)-__ARRAY_STRING_DECK[4],__ARRAY_STRING_DECK[5])]))));
                                                         ~~~~~~~~~~~~^
George

Hey it's not one of those CHR$(0) at the end of the string things is it?
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 11:58:35 am
Quote
Are there any specific coding for windows?

I think QB64 is mainly developed in Windows and ported to other OS, logical because QB was started by MS from GW Basic for DOS and/or something else in between.

So Shell stuff certainly is Windows only and anything that might involve a call to Windows API has to be translated to other OS if there is equivalent services.

So QB64 might run most trouble free with all commands in Windows.

But being portable to other OS is very important to The Team I think and endorse.
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 12:04:31 pm
Quote
That makes sense. I do not think macOS can handle CHR$(0) at end–of–line. Internally only requires a linefeed character which I believe is CHR$(13).

Oh that's interesting, they end strings with... well CHR$(13) is Carriage Return, Line Feed is CHR$(10).

Is that true, is it a missing LF or CR? instead of CHR$(0) (always looking for the easy answer first!)

(About the macOS problems with UDT and/or variable length strings.)
Title: Re: Blackjack
Post by: bplus on July 09, 2020, 06:27:28 pm
Dang! 10019 Rounds on 200 chips, everyone else out before 3000
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Blackjack
Post by: bplus on July 10, 2020, 02:11:59 pm
OK I found a way to stop the drain of chips. Maybe you can figure it out from this screen shot, each player started with 200 chips and bet 2 each round unless they Doubled Down. After 1000 rounds:
 


Now I am chipper!
Title: Re: Blackjack
Post by: bplus on July 11, 2020, 07:27:39 pm
According to results found here in Multi-Tester #3 I am modifying the Blackjack Game for more fun!

Code: QB64: [Select]
  1. ' Started from code not using card images so:
  2. '            No suits shown for cards A is Ace, J, Q, K are Jack, Queen, King, X is for 10
  3. ' 2020-07-05 Fix hit (it wasn't broken), delete line chose$ = INKEY$ before loop
  4. '            force dealer to hit on 16 stay 17, ties are push, bring in double down option.
  5. '            Fix if dealer has Blackjack should tell also fix exposing 2nd card. Work this
  6. '            towards converting to multiple AI players, then all players stats are located
  7. '            in PlayerType and displayed with ShowPlayer (player) SUB.
  8. ' 2020-07-06 Installed AI and mods for it
  9. ' 2020-07-06 new Compact Tester with 2nd AI
  10. ' 2020-07-06 start Blackjack Multi AI Tester off of Compact Tester, add in allot of code worked
  11. '            out in Blackjack with Bots 2019-06-07.
  12. '            Yes, major overhaul of last year bot code which was/is neat!
  13. '            Thanks Johnno and Steve for some interesting AI ideas to try!
  14. ' 2020-07-07 For Blackjack Multi AI Tester #2, I hope to do something kind of interesting with
  15. '            displaying many players at one time.
  16. '            Yes Mouse over a player you want to check on but try and stay out of way of updating.
  17. ' 2020-07-08 BJ Multi AI Tester #3
  18. '            No overlapping players, sucks, get rid of timer stuff, removed.
  19. '            Screen Size depends on how many players go against Dealer from 1 to 6 maximum.
  20. '            1 row of players with screen width < 1024, Dealer at top.
  21. '            Added more items to Player type to display status solely from it's array contents.
  22. '            Also forbid player to double down if es chips can't cover loss.
  23. '            Display round number in Title Bar.
  24. ' 2020-07-08 added some basic stay strategies
  25. ' 2020-07-09 Some more fixes to Tester #3: Stop dealing cards to players without chips.
  26. '            Forbid DD if don't have chips to cover loss. Need Round number when run out of chips.
  27. '            First Johnno AI went over 10,000 rounds on 200 chips!
  28. ' 2020-07-10 I give up trying to find a strategy to stop draining a player of chips, so one
  29. '            little change in rules. ;-))  Something that Casinos would never do...
  30. ' 2020-07-11 Final adjustments to Tester #3
  31.  
  32. ' >>>>>>>>>>>  GOTO LINE #272 to adjust speed of play  uncomment _DELAY line
  33. ' >>>>>>>>>>> set to 1 or 2 to watch game play, .01 for fast round and watch chips
  34.  
  35. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  36.  
  37. '  CAUTION: IN THE INTEREST OF HAVING FUN PLAYING THIS GAME, WE HAVE DEVIATED FROM CASINO RULES.
  38.  
  39. '   NEVER THINK YOUR EXPERIENCE PLAYING THIS GAME HERE WOULD BE LIKE PLAYING IN A REAL CASINO!
  40.  
  41. ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  42.  
  43. ' Blackjack Multi-Tester Notes: (removed from screening at start)
  44.  
  45. '                              *** Blackjack Multi AI Tester #3 ***
  46. '
  47. '                     Each AI bot starts with 200 chips and bets 2 each round.
  48. '                                Dealer must hit on 16 or less.
  49. '                                 Blackjack pays 1.5 X the bet.
  50. '                       Double down option available when you get 2 cards.
  51. '                         It Doubles the bet and you get one more card.
  52. '
  53. '=================================================================================================
  54.  
  55. DEFINT A-Z
  56.  
  57. CONST nPlayers = 7 '            2 to 7 only! Dealer counts as the last player
  58. CONST rank$ = "A23456789XJQK" ' for building deck and figuring Totals
  59. CONST bH = 12, bW = 20 '        box height and box width in rows and columns
  60.  
  61. TYPE PlayerType '         Goal: Put everything in PlayerType that showPlayer needs for display
  62.     ID AS STRING '        name of bot including dealer bot
  63.     Col AS INTEGER '      left corner column for player box
  64.     Row AS INTEGER '      top row for player box
  65.     FC AS _UNSIGNED LONG 'player colors are assigned in init FC are alternating Black and White
  66.     BC AS _UNSIGNED LONG 'random light and dark opposite print FC
  67.     Hand AS STRING '      cards are 1 char strings 10 is X
  68.     Ace AS INTEGER '      flag ace for totaling hand
  69.     Bust AS INTEGER '     flag for final reckoning
  70.     BJ AS INTEGER '       flag for final reckoning
  71.     Tot AS INTEGER '      card total of hand
  72.     Chips AS _INTEGER64 ' players status
  73.     SetBet AS _INTEGER64 'regular bet amount if enough chips to cover
  74.     Bet AS _INTEGER64 '   players bet each round maybe updated by DD
  75.     Tell AS STRING '      Hit, Stay Double or Win Push Loss Amt
  76.     RunOut AS DOUBLE '    Round player runs out of chips
  77.  
  78. DIM SHARED p(1 TO nPlayers) AS PlayerType '        contains player data for processing and display
  79. DIM SHARED xmax '              Screen size _WIDTH is adjusted to number of players and stored here
  80. DIM SHARED deck$(1 TO 52), deckIndex '                         cards are just string * 1 see rank$
  81. DIM SHARED round AS LONG, allOut, plr, blockDealer, session
  82. DIM results(1 TO 6)
  83.  
  84. DIM i, chose$
  85. initGame
  86. FOR session = 1 TO 20
  87.     DO 'start a round
  88.         startRound 'clears screen too and shuffles deck
  89.  
  90.         FOR i = 1 TO 2
  91.             FOR plr = 1 TO nPlayers 'each Player is dealt 2 cards
  92.                 IF plr <> nPlayers THEN
  93.                     IF p(plr).Chips > 0 THEN
  94.                         allOut = 0 'signal everyone is out of chips is false
  95.                         PlayerAddCard plr
  96.                     END IF
  97.                 ELSE
  98.                     IF allOut THEN
  99.                         showPlayer nPlayers 'final chip count = 0 ? when all is said and done
  100.                         EXIT DO
  101.                     ELSE
  102.                         PlayerAddCard plr
  103.                     END IF
  104.                 END IF
  105.             NEXT
  106.         NEXT
  107.  
  108.         IF p(nPlayers).BJ = 0 THEN 'dealer does not have BJ
  109.             FOR plr = 1 TO nPlayers - 1
  110.                 IF p(plr).Chips > 0 THEN 'make sure player still can bet
  111.                     showPlayer plr
  112.                     WHILE p(plr).Tot < 21
  113.                         SELECT CASE plr ' this has to be coded for exactly all nPlayers - 1
  114.  
  115.                             'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Insert AI subs here !!!!!!!
  116.                             CASE 1: chose$ = bplusAI$(plr)
  117.                             CASE 2: chose$ = bplusAI2$(plr)
  118.                             CASE 3: chose$ = bplusAI3$(plr)
  119.                             CASE 4: chose$ = stay18$(plr)
  120.                             CASE 5: chose$ = stay17$(plr)
  121.                             CASE 6: chose$ = Johnno2$(plr) 'no more than 6 bots
  122.  
  123.                         END SELECT
  124.                         IF chose$ = "h" THEN p(plr).Tell = "Hit"
  125.                         IF chose$ = "d" THEN p(plr).Tell = "Double Down"
  126.                         IF chose$ <> "h" AND chose$ <> "d" THEN p(plr).Tell = "Stay"
  127.                         showPlayer plr
  128.                         IF chose$ = "h" THEN
  129.                             PlayerAddCard plr
  130.                         ELSEIF chose$ = "d" AND LEN(p(plr).Hand) = 2 THEN
  131.                             IF p(plr).Chips >= 2 * p(plr).Bet THEN '  chips to cover a DD?
  132.                                 p(plr).Bet = 2 * p(plr).Bet
  133.                                 PlayerAddCard plr
  134.                                 EXIT WHILE
  135.                             ELSE 'if not play it like a hit
  136.                                 PlayerAddCard plr
  137.                             END IF
  138.                         ELSE 'stayed
  139.                             EXIT WHILE
  140.                         END IF
  141.                     WEND
  142.                 END IF
  143.             NEXT
  144.         END IF
  145.  
  146.         blockDealer = 0
  147.         showPlayer nPlayers '                 nPlayers is Dealer player number
  148.         WHILE p(nPlayers).Tot < 17
  149.             p(nPlayers).Tell = "Dealer hits"
  150.             showPlayer nPlayers
  151.             PlayerAddCard nPlayers
  152.         WEND
  153.         p(nPlayers).Tell = "Reckoning"
  154.         showPlayer nPlayers
  155.  
  156.         '    final Reckoning
  157.         FOR plr = 1 TO nPlayers - 1
  158.             IF p(plr).Chips > 0 THEN
  159.                 showPlayer plr
  160.                 IF (p(plr).BJ AND p(nPlayers).BJ) OR (p(plr).Bust AND p(nPlayers).Bust) THEN
  161.                     p(plr).Tell = "Push"
  162.                 ELSEIF p(plr).Tot > 21 OR (p(plr).Tot < p(nPlayers).Tot AND p(nPlayers).Tot < 22) THEN
  163.                     p(plr).Tell = "Lost" + STR$(p(plr).Bet)
  164.                     p(plr).Chips = p(plr).Chips - p(plr).Bet
  165.                     p(nPlayers).Chips = p(nPlayers).Chips + p(plr).Bet
  166.                 ELSEIF p(plr).Tot = p(nPlayers).Tot AND p(plr).BJ = 0 THEN
  167.                     p(plr).Tell = "Push"
  168.                 ELSE
  169.                     IF p(plr).BJ THEN
  170.                         p(plr).Tell = "Win!" + STR$(p(plr).Bet + .5 * p(plr).Bet)
  171.                         p(plr).Chips = p(plr).Chips + p(plr).Bet + .5 * p(plr).Bet
  172.                         p(nPlayers).Chips = p(nPlayers).Chips - p(plr).Bet - .5 * p(plr).Bet
  173.                     ELSE
  174.                         p(plr).Tell = "Win!" + STR$(p(plr).Bet)
  175.                         p(plr).Chips = p(plr).Chips + p(plr).Bet
  176.                         p(nPlayers).Chips = p(nPlayers).Chips - p(plr).Bet
  177.                     END IF
  178.                 END IF
  179.                 showPlayer plr
  180.                 IF p(plr).Chips = 0 THEN
  181.                     p(plr).RunOut = round
  182.                     p(plr).Tell = "Out of chips!"
  183.                     showPlayer plr
  184.                 END IF
  185.             END IF
  186.         NEXT
  187.     LOOP UNTIL allOut OR round = 1000 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Control # rounds !!!!!!!!!!!!
  188.     round = 0
  189.     COLOR &HFFCCCCFF, &HFF008822: CLS: _DISPLAY
  190.     FOR plr = 1 TO 6
  191.         LOCATE plr + 3, 5: PRINT p(plr).ID
  192.     NEXT
  193.     FOR plr = 1 TO 6
  194.         results(plr) = results(plr) + p(plr).Chips - 200 'the chips started with
  195.         LOCATE plr + 3, 17: PRINT results(plr)
  196.         p(plr).Chips = 200 'reset chips to start amount
  197.     NEXT
  198.     _DISPLAY
  199.  
  200. SUB startRound
  201.     DIM i
  202.     round = round + 1: allOut = -1
  203.     FOR i = 1 TO nPlayers
  204.         p(i).Hand = ""
  205.         p(i).Ace = 0
  206.         p(i).Tot = 0
  207.         p(i).BJ = 0
  208.         p(i).Bust = 0
  209.         p(i).Tell = ""
  210.         'because of DD option I have to reset bet during play and set it back at each new round
  211.         'make sure we aren't betting more than our chips count at least to start
  212.         IF p(i).Chips < p(i).SetBet THEN p(i).Bet = p(i).Chips ELSE p(i).Bet = p(i).SetBet
  213.     NEXT
  214.     FOR i = 52 TO 2 STEP -1 'shuffle
  215.         SWAP deck$(INT(RND * i) + 1), deck$(i)
  216.     NEXT
  217.     'deck$(7) = "A": deck$(14) = "J"  'check immediate show of Blackjack for dealer
  218.     deckIndex = 0: blockDealer = -1
  219.     _TITLE "BJ AI Tester #3 - Session:" + STR$(session) + "  Round:" + STR$(round)
  220.  
  221. SUB PlayerAddCard (rec) 'updates player's hand and total
  222.     DIM i AS INTEGER, cv AS INTEGER
  223.     deckIndex = deckIndex + 1
  224.     p(rec).Hand = p(rec).Hand + deck$(deckIndex)
  225.     IF deck$(deckIndex) = "A" THEN p(rec).Ace = -1
  226.     p(rec).Tot = 0
  227.     FOR i = 1 TO LEN(p(rec).Hand)
  228.         IF INSTR(rank$, MID$(p(rec).Hand, i, 1)) > 10 THEN
  229.             cv = 10
  230.         ELSE
  231.             cv = INSTR(rank$, MID$(p(rec).Hand, i, 1))
  232.         END IF
  233.         p(rec).Tot = p(rec).Tot + cv
  234.     NEXT
  235.     IF p(rec).Tot < 12 AND p(rec).Ace THEN p(rec).Tot = p(rec).Tot + 10
  236.     IF LEN(p(rec).Hand) = 2 AND p(rec).Tot = 21 THEN p(rec).BJ = -1
  237.     IF p(rec).Tot > 21 THEN p(rec).Bust = -1
  238.     showPlayer rec 'when ever add card show update
  239.  
  240. SUB showPlayer (nP) '
  241.     DIM i AS INTEGER, S$
  242.     COLOR p(nP).FC, p(nP).BC
  243.     FOR i = 0 TO bH - 1 'clear our block
  244.         LOCATE p(nP).Row + i, p(nP).Col: PRINT SPACE$(bW);
  245.     NEXT
  246.     cp nP, 1, p(nP).ID
  247.     cp nP, 3, "Chips:" + STR$(p(nP).Chips)
  248.     IF nP <> nPlayers THEN cp nP, 4, "Bet:" + STR$(p(nP).Bet)
  249.     FOR i = 1 TO LEN(p(nP).Hand)
  250.         S$ = S$ + MID$(p(nP).Hand, i, 1) + " "
  251.     NEXT
  252.     IF nP = nPlayers AND LEN(p(nP).Hand) = 2 AND p(nP).Tot <> 21 AND blockDealer THEN
  253.         S$ = LEFT$(S$, 2) + "?"
  254.         cp nP, 6, S$
  255.         cp nP, 7, "Total: ??"
  256.     ELSE
  257.         cp nP, 6, S$
  258.         cp nP, 7, "Total:" + STR$(p(nP).Tot)
  259.     END IF
  260.     IF p(nP).Bust THEN cp nP, 8, "Busted"
  261.     IF p(nP).BJ THEN cp nP, 8, "Blackjack"
  262.     IF p(nP).RunOut THEN cp nP, 9, "Round" + STR$(p(nP).RunOut)
  263.     cp nP, 10, p(nP).Tell ' last action of player or dealer or final win lost push
  264.     _DISPLAY
  265.    272 '_DELAY 1 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< modify this line for speed !!!!!!!!
  266.  
  267. SUB initGame 'the stuff that never changes
  268.     CONST startChips = 200
  269.     DIM i
  270.     ' 1+13*2 rows = 27*16 = 432 ymax
  271.     xmax = ((nPlayers - 1) * 21 + 1) * 8
  272.     SCREEN _NEWIMAGE(xmax, 432, 32)
  273.     _DELAY .25
  274.  
  275.     'dealer on top row then max 2 rows of 5 players
  276.     FOR i = 1 TO nPlayers
  277.         IF i <> nPlayers THEN
  278.             SELECT CASE i 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV  plug in ai names here !!!!!!!!
  279.                 CASE 1: p(i).ID = "b1 s17 dd1"
  280.                 CASE 2: p(i).ID = "b2 s17 dd2"
  281.                 CASE 3: p(i).ID = "b3 s17 dd3"
  282.                 CASE 4: p(i).ID = "s18"
  283.                 CASE 5: p(i).ID = "s17"
  284.                 CASE 6: p(i).ID = "johnno 2"
  285.             END SELECT
  286.             p(i).Col = 2 + (i - 1) * 21
  287.             p(i).Row = 15
  288.             p(i).Chips = startChips
  289.             p(i).SetBet = 2
  290.             IF i MOD 2 THEN
  291.                 p(i).BC = _RGB32(RND * 128, RND * 60, RND * 128)
  292.             ELSE
  293.                 p(i).BC = _RGB32(RND * 128 + 127, 255 - RND * 95, RND * 128 + 127)
  294.             END IF
  295.             IF i MOD 2 THEN p(i).FC = &HFFFFFFFF ELSE p(i).FC = &HFF000000
  296.         ELSE
  297.             p(i).ID = "Dealer"
  298.             p(i).Col = (xmax \ 8 - 20) \ 2 + 1
  299.             p(i).Row = 2
  300.             p(i).Chips = -startChips * (nPlayers - 1)
  301.             p(i).BC = &HFF000000
  302.             p(i).FC = &HFFFFFFFF
  303.         END IF
  304.     NEXT
  305.     FOR i = 1 TO 52 'get deck ready
  306.         deck$(i) = MID$(rank$ + rank$ + rank$ + rank$, i, 1)
  307.     NEXT
  308.     COLOR &HFFCCCCFF, &HFF008822: CLS
  309.  
  310. SUB cp (nPlayer, row, s AS STRING) 'center print a string on the given row
  311.     IF nPlayer THEN
  312.         COLOR p(nPlayer).FC, p(nPlayer).BC
  313.         LOCATE p(nPlayer).Row + row, p(nPlayer).Col + (bW - LEN(s)) / 2: PRINT s;
  314.     END IF
  315.  
  316. ' ===========  AI storage Area #51   stay 16 or 17 are contenders  various DD options
  317.  
  318. ' After looking at Dealer stats I like Stay 16 though test runs like Stay 17 same as dealer.
  319. ' So I am tryig Stay 16 with 3 different DD options only when Dealer is showing
  320. ' card below 10 and no Ace!
  321.  
  322. ' Dang Stay 17 Domimates! Changed all to Stay 17, much better!
  323.  
  324. FUNCTION bplusAI$ (pn) ' mod after looking at stats, Stay 16 DD1
  325.     DIM m
  326.     SELECT CASE p(pn).Tot
  327.         CASE 11 ' won't bust but could be a pretty low card to gamble on
  328.             IF LEN(p(pn).Hand) = 2 THEN
  329.                 m = INSTR(rank$, LEFT$(p(nPlayers).Hand, 1))
  330.                 IF m <> 1 AND m < 7 THEN bplusAI$ = "d" ELSE bplusAI$ = "h"
  331.             ELSE
  332.                 bplusAI$ = "h"
  333.             END IF
  334.         CASE IS < 17
  335.             bplusAI$ = "h"
  336.     END SELECT
  337.  
  338. FUNCTION bplusAI2$ (pN) 'after trying some stats DD very restricted, Stay 16
  339.     DIM m
  340.     SELECT CASE p(pN).Tot
  341.         CASE 10, 11 'double down unless dealer showing an Ace or 10's
  342.             IF LEN(p(pN).Hand) = 2 THEN
  343.                 m = INSTR(rank$, LEFT$(p(nPlayers).Hand, 1))
  344.                 IF m <> 1 AND m < 7 THEN bplusAI2$ = "d" ELSE bplusAI2$ = "h"
  345.             ELSE
  346.                 bplusAI2$ = "h"
  347.             END IF
  348.         CASE IS < 17: bplusAI2$ = "h"
  349.     END SELECT
  350.  
  351. FUNCTION bplusAI3$ (pn) ' first try modified to stay 16 plus dd on 11 only
  352.     DIM m
  353.     SELECT CASE p(pn).Tot 'try 9 instead of 12 for 3rd DD card
  354.         CASE 10, 11, 12 'double down unless dealer showing an Ace or high #'s
  355.             IF LEN(p(pn).Hand) = 2 THEN
  356.                 m = INSTR(rank$, LEFT$(p(nPlayers).Hand, 1))
  357.                 IF m <> 1 AND m < 7 THEN bplusAI3$ = "d" ELSE bplusAI3$ = "h"
  358.             ELSE
  359.                 bplusAI3$ = "h"
  360.             END IF
  361.         CASE IS < 17: bplusAI3$ = "h"
  362.     END SELECT
  363.  
  364. FUNCTION Johnno$ (pN) ' this was doing well before the Bust Rule changed but not now
  365.     IF p(pN).Tot = 10 OR p(pN).Tot = 11 AND LEN(p(pN).Hand) = 2 THEN
  366.         Johnno$ = "d"
  367.     ELSEIF p(pN).Tot = 10 OR p(pN).Tot = 11 AND LEN(p(pN).Hand) <> 2 THEN
  368.         Johnno$ = "h"
  369.     ELSEIF 12 <= p(pN).Tot AND p(pN).Tot <= 15 THEN
  370.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  371.             CASE "A", "K", "Q", "J", "X", "9": Johnno$ = "h"
  372.             CASE "7", "8": IF RND < .5 THEN Johnno$ = "h"
  373.             CASE ELSE: Johnno$ = "Hope to Bust em"
  374.         END SELECT
  375.     ELSEIF p(pN).Tot < 12 THEN
  376.         Johnno$ = "h"
  377.     ELSE
  378.         Johnno$ = "Stay"
  379.     END IF
  380.  
  381. FUNCTION Johnno2$ (pN) ' DD2 stay 13 depends 14-16
  382.     IF p(pN).Tot = 10 OR p(pN).Tot = 11 AND LEN(p(pN).Hand) = 2 THEN
  383.         Johnno2$ = "d"
  384.     ELSEIF p(pN).Tot = 10 OR p(pN).Tot = 11 AND LEN(p(pN).Hand) <> 2 THEN
  385.         Johnno2$ = "h"
  386.     ELSEIF 14 <= p(pN).Tot AND p(pN).Tot <= 16 THEN
  387.         SELECT CASE LEFT$(p(nPlayers).Hand, 1)
  388.             CASE "A", "K", "Q", "J", "X", "9": Johnno2$ = "h"
  389.             CASE "7", "8": IF RND < .5 THEN Johnno2$ = "h"
  390.             CASE ELSE: Johnno2$ = "Hope to Bust em"
  391.         END SELECT
  392.     ELSEIF p(pN).Tot < 14 THEN
  393.         Johnno2$ = "h"
  394.     ELSE
  395.         Johnno2$ = "Stay"
  396.     END IF
  397.  
  398. ' =================================  pure Stay Strategies no DD options
  399.  
  400. 'not a contender
  401. FUNCTION stay12$ (pN) 'how simple is this! never bust make dealer work for it
  402.     IF p(pN).Tot < 12 THEN stay12$ = "h"
  403.  
  404. FUNCTION stay16$ (pN) 'definite contender, no longer! try 18 instead
  405.     IF p(pN).Tot < 16 THEN stay16$ = "h"
  406. FUNCTION stay17$ (pN) 'definite contender really does well
  407.     IF p(pN).Tot < 17 THEN stay17$ = "h"
  408.  
  409. FUNCTION stay18$ (pN) 'was not a contender before changed player Bust Rule
  410.     IF p(pN).Tot < 18 THEN stay18$ = "h"
  411.  
Title: Re: Blackjack
Post by: bplus on July 15, 2020, 03:25:02 pm
I have modified the B&J Blackjack Game collaboration with Johnno with that one little rule change that casino's would never do.

"If both you and the dealer bust then it is a push."  That's all I changed, so now if you both get Blackjack or if you both bust, it is a push.

Now if you have a decent strategy of Blackjack play you can hold your own against the dealer.

Title: Re: Blackjack
Post by: johnno56 on July 15, 2020, 07:03:43 pm
Cool... But, my biggest problem, is holding on to my chips! Hey. My AI counterpart plays better than I can. Maybe it can create tutorials on how to play? lol  Nice job!
Title: Re: Blackjack
Post by: bplus on July 15, 2020, 08:09:57 pm
Hi @johnno56

Try this: always hit on less than 17, Double Down if you have 10 or 11 and Dealer has less than 8. That won't work in a casino but should be more than OK with latest version.

Always bet the same amount, never think you will get lucky or are due to. If you DD you will have to click back you regular amount bet otherwise just keep clicking your regular bet. Have a pot of coffee ready because it sometimes takes a while for the math to kick in. I hit a streak where the Dealer was getting Blackjack every other hand! 5 BJ's in 10 rounds! I thought God was trying to tell me something ;-)) then I got 2 in a row, what a night then maybe 10 rounds later 4 BJs in a row Dealer got 3 I got 1, crazy!
Title: Re: Blackjack
Post by: SierraKen on July 16, 2020, 12:46:50 pm
This is an INCREDIBLE game! Very professional. I like the sounds the most. But I do have a question, how long can it play for? When do you win or lose the whole game? Maybe I didn't see my total correctly but it had me playing even in negative numbers.
Title: Re: Blackjack
Post by: bplus on July 16, 2020, 01:03:30 pm
You can play forever Ken!

The game tracks the chips you have under the name you are playing.

You will win Jackpot Blackjack every 170 rounds or so (RND average), it is 50 X's whatever you are betting at that moment.

Title: Re: Blackjack
Post by: SierraKen on July 16, 2020, 01:46:10 pm
Edit:
Great game!
I just deleted my idea from here because you guys have worked so hard on this, I don't want to add to your frustration.
Title: Re: Blackjack
Post by: SierraKen on July 16, 2020, 01:52:05 pm
Don't get me wrong though, this is still fun to play!

Note: I just deleted my idea from the above post. I don't want to add to your frustration. Must have taken a very long time to get this far on such a good game.
Title: Re: Blackjack
Post by: SierraKen on July 16, 2020, 02:27:29 pm
I also like how you used an icon for Windows. I need to try that someday. :)
Title: Re: Blackjack
Post by: FellippeHeitor on July 16, 2020, 02:39:01 pm
You guys have done a great job with this one. Kudos to all involved!
Title: Re: Blackjack
Post by: Dav on July 16, 2020, 11:11:52 pm
Playing great! (the game, not me).  Enjoyable game.  Ya'll did a great job.

- Dav
Title: Re: Blackjack
Post by: bplus on January 12, 2021, 11:30:59 am
This is nice bplus :)

Is there any chance in making a Special Black Jack version that Tests Card counting Methods,Best Strategies,Etc. ?



How To Count Cards...
https://www.blackjackapprenticeship.com/how-to-count-cards

My interest in this started a long,long time ago probably the same time I got interested in Chess,and getting Computers to play better than Humans at various games.
And the one person that got me interested in Black Jack was Edward O. Thorp and his Beat the Dealer: A Winning Strategy for the Game of Twenty-One...

https://www.powells.com/book/beat-the-dealer-9780394703107
https://en.wikipedia.org/wiki/Edward_O._Thorp

A.R.B :)


Thanks A.R.B.

Sure it's possible to simulate Blackjack as it's played in Vegas or somewhere else just code the rules of the game you want to simulate.

Please do not mistake this game here as anything like the real thing. This game is way too generous with rules and of course the Blackjack Jackpot! Also different, 1 deck that is shuffled before each round and it is only you against the house dealer.

If are seriously considering playing in real games, it is a good idea to practice with simulations as real as possible.

When I was coding this, I skipped the Split Option because it seemed a nightmare lot of work for the one option of play.