-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeck.cpp
More file actions
51 lines (42 loc) · 964 Bytes
/
Deck.cpp
File metadata and controls
51 lines (42 loc) · 964 Bytes
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
#include "Deck.h"
#include <algorithm>
#include <iostream>
#include <ctime>
#define NUMBER_OF_DECKS 4
#define NUMBER_OF_RANKS 13
#define NUMBER_OF_SUITS 4
void Deck::SetUpCards() {
// Vegas Deck has 4 packs of cards
for (int i = 0; i < NUMBER_OF_DECKS; i++ ) {
// 13 Rank values,
for (int j = 1; j <= NUMBER_OF_RANKS; j++) {
// 4 Suits
for (int k = 0; k < NUMBER_OF_SUITS; k++) {
cards.push_back( Card(j, (Card::Suit)k ) );
}
}
}
srand ( unsigned ( time (NULL) ) ); // Seed random value;
ShuffleCards();
}
void Deck::ShuffleCards() {
random_shuffle ( cards.begin(), cards.end() );
}
Card Deck::TakeCard() {
Card c = cards.back();
cards.pop_back();
if (cards.empty()) {
SetUpCards();
}
return c;
}
void Deck::RePack() {
cards.erase(cards.begin(),cards.end());
SetUpCards();
}
void Deck::PrintDeck() {
for (int i = 0; i < cards.size(); i++) {
std::cout << cards[i].ToString() << std::endl;
}
std::cout << std::endl;
}