Skip to content

Commit 9732ac0

Browse files
committed
placeholder for card
1 parent c437caf commit 9732ac0

2 files changed

Lines changed: 38 additions & 18 deletions

File tree

src/blackjack.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,17 @@ int Blackjack::read_arranged_cards(std::istringstream iss) {
362362
int n = 0;
363363
if (number) {
364364
n = std::stoi(token);
365-
if (n <= 0 || n > 52) {
365+
if (n > 52) {
366366
// TODO: negative values are placeholders for random cards
367367
std::cerr << "error: invalid integer card " << token << std::endl;
368368
return 1;
369369
}
370370
} else {
371371
char rank = token[0];
372372
char suit = token[1];
373-
if (rank == 'A') {
373+
if (rank == 'X') { // placeholder for random
374+
n = 0;
375+
} else if (rank == 'A') {
374376
n = 1;
375377
} else if (rank == 'T') {
376378
n = 10;
@@ -404,10 +406,6 @@ int Blackjack::read_arranged_cards(std::istringstream iss) {
404406
}
405407
}
406408

407-
if (n == 0) {
408-
std::cerr << "error: invalid card " << token << std::endl;
409-
}
410-
411409
arranged_cards.push_back(n);
412410
}
413411
return 0;

src/report.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ void Dealer::updateMeanAndVariance(void) {
2222

2323

2424
void Dealer::prepareReport(void) {
25-
25+
26+
// TODO: if n_hand is one the error is NaN
27+
/*
2628
if (n_hand <= 1) {
2729
return;
2830
}
31+
*/
2932

3033
// we need to update these statistics after the last played hand
3134
updateMeanAndVariance();
3235

33-
double error = error_standard_deviations * sqrt (playerStats.variance / (double) n_hand);
36+
double total = static_cast<double>(n_hand);
37+
double error = error_standard_deviations * sqrt (playerStats.variance / total);
3438

3539
int precision = 0;
3640
if (error > 0) {
@@ -59,16 +63,34 @@ void Dealer::prepareReport(void) {
5963
report.push_back(reportItem(2, "hands", n_hand));
6064
report.push_back(reportItem(2, "bankroll", playerStats.bankroll));
6165

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 - playerStats.bustsPlayerAllHands - playerStats.blackjacksDealer)));
66+
67+
report.push_back(reportItem(3, "busts_player_n", playerStats.bustsPlayer));
68+
report.push_back(reportItem(3, "busts_dealer_n", playerStats.bustsDealer));
69+
70+
report.push_back(reportItem(3, "busts_player", playerStats.bustsPlayer / total));
71+
report.push_back(reportItem(3, "busts_player_nobj", playerStats.bustsPlayer / (total - playerStats.blackjacksPlayer)));
72+
73+
double b1 = playerStats.bustsDealer / total;
74+
double b2 = playerStats.bustsDealer / (total - playerStats.bustsPlayerAllHands);
75+
double b3 = playerStats.bustsDealer / (total - playerStats.blackjacksDealer);
76+
double b4 = playerStats.bustsDealer / (total - playerStats.bustsPlayerAllHands - playerStats.blackjacksDealer);
77+
78+
// double b2 = b1 * (1 + (double)playerStats.bustsPlayerAllHands/total);
79+
// double b3 = b2 * (1 + (double)playerStats.blackjacksDealer/total);
80+
report.push_back(reportItem(3, "busts_dealer1", b1));
81+
// report.push_back(reportItem(3, "busts_dealer2old", playerStats.bustsDealer / (double) (n_hand - playerStats.bustsPlayerAllHands)));
82+
report.push_back(reportItem(3, "busts_dealer2", b2));
83+
// report.push_back(reportItem(3, "busts_dealer3old", playerStats.bustsDealer / (double) (n_hand - playerStats.bustsPlayerAllHands - playerStats.blackjacksDealer)));
84+
report.push_back(reportItem(3, "busts_dealer3", b3));
85+
report.push_back(reportItem(3, "busts_dealer3", b4));
6486

65-
report.push_back(reportItem(3, "wins", playerStats.wins / (double) n_hand));
66-
report.push_back(reportItem(3, "pushes", playerStats.pushes / (double) n_hand));
67-
report.push_back(reportItem(3, "losses", playerStats.losses / (double) n_hand));
87+
report.push_back(reportItem(3, "wins", playerStats.wins / total));
88+
report.push_back(reportItem(3, "pushes", playerStats.pushes / total));
89+
report.push_back(reportItem(3, "losses", playerStats.losses / total));
6890

6991
report.push_back(reportItem(4, "total_money_waged", playerStats.totalMoneyWaged));
70-
report.push_back(reportItem(4, "blackjacks_player", playerStats.blackjacksPlayer / (double) n_hand));
71-
report.push_back(reportItem(4, "blackjacks_dealer", playerStats.blackjacksDealer / (double) n_hand));
92+
report.push_back(reportItem(4, "blackjacks_player", playerStats.blackjacksPlayer / total));
93+
report.push_back(reportItem(4, "blackjacks_dealer", playerStats.blackjacksDealer / total));
7294
// if (playerStats.bustsPlayerAllHands != 0) {
7395
report.push_back(reportItem(4, "blackjacks_dealer_real1", playerStats.blackjacksDealer / (double) (n_hand - playerStats.bustsPlayerAllHands)));
7496
report.push_back(reportItem(4, "blackjacks_dealer_real2", playerStats.blackjacksDealer / (double) (n_hand - playerStats.bustsPlayer)));
@@ -83,9 +105,9 @@ void Dealer::prepareReport(void) {
83105

84106
int Dealer::writeReportYAML(void) {
85107

86-
if (n_hand <= 1) {
87-
return 0;
88-
}
108+
// if (n_hand <= 1) {
109+
// return 0;
110+
// }
89111

90112

91113
std::ostream* out = &std::cerr;

0 commit comments

Comments
 (0)