1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# A Party of Dice
A game simulation I wrote to help me better understand Go concurrency
concepts.
Based loosely on the `makeThumbnails6` example in Chapter 8 (page 238)
of *The Go Programming Language* (Addison-Wesley, 2016).
# Usage
The following invocation runs the simulation with two players, each of
which plays with a six-sided die:
`go run . -n 2 -sides 6`
Since 2 and 6 are the default values, in this case the following is
equivalent:
`go run .`
Of course, `go run . -help` will print a detailed listing of available
command-line arguments.
# The Scene: What Is Being Simulated?
Several people agree to convene to play a game of dice. Beforehand,
they decided on the number of sides a given die should have. Once they
do that, each player brings with them a die of that many sides (for
example, 6, 12, etc.; even a coin can count as a die in this case.)
One of the players (picked arbitrarily) rolls their die once. The
number that it shows becomes the winning number. Each player is then
tasked with rolling their die until they hit that number.
For example, three players get together and decide to use an ordinary
six-sided die each. The die is rolled, resulting in a 4. The players
then each go off into their corners and roll their die until they hit
a 4, upon which they can declare victory.
The player to hit the number in the smallest number of turns, wins. In
the case of a tie, the first one to roll the winning number wins. For
example, if player 1 hits the number in three turns, then player 2
hits the number in two turns, then player 3 also in two turns, player
2 wins.
|