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 38 39 40 41 42 43 44 45 46 47 48
|
//----------------------------------------------------------------------------
// Card class
// A card represents four things:
// - an integer index in 0..52
// - a suit in 0..13
// - a face in Spades..Hearts
// - an integer BlackJack game value
// A suit/value of zero is the Joker (unused in this program)
//
const char* SuitNames[] =
{
"Joker", "Ace", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"
};
const int SuitValue[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
enum Suit
{
Joker = 0,
Ace = 1,
Jack = 11,
Queen = 12,
King = 13,
SoftAce = 11
};
const char* FaceNames[] = { "Spades", "Diamonds", "Clubs", "Hearts" };
enum Face { Spades, Diamonds, Clubs, Hearts };
//............................................................................
struct Card
{
Face face;
Suit suit;
Card( int index = Joker ):
face( (Face)( (index != Joker) ? ((index -1) /13) : Spades ) ),
suit( (Suit)( (index != Joker) ? (((index -1) %13) +1) : Joker ) )
{ }
Card( int suit, int face ):
face( (Face)face ),
suit( (Suit)suit )
{ }
inline int value() const { return SuitValue[ suit ]; }
inline operator int() const { return SuitValue[ suit ]; }
inline bool ace() const { return suit == Ace; }
inline int index() const { return (face *13) +suit; }
};
|