Log In  


Cart #33667 | 2016-12-19 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

A basic blackjack/twenty-one game against the computer.

The game is turn-based. Each turn, you may either take a card ("hit") or do nothing ("stand"). The dealer will do the same. To win, your points must be below or equal to 21 and above that of the dealer. You also win in the event the dealer gets over 21 points. Face cards (KQJ) are all valued at 10. Ace is valued at either 1 or 11, whichever gives you the most advantage.

Update:

  • Fixed a bug where scoring 21 caused you to lose (misunderstanding of the rules on my side).
  • Updated the scoring algorithm for aces: the points for them are now counted after all the other cards you have, so they can be valued at 11 or 1 as is fit best, and change accordingly (i.e. if you have an ace and a 5, you have 16 points, but if you draw a 6 afterwards the ace will be down-valued to 1 leaving you with 12 points). This new algorithm represents the choices of reasonable players closer without you actually having to decide what the aces should be valued at.
1


Good start! Having created a Blackjack game myself, and doing a ton of research into all the game's rules during that time, a couple things to note:

  • If the player and dealer both have the same score, it's called a 'push'. This is basically a tie, and you get your money back.
  • You shouldn't lose on 21. 21 is the highest number, and you automatically win if you get 21 ON THE DEAL (the dealer's score doesn't matter in this case, even if the dealer also has 21). If you hit one or more times to get to 21, then it's NOT a Blackjack and is subject to the same possible 'push' if the dealer also gets 21, UNLESS the dealer has Blackjack, in which case this supersedes your non-Blackjack 21. If they player and dealer both have Blackjack (21 in the deal), the player still wins.
  • If the player or dealer goes over 21, this is called a 'bust', and the one who went over 21 loses.
  • In most Blackjack games, especially in casinos, the dealer must stand when reaching 17. In other words, if they are at or over 17, either during the deal or after hitting any number of times, they must stand and cannot hit again.
  • Aces count as 11, unless it would cause a bust, then they count as 1, so score is adjusted accordingly.
  • The dealer's first card is always shown face up, with their second card face down. Once the player stands, the dealer then flips over their second card and hits or stands from there. This is integral to player strategy, because if the dealer's first card shown is a 10-value card or ace, the player adjusts their strategy accordingly. Likewise, if the dealer's shown card is a 2 for example, you know the best they can have is 13 (if the face down card is an ace), so you strategize around that as well.
  • During the initial 2-card deal, the player has the option to 'double down' (unless they get a Blackjack). This is just doubling your bet, and causes an automatic hit. If you hit, you lose the option to double down. If you double down, you automatically hit, and lose the option to hit any further.
  • Winning pays back 2x the initial bet, and getting a Blackjack pays out 2.5x the initial bet.

BONUS:

  • If the player is dealt two cards that are the same (suit obviously doesn't matter), they get the option to 'split'. Splitting gives the player two separate Blackjack hands, which they play individually as normal hands. This gives you the opportunity of winning on one or both hands. Splitting can also happen again even after a split, if one or both of the hands is again dealt a pair. Splitting also splits your bet between the number of hands you have.
  • As mentioned before, part of Blackjack player strategy can be around the first card shown by default by the dealer. If the dealer has an ace shown, you can optionally choose 'insurance'. This is basically an extra bet on top of your normal bet, and if you take insurance, you are betting that the dealer has Blackjack. If the dealer has Blackjack, then you win this side bet. Insurance pays back double of each dollar bet on the insurance bet. If the dealer has Blackjack, you lose your initial bet (because you lost the hand), but you win the insurance bet. If the dealer does not have Blackjack, you lose the insurance bet, but the rest of the game plays out normally.

Great write-up, Scathe!

Couple other things I would mention are:

  • The initial hand for all players should be dealt at once; here, the player would have 2 cards visible and the dealer would have one visible and one hidden.
  • Dealer should wait for all players to STAND before they are allowed to HIT.

Nice start on your game, tlm. Hope you keep adding to it. If you want a good 2-button model for blackjack, you may want to check out the awesome Vegas Dream by HAL on NES. That game also has a few neat features like little random dialogue scenes that can lead to you winning or losing money outside of the games of chance.


I have fixed a couple of bugs and updated the scoring algorithm for aces, thank you for the feedback! I haven't implemented pushes/ties yet (I'm aware of the issue, but it's fairly minor so I didn't bother). I was unaware that 21 is auto-win, but seeing as only one card is dealt in my current code I don't see how 21 could happen on the deal. This is something I may have to look into. The "stand at 17 or above" is already implemented, though. I was unaware about the thing where some cards have to be shown face up... and honestly I'm not sure I can even implement that with the way my current code is structured, unfortunately (I basically draw the dealer's entire hand face down unless the game's already over, in which case it's all drawn face up). There's also no betting/winnings of any kind in this version, and I have no plans to implement that. As it is my first game, it's meant to be greatly simplified.


@tlm: Gotcha. Well, it's a good first game. Can't wait to see what you make next :)



[Please log in to post a comment]