-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblackjack.h
109 lines (94 loc) · 2.21 KB
/
blackjack.h
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
/**
* @file blackjack.h
* @author DSN
* @brief Defines a 2-player ( \c User vs \c Dealer ) game of \c Blackjack
* @version 0.4
* @date 2023-08-19
*
*/
#ifndef BLACKJACK_H
#define BLACKJACK_H
#include "player.h"
#include "deck.h"
#include <vector>
/**
* @brief \c Players is a vector of \c Player addresses
* @details
* - Run-time polymorphism requires us to use the base class address.
*
*/
using Players = std::vector<Player*>;
/**
* @brief If a player's score reaches beyond this limit, he is busted.
*
*/
static constexpr int playerLimit{ 21 };
/**
* @brief If the dealer's score reaches beyond this limit, he has to stand.
*
*/
static constexpr int dealerLimit{ 17 };
/**
* @brief A game of Blackjack is defined by the players, a deck of cards, and a few parameters based on the rules.
*
*/
class Blackjack
{
private:
Deck m_deck{};
std::size_t m_numPlayers{};
Players m_players{};
Players active_players{}; // holds the players not busted yet
/**
* @brief A utility function to check if the game is over or not
*
* @param deck
* @return true : there are atleast 2 players who are neither busted nor are standing
* @return false : all (possibly but one) players are either busted or are standing
*/
bool gameNotOver();
/**
* @brief Get the maximum score among non-busted players
*
* @return int
*/
int getMaxScore();
/**
* @brief Compute the outcome of each player
*
*/
void computePlayerOutcomes();
public:
/**
* @brief Initialize the players playing \c Blackjack
* @details
* - Initially all players are active (naturally).
* @param players
*
*/
Blackjack(Players& players)
{
m_numPlayers = players.size();
for (auto& player : players)
{
m_players.push_back(player);
active_players.push_back(player);
}
}
/**
* @brief Reset each player
*
*/
void resetPlayers();
/**
* @brief Play a game of \c Blackjack
*
*/
void play();
/**
* @brief Display the result for each player
*
*/
void displayResult();
};
#endif