Blackjack, anyone?

Pages: 12
I was just going through that page again and I notice something missing.
Some casino's I've played in have a 5 card win.. That isn't mentioned here.

Some casino's I've played (not all) have it so that If you draw three more cards for a total of 5 in the hand, without busting, you automatically win.

I think, I'm going to make an object to contain settings, where early surrender, 5 card win, and a couple other settings can be tweaked and stored. Including how many decks we're playing with.
Winning with 5 cards is a rule of "21". A game very similar to blackjack.
BlackJack byitshelf doesn't have this rule :D
Alright, here's a stupid question: If all the players are standing (or busted or even-moneyed), can the dealer keep hitting until he's satisfied? Or must he stand when no one else is left actively playing?

Currently I assume the first option...
He can, but since there are no other players playing and there is no advantage or any possibility of winning more, there is no reason of doing something like that :P
if, by the time the dealer finally reaches his turn, all of the other players are elminated, his hand is not played. If other players are standing, and he does not beat their hands, he must play, hitting soft 17, and standing on hard 17. If the otehr players have 16 or less and the dealer has a soft 17, then yes, he does hit. His rules are he must hit soft 17 and stand on hard 17. This does give the players the chance that he may bust.
Yeah! I think I'm done. Just a quick check, if you will, on my scoring here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
inline bool operator < ( const Hand& left, const Hand& right )
  {
  return left.bust() or ((left.value() < right.value()) and !right.bust());
  }

inline bool operator == ( const Hand& left, const Hand& right )
  {
  return !left.bust() and !right.bust() and (left.value() == right.value());
  }

Status status( const Hand& player, const Hand& dealer )
  {
  if (player.bust())      return Bust;
  if (player.blackjack()) return ((&player != &dealer)
                                   and dealer.blackjack()) ? Push : BlackJack;
  if (player == dealer)   return Push;
  if (player <  dealer)   return Lose;
  return                         Winner;
  }

int main()
  {
  ...
      foreach (player, num_players)
        if (!hands[ player ].empty())
          switch (status( hands[ player ], hands[ Dealer ] ))
            {
            case Bust:      winnings[ player ] -= bets[ player ] + insurance[ player ]; break;
            case Push:      winnings[ player ] -=                  insurance[ player ]; break;
            case Lose:      winnings[ player ] -= bets[ player ] +(insurance[ player ]
                               *Money( hands[ Dealer ].blackjack() ? -2 : 1 ));         break;
            case BlackJack: winnings[ player ] += bets[ player ] *Money( 1.5 );         break;
            case Winner:    winnings[ player ] += bets[ player ] -insurance[ player ];
            }

  ...
  }

(If the player took even money his hand was clear()ed and his winnings calculated before reaching this step.)

This seems to work right when I play it, but I'd like one or two second opinions...

I'll post all the code if you all want.

[edit] Added the Hand < and == operators in case you were wondering...
Last edited on
Looks good to me. Question though is this C#? I see the "foreach" which I read is in C# and the 'and's and 'or's puzzle me.
I think that you are right on your calculations.

I have to say "WOW!!!"... I could never imagine somebody doing so many things ( classes, maps, enumerators etc ) just for a blackjack game... You really enjoy doing this don't you?? :D

One tiny question:
How did you change the && operator with "and" and the || operator with "or" ???

return left.bust() or ((left.value() < right.value()) and !right.bust());
Props to you for doing the entire game. Mine fell short at insurance and splitting (I will get to it someday).
Heh, sorry.

and and or are C++ language features called "operator synonyms"
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#C.2B.2B_operator_synonyms

Not every compiler works properly, though, unless you
#include <ciso646>
at the top of your program.

I suppose I tend to like them over their @&($#)! counterparts [pun intended] just because I came from something you can actually read: Pascal.

foreach is a wonderful Boost macro I use all the time.
http://www.boost.org/doc/libs/1_36_0/doc/html/foreach.html

In this case, though, it is just a cheap macro I defined myself to iterate over all the players except the dealer.

Let me try to compress the source code a little (it is over 800 lines and 25 Kbytes) and I'll post it here for you all to dink with.

[edit] Yes, I always enjoy dinking with silly stuff like this :-)
Last edited on
Topic archived. No new replies allowed.
Pages: 12