-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.cpp
More file actions
49 lines (43 loc) · 1.32 KB
/
deck.cpp
File metadata and controls
49 lines (43 loc) · 1.32 KB
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
/* File. deck.cpp
* Course: CS215-012
* Project: Project 2
* Purpose: Implement the functions for the deck class.
* Author: Brennen Adams
*/
#include "deck.h"
#include <algorithm>
#include <random>
#include <vector>
using namespace std;
// Create a standard 52-card deck arranged in the default starting order.
// For each suit (in dictionary order: Clubs, Diamonds, Hearts, Spades),
// cards are added in descending order: Ace, King, Queen, Jack, then 10 to 2.
void Deck::createDeck()
// Cards are grouped by suit and then number (All Aces, All Kings, All Queens, etc.)
// The final Order will be: A, A, A, A, K, K, K, K, Q, Q, Q, Q, J, J, J, J, 10, 10, 10, 10, 9, 9, 9, 9, etc.
{
for (int point = 2; point <= 14; point++) {
for (char suit : {'C', 'D', 'H', 'S'}) {
{
deck.push_back(Card(suit, point)); // Add a card to the deck
}
}
}
}
// Shuffle the deck using a random number generator
void Deck::shuffleDeck()
{
random_device rd;
mt19937 g(rd());
shuffle(deck.begin(), deck.end(), g);
}
// Deals a card from the front of the deck, removing it
Card Deck::deal_a_card()
{
if (deck.empty()) {
throw out_of_range("No more cards in the deck");
}
Card dealtCard = deck.back(); // Get the last card
deck.pop_back(); // Remove the last card from the deck
return dealtCard; // Return the dealt card
}