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 Code Hunter 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 Code Hunter 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 Code Hunter 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