-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
102 lines (73 loc) · 2.6 KB
/
Player.cpp
File metadata and controls
102 lines (73 loc) · 2.6 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
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
#include <iostream>
#include "Player.h"
#include <algorithm>
#include <map>
//We add a card in the myHand vector
void Player::AddCard(Card card) {
_myHand.emplace_back(card);
}
//We sort the cards in the _my Hand variable
void Player::sortHand() {
std::sort(_myHand.begin(), _myHand.end(), Card::compareCardValues);
}
//This display the info : PlayerName + Cards + Pattern
void Player::ToString() {
std::cout << _playerName << " player cards :" << "\n";
sortHand();
for (auto &card: _myHand) {
card.ToString();
}
std::cout << getPattern().patternToString();
std::cout << "\n";
}
//Give a name to the Object Player
Player::Player(std::string playerName) {
_playerName = playerName;
}
// Get Pattern of the 5 Cards for each player
Pattern Player::getPattern() {
Pattern result = Pattern();
std::map<Values, int> countValues;
std::map<Suits, int> countSuits;
for (Card card1: _myHand) {
int countValue = 0;
int countSuit = 0;
for (Card card2: _myHand) {
if (card1.getValue() == card2.getValue()) {
countValue++;
}
if (card1.getSuits() == card1.getSuits()) {
countSuit++;
}
}
countValues[card1.getValue()] = countValue;
countSuits[card1.getSuits()] = countSuit;
}
for (auto &countValue: countValues) {
if (countValue.second == 2) {
result.PatternValue = Pattern::Patterns::PAIR;
result.firstCard = countValue.first;
if (countValue.second > 2 && countValue.first != result.firstCard) {
result.PatternValue = Pattern::Patterns::TWO_PAIRS;
result.secondCard = countValue.first;
}
}
if (countValue.second == 3) {
result.PatternValue = Pattern::Patterns::THREE_OF_A_KIND;
result.firstCard = countValue.first;
if (countValue.second == 2 && countValue.first != result.firstCard) {
result.PatternValue = Pattern::Patterns::FULL_HOUSE;
result.secondCard = countValue.first;
}
}
if (countValue.second == 4) {
result.PatternValue = Pattern::Patterns::FOUR_OF_A_KIND;
result.firstCard = countValue.first;
if (countValue.second == 2 && countValue.first != result.firstCard) {
result.PatternValue = Pattern::Patterns::STRAIGHT;
result.secondCard = countValue.first;
}
}
return result;
}
}