Skip to content

Commit b2d0d11

Browse files
committed
report
1 parent c2878d5 commit b2d0d11

4 files changed

Lines changed: 51 additions & 42 deletions

File tree

src/blackjack.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,11 @@ void Blackjack::deal(void) {
570570
return;
571571
}
572572
} else {
573-
// in ENHC, if the player has 21..
573+
// in ENHC, if the player has 21...
574574
if (player->value_player == -21) {
575575
if (card[dealer_up_card].value == 10 || card[dealer_up_card].value == 11) {
576576
// and the dealer shows an ace or a face she has to draw
577577
// (actually she should ask for insurance)
578-
// but if the dealer does show an ace or a face the she has to hit
579578
dealer_hole_card = draw(&hand);
580579
info(lbj::Info::CardDealerRevealsHole, dealer_hole_card);
581580
}
@@ -701,22 +700,25 @@ void Blackjack::deal(void) {
701700
}
702701
} else {
703702
// assume the player busted in all the hands
704-
bool bustedAllHands = true;
703+
bool player_busted_all_hands = true;
705704
for (auto playerHand = playerStats.hands.begin(); playerHand != playerStats.hands.end(); playerHand++) {
706705
// if he (she) did not bust, set to false
707706
if (playerHand->busted() == false) {
708-
bustedAllHands = false;
707+
player_busted_all_hands = false;
709708
break;
710709
}
711710
}
712711

713-
if (bustedAllHands) {
712+
if (player_busted_all_hands) {
714713
if (enhc == false) {
715714
info(lbj::Info::CardDealerRevealsHole, dealer_hole_card);
716715
#ifdef BJDEBUG
717716
std::cout << "hole " << card[dealer_hole_card].utf8() << std::endl;
718717
#endif
719718
}
719+
// } else {
720+
playerStats.bustsPlayerAllHands++;
721+
// }
720722

721723
player->actionRequired = lbj::PlayerActionRequired::None;
722724
nextAction = lbj::DealerAction::StartNewHand;

src/dealer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class Dealer {
310310
unsigned int blackjacksDealer = 0;
311311

312312
unsigned int bustsPlayer = 0;
313+
unsigned int bustsPlayerAllHands = 0; // this is incremented only if all hands were busted (only for enhc)
313314
unsigned int bustsDealer = 0;
314315

315316
unsigned int wins = 0;

src/players/basic.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Basic::Basic(Configuration &conf) : Player(conf) {
3333

3434
for (int value = 0; value < 21; value++) {
3535
for (int upcard = 0; upcard < 12; upcard++) {
36-
hard[value][upcard] = lbj::PlayerActionTaken::None;
37-
soft[value][upcard] = lbj::PlayerActionTaken::None;
38-
pair[value][upcard] = lbj::PlayerActionTaken::None;
36+
hard[value][upcard] = PlayerActionTaken::None;
37+
soft[value][upcard] = PlayerActionTaken::None;
38+
pair[value][upcard] = PlayerActionTaken::None;
3939
}
4040
}
4141

@@ -89,33 +89,33 @@ Basic::Basic(Configuration &conf) : Player(conf) {
8989
if (default_hard[value] != "") {
9090
switch (default_hard[value][upcard]) {
9191
case 'h':
92-
hard[value][upcard] = lbj::PlayerActionTaken::Hit;
92+
hard[value][upcard] = PlayerActionTaken::Hit;
9393
break;
9494
case 's':
95-
hard[value][upcard] = lbj::PlayerActionTaken::Stand;
95+
hard[value][upcard] = PlayerActionTaken::Stand;
9696
break;
9797
case 'd':
98-
hard[value][upcard] = lbj::PlayerActionTaken::Double;
98+
hard[value][upcard] = PlayerActionTaken::Double;
9999
break;
100100
}
101101
}
102102

103103
if (default_soft[value] != "") {
104104
switch (default_soft[value][upcard]) {
105105
case 'h':
106-
soft[value][upcard] = lbj::PlayerActionTaken::Hit;
106+
soft[value][upcard] = PlayerActionTaken::Hit;
107107
break;
108108
case 's':
109-
soft[value][upcard] = lbj::PlayerActionTaken::Stand;
109+
soft[value][upcard] = PlayerActionTaken::Stand;
110110
break;
111111
case 'd':
112-
soft[value][upcard] = lbj::PlayerActionTaken::Double;
112+
soft[value][upcard] = PlayerActionTaken::Double;
113113
break;
114114
}
115115
}
116116

117117
if (default_pair[value] != "" && default_pair[value][upcard] == 'y') {
118-
pair[value][upcard] = lbj::PlayerActionTaken::Split;
118+
pair[value][upcard] = PlayerActionTaken::Split;
119119
}
120120
}
121121
}
@@ -143,7 +143,7 @@ Basic::Basic(Configuration &conf) : Player(conf) {
143143
stream >> token;
144144

145145
int value = 0;
146-
lbj::PlayerActionTaken (*strategy)[21][12] = nullptr;
146+
PlayerActionTaken (*strategy)[21][12] = nullptr;
147147
switch (token[0]) {
148148
case 'h':
149149
case 'H':
@@ -181,26 +181,26 @@ Basic::Basic(Configuration &conf) : Player(conf) {
181181
// TODO: check error
182182
stream >> token;
183183
if (token == "h" || token == "H") {
184-
(*strategy)[value][upcard] = lbj::PlayerActionTaken::Hit;
184+
(*strategy)[value][upcard] = PlayerActionTaken::Hit;
185185
} else if (token == "s" || token == "S") {
186-
(*strategy)[value][upcard] = lbj::PlayerActionTaken::Stand;
186+
(*strategy)[value][upcard] = PlayerActionTaken::Stand;
187187
} else if (token == "d" || token == "D") {
188-
(*strategy)[value][upcard] = lbj::PlayerActionTaken::Double;
188+
(*strategy)[value][upcard] = PlayerActionTaken::Double;
189189
} else if (token == "y" || token == "Y") {
190190
// the pair data is different as it is not written as a function of the value
191191
// but of the value of the individual cards,
192192
// i.e. p8 means split a pair of eights and not a hand with two fours
193193
// to avoid clashing a pair of aces with a pair of sixes, we treat the former differently
194194
if (value != 11) {
195-
(*strategy)[2*value][upcard] = lbj::PlayerActionTaken::Split;
195+
(*strategy)[2*value][upcard] = PlayerActionTaken::Split;
196196
} else {
197-
(*strategy)[11][upcard] = lbj::PlayerActionTaken::Split;
197+
(*strategy)[11][upcard] = PlayerActionTaken::Split;
198198
}
199199
} else if (token == "n" || token == "N") {
200200
if (value != 11) {
201-
(*strategy)[2*value][upcard] = lbj::PlayerActionTaken::None;
201+
(*strategy)[2*value][upcard] = PlayerActionTaken::None;
202202
} else {
203-
(*strategy)[11][upcard] = lbj::PlayerActionTaken::None;
203+
(*strategy)[11][upcard] = PlayerActionTaken::None;
204204
}
205205
} else {
206206
std::cerr << "error: unknown command '" << token << "' in " << strategy_file_path << ":" << line_num << std::endl;
@@ -219,16 +219,16 @@ int Basic::play() {
219219
std::size_t upcard;
220220

221221
switch (actionRequired) {
222-
case lbj::PlayerActionRequired::Bet:
222+
case PlayerActionRequired::Bet:
223223
current_bet = 1;
224-
actionTaken = lbj::PlayerActionTaken::Bet;
224+
actionTaken = PlayerActionTaken::Bet;
225225
break;
226226

227-
case lbj::PlayerActionRequired::Insurance:
228-
actionTaken = lbj::PlayerActionTaken::DontInsure;
227+
case PlayerActionRequired::Insurance:
228+
actionTaken = PlayerActionTaken::DontInsure;
229229
break;
230230

231-
case lbj::PlayerActionRequired::Play:
231+
case PlayerActionRequired::Play:
232232

233233
#ifdef BJDEBUG
234234
std::cout << "player " << value_player << " dealer " << value_dealer << std::endl;
@@ -238,27 +238,27 @@ int Basic::play() {
238238

239239
// first, we see if we can and shold split
240240
if (can_split &&
241-
((value_player == -12 && pair[11][upcard] == lbj::PlayerActionTaken::Split) ||
242-
pair[value][upcard] == lbj::PlayerActionTaken::Split)) {
243-
actionTaken = lbj::PlayerActionTaken::Split;
241+
((value_player == -12 && pair[11][upcard] == PlayerActionTaken::Split) ||
242+
pair[value][upcard] == PlayerActionTaken::Split)) {
243+
actionTaken = PlayerActionTaken::Split;
244244

245245
} else {
246246

247247
actionTaken = (value_player < 0) ? soft[value][upcard] : hard[value][upcard];
248248

249249
if (can_double == false) {
250-
if (actionTaken == lbj::PlayerActionTaken::Double) {
251-
actionTaken = lbj::PlayerActionTaken::Hit;
250+
if (actionTaken == PlayerActionTaken::Double) {
251+
actionTaken = PlayerActionTaken::Hit;
252252
}
253253
}
254254
}
255255

256256
#ifdef BJDEBUG
257-
if (actionTaken == lbj::PlayerActionTaken::Hit) {
257+
if (actionTaken == PlayerActionTaken::Hit) {
258258
std::cout << "hit" << std::endl;
259-
} else if (actionTaken == lbj::PlayerActionTaken::Stand) {
259+
} else if (actionTaken == PlayerActionTaken::Stand) {
260260
std::cout << "stand" << std::endl;
261-
} else if (actionTaken == lbj::PlayerActionTaken::Split) {
261+
} else if (actionTaken == PlayerActionTaken::Split) {
262262
std::cout << "split" << std::endl;
263263
} else {
264264
std::cout << "none" << std::endl;
@@ -268,7 +268,7 @@ int Basic::play() {
268268

269269
break;
270270

271-
case lbj::PlayerActionRequired::None:
271+
case PlayerActionRequired::None:
272272
break;
273273

274274
}

src/report.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,21 @@ void Dealer::prepareReport(void) {
5959
report.push_back(reportItem(2, "hands", n_hand));
6060
report.push_back(reportItem(2, "bankroll", playerStats.bankroll));
6161

62-
report.push_back(reportItem(3, "busts_player", playerStats.bustsPlayer / (double) n_hand));
63-
report.push_back(reportItem(3, "busts_dealer", playerStats.bustsDealer / (double) n_hand));
62+
report.push_back(reportItem(3, "busts_player", playerStats.bustsPlayer / (double) n_hand));
63+
report.push_back(reportItem(3, "busts_dealer", playerStats.bustsDealer / (double) n_hand));
64+
report.push_back(reportItem(3, "busts_dealer_real", playerStats.bustsDealer / (double) (n_hand - playerStats.bustsPlayerAllHands)));
65+
6466
report.push_back(reportItem(3, "wins", playerStats.wins / (double) n_hand));
6567
report.push_back(reportItem(3, "pushes", playerStats.pushes / (double) n_hand));
6668
report.push_back(reportItem(3, "losses", playerStats.losses / (double) n_hand));
6769

68-
report.push_back(reportItem(4, "total_money_waged", playerStats.totalMoneyWaged));
69-
report.push_back(reportItem(4, "blackjacks_player", playerStats.blackjacksPlayer / (double) n_hand));
70-
report.push_back(reportItem(4, "blackjacks_dealer", playerStats.blackjacksDealer / (double) n_hand));
70+
report.push_back(reportItem(4, "total_money_waged", playerStats.totalMoneyWaged));
71+
report.push_back(reportItem(4, "blackjacks_player", playerStats.blackjacksPlayer / (double) n_hand));
72+
report.push_back(reportItem(4, "blackjacks_dealer", playerStats.blackjacksDealer / (double) n_hand));
73+
// if (playerStats.bustsPlayerAllHands != 0) {
74+
report.push_back(reportItem(4, "blackjacks_dealer_real1", playerStats.blackjacksDealer / (double) (n_hand - playerStats.bustsPlayerAllHands)));
75+
report.push_back(reportItem(4, "blackjacks_dealer_real2", playerStats.blackjacksDealer / (double) (n_hand - playerStats.bustsPlayer)));
76+
// }
7177

7278
report.push_back(reportItem(5, "variance", playerStats.variance));
7379
report.push_back(reportItem(5, "deviation", sqrt(playerStats.variance)));

0 commit comments

Comments
 (0)