-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
127 lines (114 loc) · 3.21 KB
/
Player.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Player.h"
#include <iostream>
#include "Deck.h"
#include "Table.h"
#include "Count.h"
#include "Utils.h"
void Player::registerWin(const Hand & hand) {
VPRINT << name << " wins " << hand
<< " : +" << hand.getBet() << std::endl;
net_gains += hand.getBet();
winAdjustBet();
}
void Player::registerBlackjack(const Hand & hand) {
int payout = hand.getBet() + hand.getBet() / 2;
VPRINT << name << " blackjack " << hand
<< " : +" << payout << std::endl;
net_gains += payout;
blackjackAdjustBet();
}
void Player::registerLoss(const Hand & hand) {
VPRINT << name << " loses " << hand
<< " : -" << hand.getBet() << std::endl;
net_gains -= hand.getBet();
lossAdjustBet();
}
void Player::registerPush(const Hand & hand) {
VPRINT << name << " push " << hand << std::endl;
pushAdjustBet();
}
Player::SubhandResults Player::runHand(Hand hand, Card upcard) const {
SubhandResults subhands;
bool run = true;
while(run && !hand.isBust()) {
switch(makeDecision(hand, upcard)) {
case Decision::hit:
hand.dealCard();
break;
case Decision::stand:
run = false;
break;
case Decision::double_down:
if(hand.getCards().size() != 2) {
ERROR("Cannot double here.");
}
hand.doubleBet();
hand.dealCard();
run = false;
break;
case Decision::split:
if(!hand.isPair()) {
ERROR("Cannot split here.");
}
Hand a(hand.getBet());
Hand b(hand.getBet());
Card split_card = hand.getCards()[0];
if(hand.isSoft()) {
split_card = Card(11);
}
a.addCard(split_card);
b.addCard(split_card);
// Run first hand
a.dealCard();
if(split_card.isSoft()) {
subhands.push_back(a);
}
else {
SubhandResults a_res = runHand(a, upcard);
subhands.insert(subhands.end(), a_res.begin(), a_res.end());
}
// Run second hand
b.dealCard();
if(split_card.isSoft()) {
subhands.push_back(b);
}
else {
SubhandResults b_res = runHand(b, upcard);
subhands.insert(subhands.end(), b_res.begin(), b_res.end());
}
return subhands;
}
}
subhands.push_back(std::move(hand));
return subhands;
}
Hand runDealer(Hand hand) {
while(hand.totalValue() < 17) {
hand.dealCard();
}
return hand;
}
Decision SimplePlayer::makeDecision(const Hand & hand, Card upcard) const {
if(hand.totalValue() < 17) {
if(hand.isPair()) {
return Decision::split;
}
if(hand.getCards().size() == 2 && hand.totalValue() >= 9 && hand.totalValue() <= 11) {
return Decision::double_down;
}
return Decision::hit;
}
return Decision::stand;
}
Decision BasicPlayer::makeDecision(const Hand & hand, Card upcard) const {
return Table::basic_strategy.getDecision(hand, upcard);
}
void HiLoPlayer::countCards(const std::vector<Card> & cards) {
for(Card card : cards) {
addToCount(Count::hilo.getCountValue(card));
}
double true_count = getCount() / Deck::deck.getRemainingDecks();
VPRINT << true_count << ':' << int(true_count) << std::endl;
setBet(int(true_count));
if(getBet() < 1) setBet(1);
}