This is what I would do. First I would simplify your deck and declare it as a vector. Using a vector gives you a lot of options.
Let's say your using one deck. You could declare your deck as such...
std::vector<Card> deck
Now to actually construct it, I would use id's 0 thru 51. Before I'd add cards to the deck, let me explain why I use card IDs. Let's assume each suit corresponds to consecutive IDs. Since there's 13 cards of each suit, lets say card IDs 0-12 are hearts, 13-25 are clubs, 26-38 are diamonds, 39-51 are spades. Cool. Now about about we give each card a rank, like A, 5, 10, J, Q, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
Rank Card
0 A
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 J
11 Q
12 K
|
By structuring our ID's in this manner, you'll kill a bunch of birds with one stone. Let me simplify your card constructor and add some members to your class card.
1 2 3 4 5 6 7 8 9 10
|
class card{
int rank;
enum suits {HEART, CLUB, DIAMOND, SPADE};
};
card::card(int _id):id(_id){
rank = id % 13;
suit = id / 13;
}
|
If we were to call
card(23)
what card would that be? Well, 23 % 13 is 10, so now we know we have a J of some suit. Then to find out the suit, we would use the divisor operator. So 23 / 13 is 1, which corresponds to CLUB. Therefore id(23) corresponds to a J of clubs. How about
card(39)
? Well, 39 % 13 is 0, and 39 / 13 is 3, so we'd have an A of spades. Make sense?
Now to actually construct our deck, which use a basic for loop.
1 2 3 4 5
|
for(int i = 0; i < 52 * numDecks; i++){
deck.push_back(card(i)); // a sorted deck (Hearts->Clubs->Diamonds->Spades)
}
std::random_shuffle(deck.begin(), deck.end()); //shuffle them
|
If you haven't already, I would create a class Player because each player is going to need their own hand of cards and other members. Then when you want start the game, you can implement a member function of class Player like such...
1 2 3 4
|
void Player::takeCard(std::vector<Card> &deck){
//take the card off the top of the deck (splice or pop_back)
//place that card onto the players hand
}
|
Now every time a player needs to take a card from the top of the deck, they'll actually remove it from the deck since you're passing it by reference. Within that function there are multiple ways to remove the card, but I'm just giving you a basic idea. At the beginning of the game, each player could call Player::takeCard() 6 times, to grab 6 cards.
1 2 3 4 5 6 7
|
const int handStartSize = 6;
for(auto &player : players){ //assumes a you have a container of Players
for(int i = 0; i < handStartSize; i++){
player.takeCard(deck);
}
}
|
I don't know if players have to replace their cards back into the deck, but if so, you could create another member function of class Player like replaceCard(). This way you could add cards back to the deck and remove them from the players hand.