Skip to content

Commit c437caf

Browse files
committed
stuff
1 parent b2d0d11 commit c437caf

4 files changed

Lines changed: 153 additions & 30 deletions

File tree

doc/libreblackjack.texi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@documentencoding UTF-8
44

55
@setfilename blackjack.info
6-
@set UPDATED 2025-10-14
6+
@set UPDATED 2025-10-15
77
@set VERSION
88

99
@copying
@@ -31,7 +31,7 @@ Texts. A copy of the license is included in the section entitled
3131
@titlepage
3232
@title Libre@ Blackjack
3333
@author Jeremy Theler
34-
2025-10-14
34+
2025-10-15
3535
@page
3636
@vskip 0pt plus 1filll
3737
@insertcopying

players/00-internal/README.md

Lines changed: 133 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,146 @@
1-
2-
---
3-
title: Internal player
4-
...
5-
61
# Internal player
72

8-
> Difficulty: 00/100
9-
10-
If `blackjack` is called with the `-i` option, it uses an _internal_ player to play against itself. By default it plays basic strategy, although it can read a text file with the strategy. Run
3+
If `blackjack` is called with the `-i` option, it uses an _internal_ player to play against itself.
4+
By default it plays basic strategy, although it can read a text file with the strategy. Run
115

126
```terminal
137
blackjack -i
148
```
159

16-
and you will get the following report with the results of playing one million hands with basic strategy.
10+
and you will get the following report with the results of playing one million hands with basic strategy within a couple of seconds
1711

1812
```yaml
19-
---
20-
result: "(-0.7 ± 0.3) %"
21-
mean: -0.006799
22-
error: 0.00348707
13+
result: "(-0.4 ± 0.3)"
14+
rules: "ahc h17 das doa 3rsp 0decks"
15+
mean: -0.0043645
16+
error: 0.00348685
2317
hands: 1e+06
24-
bankroll: -6799
25-
bustsPlayer: 0.139358
26-
bustsDealer: 0.239722
27-
wins: 0.448034
28-
pushes: 0.085913
29-
losses: 0.495532
30-
...
18+
bankroll: -4364.5
19+
busts_player: 0.138314
20+
busts_dealer: 0.240593
21+
wins: 0.449235
22+
pushes: 0.085877
23+
losses: 0.494409
24+
total_money_waged: 1.13739e+06
25+
blackjacks_player: 0.047296
26+
blackjacks_dealer: 0.047421
27+
variance: 1.3509
28+
deviation: 1.16228
29+
```
30+
31+
If you want to change the strategy the player plays, then prepare a text file that looks like this
3132
3233
```
34+
# 2 3 4 5 6 7 8 9 T A
35+
h20 s s s s s s s s s s
36+
h19 s s s s s s s s s s
37+
h18 s s s s s s s s s s
38+
h17 s s s s s s s s s s
39+
h16 s s s s s h h h h h
40+
h15 s s s s s h h h h h
41+
h14 s s s s s h h h h h
42+
h13 s s s s s h h h h h
43+
h12 h h s s s h h h h h
44+
h11 d d d d d d d d h h
45+
h10 d d d d d d d d h h
46+
h9 h d d d d h h h h h
47+
h8 h h h h h h h h h h
48+
h7 h h h h h h h h h h
49+
h6 h h h h h h h h h h
50+
h5 h h h h h h h h h h
51+
h4 h h h h h h h h h h
52+
# 2 3 4 5 6 7 8 9 T A
53+
s20 s s s s s s s s s s
54+
s19 s s s s s s s s s s
55+
s18 s d d d d s s h h h
56+
s17 h d d d d h h h h h
57+
s16 h h d d d h h h h h
58+
s15 h h d d d h h h h h
59+
s14 h h h d d h h h h h
60+
s13 h h h h d h h h h h
61+
s12 h h h h d h h h h h
62+
# 2 3 4 5 6 7 8 9 T A
63+
pA y y y y y y y y y n
64+
pT n n n n n n n n n n
65+
p9 y y y y y n y y n n
66+
p8 n n n n n n n n n n
67+
p7 y y y y y y n n n n
68+
p6 y y y y y n n n n n
69+
p5 n n n n n n n n n n
70+
p4 n n n y y n n n n n
71+
p3 y y y y y y n n n n
72+
p2 y y y y y y n n n n
73+
```
74+
75+
save it as `strategy.txt` (or pick a more informative name) and run it like
76+
77+
```terminal
78+
blackjack -i --strategy=strategy.txt
79+
```
80+
81+
to see how dumb it is to never split:
82+
83+
84+
```txt
85+
# 2 3 4 5 6 7 8 9 T A
86+
h20 s s s s s s s s s s
87+
h19 s s s s s s s s s s
88+
h18 s s s s s s s s s s
89+
h17 s s s s s s s s s s
90+
h16 s s s s s h h h h h
91+
h15 s s s s s h h h h h
92+
h14 s s s s s h h h h h
93+
h13 s s s s s h h h h h
94+
h12 h h s s s h h h h h
95+
h11 d d d d d d d d h h
96+
h10 d d d d d d d d h h
97+
h9 h d d d d h h h h h
98+
h8 h h h h h h h h h h
99+
h7 h h h h h h h h h h
100+
h6 h h h h h h h h h h
101+
h5 h h h h h h h h h h
102+
h4 h h h h h h h h h h
103+
# 2 3 4 5 6 7 8 9 T A
104+
s20 s s s s s s s s s s
105+
s19 s s s s s s s s s s
106+
s18 s d d d d s s h h h
107+
s17 h d d d d h h h h h
108+
s16 h h d d d h h h h h
109+
s15 h h d d d h h h h h
110+
s14 h h h d d h h h h h
111+
s13 h h h h d h h h h h
112+
s12 h h h h d h h h h h
113+
# 2 3 4 5 6 7 8 9 T A
114+
pA n n n n n n n n n n
115+
pT n n n n n n n n n n
116+
p9 n n n n n n n n n n
117+
p8 n n n n n n n n n n
118+
p7 n n n n n n n n n n
119+
p6 n n n n n n n n n n
120+
p5 n n n n n n n n n n
121+
p4 n n n n n n n n n n
122+
p3 n n n n n n n n n n
123+
p2 n n n n n n n n n n
124+
```
125+
126+
i.e., roughly you give up 1% of your expected return:
127+
128+
```yaml
129+
result: "(-1.4 ± 0.3)"
130+
rules: "ahc h17 das doa 3rsp 0decks"
131+
mean: -0.0135275
132+
error: 0.00328319
133+
hands: 1e+06
134+
bankroll: -13527.5
135+
busts_player: 0.16438
136+
busts_dealer: 0.232731
137+
wins: 0.431502
138+
pushes: 0.086498
139+
losses: 0.482
140+
total_money_waged: 1.08152e+06
141+
blackjacks_player: 0.047659
142+
blackjacks_dealer: 0.047255
143+
variance: 1.1977
144+
deviation: 1.0944
145+
```
33146
34-
-------
35-
:::{.text-center}
36-
[Previous](../) | [Index](../) | [Next](../02-always-stand)
37-
:::

src/report.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ void Dealer::prepareReport(void) {
6060
report.push_back(reportItem(2, "bankroll", playerStats.bankroll));
6161

6262
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)));
63+
report.push_back(reportItem(3, "busts_dealer", playerStats.bustsDealer / (double) (n_hand - playerStats.bustsPlayerAllHands - playerStats.blackjacksDealer)));
6564

6665
report.push_back(reportItem(3, "wins", playerStats.wins / (double) n_hand));
6766
report.push_back(reportItem(3, "pushes", playerStats.pushes / (double) n_hand));

tests/internal.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ checkyq
1313

1414
# https://wizardofodds.com/games/blackjack/appendix/9/6dh17r4/
1515
# ref=-0.006151
16-
ref=-0.006556
16+
ref=-0.0065
1717

1818
n=1e6
1919
d=6
20-
echo "${d}decks h17 das nrsa ${n}"
20+
echo "ahc ${d}decks h17 das nrsa ${n}"
2121
$blackjack -i -p --report=ahc.yaml -n${n} --h17 --shuffle_every_hand=true --decks=${d}
2222
actual=$(yq .mean ahc.yaml)
2323
tol=$(yq .error ahc.yaml)
@@ -27,3 +27,18 @@ echo " $tol"
2727
awk -v a="$actual" -v r="$ref" -v t="$tol" 'BEGIN { exit !((a >= (r-t)) && (a <= (r+t))) }'
2828
exitifwrong $?
2929
echo "ok"
30+
31+
32+
ref=-0.0085
33+
n=1e6
34+
d=0
35+
echo "enhc ${d}decks s17 das nrsa ${n}"
36+
$blackjack -i -p --report=enhc.yaml -n${n} --rules="enhc s17" --shuffle_every_hand=true --decks=${d}
37+
actual=$(yq .mean enhc.yaml)
38+
tol=$(yq .error enhc.yaml)
39+
echo $actual
40+
echo $ref
41+
echo " $tol"
42+
awk -v a="$actual" -v r="$ref" -v t="$tol" 'BEGIN { exit !((a >= (r-t)) && (a <= (r+t))) }'
43+
exitifwrong $?
44+
echo "ok"

0 commit comments

Comments
 (0)