Skip to content

Commit fc39259

Browse files
committed
maximum re-splits
1 parent 7a5cd62 commit fc39259

9 files changed

Lines changed: 118 additions & 163 deletions

File tree

players/00-internal/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
blackjack -i
1+
blackjack -ip
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
h17 = true
1+
rules = s17
22
hands = 1e5
33
rng_seed = 12345

players/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
for dir in */; do
2+
if [ -d "${dir}" ]; then
3+
echo "$dir"
4+
cd "${dir}"
5+
./run.sh
6+
cd ..
7+
fi
8+
done

src/blackjack.cpp

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,28 @@ Blackjack::Blackjack(Configuration &conf) : Dealer(conf), rng(dev_random()), fif
6868
///conf+maximum_bet+example maximum_bet = 20
6969
conf.set(&max_bet, {"maximum_bet", "max_bet", "maxbet"});
7070

71-
///conf+rules+usage `rules = [ ahc | enhc ] [ h17 | s17 ] [ das | ndas ] [ doa | da9 ]`
72-
///conf+rules+details Defines the rules of the game.
71+
///conf+rules+usage `rules = [ ahc | enhc ] [ h17 | s17 ] [ das | ndas ] [ doa | do9 ]`
72+
///conf+rules+details Defines the rules of the game.
73+
///conf+rules+details @
74+
///conf+rules+details | Rule | Yes | No |
75+
///conf+rules+details |:-----------------------------------------|:-------:|:-------:|
76+
///conf+rules+details | Dealer peeks for blackjack | `ahc` | `enhc` |
77+
///conf+rules+details | Dealer has to hit a soft 17 | `h17` | `s17` |
78+
///conf+rules+details | Player can double after splitting | `das` | `ndas` |
79+
///conf+rules+details | Player can double on any first two cards | `doa` | `do9` |
80+
///conf+rules+details @
81+
///conf+rules+details * When playing `ahc` (default), the dealer has a hole card.
82+
///conf+rules+details If the upcard is an ace, he checks for possible blackjack before
83+
///conf+rules+details allowing for the player to split nor double down.
84+
///conf+rules+details When playing `enhc` the dealer does not draw a hole card and
85+
///conf+rules+details check for blackjack after the player has played.
86+
///conf+rules+details * The `do9` rules means that the player can only double if the
87+
///conf+rules+details first two cards sum up nine, ter or eleven.
88+
///conf+rules+details @
7389
///conf+rules+default Empty, meaning `ahc`, `h17`, `das`, `doa`.
74-
///conf+rules+example maximum_bet = 0
75-
///conf+rules+example maximum_bet = 1
76-
///conf+rules+example maximum_bet = 20
77-
// rules are base, particular options take precedence
90+
///conf+rules+example rules = ahc h17 das doa
91+
///conf+rules+example rules = enhc s17 ndas
92+
///conf+rules+example rules = s17 do9
7893
if (conf.exists("rules")) {
7994
std::istringstream iss(conf.getString("rules"));
8095
std::string token;
@@ -94,7 +109,7 @@ Blackjack::Blackjack(Configuration &conf) : Dealer(conf), rng(dev_random()), fif
94109
das = false;
95110
} else if (token == "doa" || token == "DOA") {
96111
doa = true;
97-
} else if (token == "da9" || token == "DA9") {
112+
} else if (token == "do9" || token == "DO9") {
98113
doa = false;
99114
/*
100115
} else if (token == "rsa" || token == "RSA") {
@@ -110,11 +125,8 @@ Blackjack::Blackjack(Configuration &conf) : Dealer(conf), rng(dev_random()), fif
110125
conf.markUsed("rules");
111126
}
112127

113-
conf.set(&h17, {"h17", "hit_soft_17"});
114-
conf.set(&das, {"das", "double_after_split"});
115-
conf.set(&doa, {"doa", "double_on_any"});
116128
// conf.set(&rsa, {"rsa", "resplit_aces"});
117-
conf.set(&enhc, {"enhc", "european_no_hole_card"});
129+
118130
conf.set(&blackjack_pays, {"blackjack_pays"});
119131

120132
conf.set(&playerStats.bankroll, {"bankroll", "initial_bankroll"});
@@ -185,6 +197,29 @@ Blackjack::~Blackjack() {
185197
return;
186198
}
187199

200+
Player::Player(Configuration &conf) {
201+
///conf+flat_bet+usage `flat_bet = ` $b$
202+
///conf+flat_bet+details Tells both the dealer and the player that the betting scheme is flat or not.
203+
///conf+flat_bet+details The dealer will not ask for bets and the internal player, if asked, always says `1`.
204+
///conf+flat_bet+details The value can be either `false` or `true` or `0` or `1`.
205+
///conf+flat_bet+default $false$
206+
///conf+flat_bet+example flat_bet = false
207+
///conf+flat_bet+example flat_bet = true
208+
///conf+flat_bet+example flat_bet = 1
209+
conf.set(&flat_bet, {"flat_bet", "flatbet"});
210+
211+
///conf+no_insurance+usage `no_insurance = ` $b$
212+
///conf+no_insurance+details If $b$ is `true`, the dealer will not ask for insurance and assume
213+
///conf+no_insurance+details the player will never take it when the dealer shows an ace.
214+
///conf+no_insurance+details The value can be either `false` or `true` or `0` or `1`.
215+
///conf+no_insurance+default $false$
216+
///conf+no_insurance+example no_insurance = false
217+
///conf+no_insurance+example no_insurance = true
218+
///conf+no_insurance+example no_insurance = 1
219+
conf.set(&no_insurance, {"no_insurance", "never_insurance", "never_insure", "dont_insure"});
220+
conf.set(&always_insure, {"always_insure"});
221+
}
222+
188223
int Blackjack::read_arranged_cards(std::istringstream iss) {
189224
std::string token;
190225
while(iss >> token) {
@@ -260,7 +295,7 @@ void Blackjack::can_double_split(void) {
260295
player->can_double &= (value == 9 || value == 10 || value == 11);
261296
}
262297

263-
player->can_split = n_cards == 2 && (card[*(playerStats.currentHand->cards.begin())].value == card[*(++playerStats.currentHand->cards.begin())].value);
298+
player->can_split = (n_cards == 2) && (card[*(playerStats.currentHand->cards.begin())].value == card[*(++playerStats.currentHand->cards.begin())].value) && (playerStats.splits < resplits);
264299
return;
265300
}
266301

@@ -840,10 +875,8 @@ int Blackjack::process(void) {
840875
secondCard = *(++playerStats.currentHand->cards.begin());
841876

842877
// up to three splits (i.e. four hands)
843-
// TODO: choose through conf how many max splits are available
844878
// TODO: check bankroll to see if player can split
845-
// if (playerStats.splits < 3 && playerStats.currentHand->cards.size() == 2 && card[firstCard].value == card[secondCard].value) {
846-
if (playerStats.currentHand->cards.size() == 2 && card[firstCard].value == card[secondCard].value) {
879+
if (playerStats.splits < resplits && playerStats.currentHand->cards.size() == 2 && card[firstCard].value == card[secondCard].value) {
847880

848881
// take player's money
849882
playerStats.bankroll -= playerStats.currentHand->bet;
@@ -1050,8 +1083,9 @@ std::string Blackjack::rules(void) {
10501083
return ((enhc) ? "enhc" : "ahc") + std::string(" ") +
10511084
((h17) ? "h17" : "s17") + std::string(" ") +
10521085
((das) ? "das" : "ndas") + std::string(" ") +
1053-
((doa) ? "doa" : "da9") + std::string(" ") +
1086+
((doa) ? "doa" : "do9") + std::string(" ") +
10541087
// ((rsa) ? "rsa" : "nrsa") + std::string(" ") +
1088+
std::to_string(resplits) + "rsp " +
10551089
std::to_string(n_decks) + "decks" ;
10561090
}
10571091
}

src/blackjack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Blackjack : public Dealer {
7070
size_t n_arranged_cards = 0; // just to prevent calling size() each time we draw a card
7171
size_t i_arranged_cards = 0;
7272

73+
unsigned int resplits = 3;
7374
unsigned int max_bet = 0;
7475
unsigned int number_of_burnt_cards = 0;
7576

src/dealer.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ class PlayerHand : public Hand {
193193

194194
class Player {
195195
public:
196-
Player(Configuration &conf) {
197-
// conf.set(&flat_bet, {"flat_bet", "flatbet"});
198-
// conf.set(&no_insurance, {"never_insurance", "never_insure", "no_insurance", "dont_insure"});
199-
// conf.set(&always_insure, {"always_insure"});
200-
};
196+
Player(Configuration &conf);
201197
virtual ~Player() = default;
202198
// delete copy and move constructors
203199
Player(Player&) = delete;

0 commit comments

Comments
 (0)