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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <iostream>
//#include <array>
#include <list>
enum class Suit {Hearts, Diamonds, Clubs, Spades};
enum class Rank {Two = 2, Three, Four, Five, Six, Seven, Eight , Nine, Ten,
Jack, Queen, King, Ace
};
struct Card {
Card(const Rank R, const Suit S )
:
rank(R),
suit(S)
{}
Rank rank;
Suit suit;
};
void InitDeck(std::list<Card>& Deck, std::size_t NumCards);
void PrintDeck(std::list<Card>& Deck);
int main() {
//Card AceClubs(Rank::Ace, Suit::Clubs);
const std::size_t NumCards =52;
std::list<Card> Deck;
//Deck.push_back(AceClubs);
InitDeck(Deck, NumCards);
return 0;
}
void InitDeck(std::list<Card>& Deck, std::size_t NumCards) {
for (std::size_t C = 0 ; C < NumCards ; ++C) {
const std::size_t CardsPerSuit = 13;
Suit ThisCardSuit;
// Choose the suit
switch (C / 13) { // integer division does what we want here
case 0:
ThisCardSuit = Suit::Hearts;
break;
case 1:
ThisCardSuit = Suit::Diamonds;
break;
case 2:
ThisCardSuit = Suit::Clubs;
break;
case 3:
ThisCardSuit = Suit::Spades;
break;
default:
std::cout << "Error in Suit Selection\n";
break;
}
Rank ThisCardRank;
// Choose the Rank
switch (C % CardsPerSuit) {
case 0:
ThisCardRank = Rank::Two;
break;
case 1:
ThisCardRank = Rank::Three;
break;
case 2:
ThisCardRank = Rank::Four;
break;
case 3:
ThisCardRank = Rank::Five;
break;
case 4:
ThisCardRank = Rank::Six;
break;
case 5:
ThisCardRank = Rank::Seven;
break;
case 6:
ThisCardRank = Rank::Eight;
break;
case 7:
ThisCardRank = Rank::Nine;
break;
case 8:
ThisCardRank = Rank::Ten;
break;
case 9:
ThisCardRank = Rank::Jack;
break;
case 10:
ThisCardRank = Rank::Queen;
break;
case 11:
ThisCardRank = Rank::King;
break;
case 12:
ThisCardRank = Rank::Ace;
default:
break;
}
Deck.emplace_back(Card(ThisCardRank, ThisCardSuit));
}
}
void PrintDeck(std::list<Card>& Deck) {
}
|