You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/blackjack.md
+76-19Lines changed: 76 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ a dealer (he) that knows how to deal blackjack, tells the player (her) what card
51
51
52
52
# Running `blackjack`
53
53
54
-
## Invocation
54
+
## Invocation {#sec:invocation}
55
55
56
56
The `blackjack` program executable follows the POSIX standard. Its usage is:
57
57
@@ -74,16 +74,26 @@ decks = 4
74
74
no_insurance = true
75
75
```
76
76
77
+
Proper quotation migh be needed if the value contains spaces. For example,
78
+
79
+
```terminal
80
+
blackjack --internal --cards="TH JS 6D"
81
+
```
82
+
77
83
With no command-line options and no configuration file, `blackjack` starts in interactive mode and it is ready to start a blackjack game (see @sec:interactive for details).
78
84
79
-
## Results
85
+
## Results {#sec:results}
86
+
87
+
TBD
80
88
81
89
In YAML
82
90
83
91
`yq`
84
92
85
93
## Interactive game {#sec:interactive}
86
94
95
+
TBD
96
+
87
97
If `blackjack` is attached to an interactive TTY (i.e. neither the standard input nor outputs are redirected) and there is no `player` option in the configuration file, an interactive game is triggered. First thing the program will do is to ask for a bet:
88
98
89
99
```terminal
@@ -105,7 +115,7 @@ xxxxx
105
115
```
106
116
107
117
The user can quit by either typing `quit` (or `q`) or hitting Ctrl-D.
108
-
See @sec:playing for a description of all the possible commands---in both ways, from the dealer to the player and from the player to the dealer.
118
+
Write `help` or see @sec:p2d for a description of all the possible commandsthe player can give to the dealer.
109
119
110
120
111
121
# Playing blackjack {#sec:playing}
@@ -125,36 +135,81 @@ Here are the basic Blackjack rules:
125
135
6. If the dealer has a ten or an ace showing (after offering insurance with an ace showing), then he will peek at his facedown card to see if he has a blackjack. If he does, then he will turn it over immediately.
126
136
7. If the dealer does have a blackjack, then all wagers (except insurance) will lose, unless the player also has a blackjack, which will result in a push. The dealer will resolve insurance wagers at this time.
127
137
8. Play begins with the player to the dealer's left. The following are the choices available to the player:
128
-
-**Stand**: Player stands pat with his cards.
129
-
-**Hit**: Player draws another card (and more if he wishes). If this card causes the player's total points to exceed 21 (known as "breaking" or "busting") then he loses.
130
-
-**Double**: Player doubles his bet and gets one, and only one, more card.
131
-
-**Split**: If the player has a pair, or any two 10-point cards, then he may double his bet and separate his cards into two individual hands. The dealer will automatically give each card a second card. Then, the player may hit, stand, or double normally. However, when splitting aces, each ace gets only one card. Sometimes doubling after splitting is not allowed. If the player gets a ten and ace after splitting, then it counts as 21 points, not a blackjack. Usually the player may keep
132
-
re-splitting up to a total of four hands. Sometimes re-splitting aces is not allowed.
133
-
-**Surrender**: The player forfeits half his wager, keeping the other half, and does not play out his hand. This option is only available on the initial two cards, and depending on casino rules, sometimes it is not allowed at all.
138
+
139
+
Stand
140
+
141
+
: Player stands pat with his cards.
142
+
143
+
Hit
144
+
145
+
: Player draws another card (and more if he wishes). If this card causes the player's total points to exceed 21 (known as "breaking" or "busting") then he loses.
146
+
147
+
Double
148
+
149
+
: Player doubles his bet and gets one, and only one, more card.
150
+
151
+
Split
152
+
153
+
: If the player has a pair, or any two 10-point cards, then he may double his bet and separate his cards into two individual hands. The dealer will automatically give each card a second card. Then, the player may hit, stand, or double normally. However, when splitting aces, each ace gets only one card. Sometimes doubling after splitting is not allowed. If the player gets a ten and ace after splitting, then it counts as 21 points, not a blackjack. Usually the player may keep re-splitting up to a total of four hands. Sometimes re-splitting aces is not allowed.
154
+
155
+
Surrender
156
+
157
+
: The player forfeits half his wager, keeping the other half, and does not play out his hand. This option is only available on the initial two cards, and depending on casino rules, sometimes it is not allowed at all.
158
+
134
159
9. After each player has had his turn, the dealer will turn over his hole card. If the dealer has 16 or less, then he will draw another card. A special situation is when the dealer has an ace and any number of cards totaling six points (known as a "soft 17"). At some tables, the dealer will also hit a soft 17.
135
160
10. If the dealer goes over 21 points, then any player who didn't already bust will win.
136
161
11. If the dealer does not bust, then the higher point total between the player and dealer will win.
137
162
12. Winning wagers pay even money, except a winning player blackjack usually pays 3 to 2. Some casinos have been short-paying blackjacks, which is a rule strongly in the casino's favor.
138
163
164
+
To perform monte-carlo simulations, in Libre Blackjack the dealer (he) and the player (she) can “talk” through commands which are ASCII strings sent through an inter-process communcation (IPC) mechanism.
165
+
In the most basic case, an automated player reads messages from the dealer from `blackjack`’s standard output and writes her ASCII commands into the dealer’s standard input.
166
+
167
+
168
+
## Messages from the dealer to the player {#sec:d2p}
169
+
170
+
* Messages are ASCII-formatted string composed of tokens separated by spaces.
171
+
* Each message starts with a single token which is either a single English word (e.g. `bet` or `play`) or more than one English words concatenated using a low hyphen `_` (e.g. `new_hand` or `player_card`). That is to say, the first token of the message is a single-token string.
172
+
* The first token might or might not end with a question mark `?` (e.g. `card_player 4H` or `play? 18 4`):
173
+
- Messages with tokens that do not end in a question mark `?` are informative and do not need any response from the player.
174
+
- Interrogative messages strating with tokens than end in a question mark `?` need to be answered by the player. That is to say, after issuing a message as a question the dealer starts listening to the proper communication channel (see @sec:communication) for a valid command from the dealer (detailed in @sec:p2d).
175
+
* A message might have extra tokens that convey information to the player, e.g. `new_hand 15141 -4587.5`, `card_player 9S`, `play? 16 10`.
176
+
* All numerical values such as hand totals or bankrolls are given as decimal ASCII strings.
177
+
139
178
140
-
In Libre Blackjack, the dealer (he) and the player (she) can “talk” through commands which are ASCII strings sent through the standard input/output. In the most basic case, a human player reads commands from the dealer from `blackjack`’s standard output and writes her commands into the dealer’s standard input. Those commands from the dealer that require a particular action from the player end with a quotation sign such as `bet?`, `insurance?` or `play?`.
179
+
### Informative messages
141
180
142
-
All numerical values such as hand totals or bankrolls are given as decimal ASCII strings.
181
+
```include
182
+
commands-inf.md
183
+
```
184
+
185
+
#### `new_hand` $n$ $b$ {#sec:new_hand}
186
+
187
+
The dealer states that a new hand is starting. The integer $n$ states the number of the hand (starting from 1).
188
+
The decimal number $b$ states the player's bankroll before placing the bet in the starting hand.
189
+
190
+
191
+
**Examples**
192
+
193
+
```
194
+
new_hand 1 0.000000
195
+
new_hand 22 -8.000000
196
+
new_hand 24998 -7609.500000
197
+
```
143
198
144
-
##Commands from the dealer to the player
199
+
### Interrogative messages
145
200
146
-
xxxx
147
201
148
-
## Commands from the player to the dealer
202
+
203
+
## Commands from the player to the dealer {#sec:p2d}
204
+
205
+
TBD
149
206
150
207
The following commands are available for the player for playing her hand.
151
208
152
-
include(input-particular.md)
153
209
154
210
155
211
The following are general commands in the sense that they can be sent from the player to the dealer at any moment of the game.
156
212
157
-
include(input-general.md)
158
213
159
214
160
215
@@ -207,19 +262,21 @@ decks = 1 # number of decks, negative means infinite
207
262
208
263
## Reference
209
264
210
-
xxxx
265
+
TBD
211
266
212
267
213
268
# Internal players
214
269
215
-
270
+
TBD
216
271
217
272
# Examples
218
273
219
274
The directory `players` contains a few examples of automated players, which are discussed in the following sections.
0 commit comments