This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yahtzee.txt
282 lines (228 loc) · 10.7 KB
/
yahtzee.txt
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
Yahtzee is a popular dice game for two (or conceivably more) players.
Rules can be found at http://www.hasbro.com/common/instruct/Yahtzee.pdf.
Write a program that plays Yahtzee. Your program will play games
against other Yahtzee players. Your goal is to win games by scoring
more points than your opponent.
I/O:
The program should accept a stream of positions from stdin and print
a stream of actions to stdout. A position is described by 34
integers, as follows:
Integers 1-14 give the content of the current player's scorecard. The
first thirteen integers give the entries in the thirteen Yahtzee
scoring areas: ones, twos, threes, fours, fives, sixes, three of a
kind, four of a kind, full house, small straight, large straight,
Yahtzee, and chance. An entry of -1 means that the slot in question
has not yet been filled. The fourteenth entry gives the number of
bonus points scored for Yahtzees beyond the first.
Integers 15-28 give the content of the opponent's scorecard.
Integers 29-33 give the dice rolled. Each integer is a number from 1
to 6.
Integer 34 gives the roll number. A value of 1 indicates that this is
the first roll, 2 indicates the second roll, and 3 indicates the third
roll.
The program should print out an "action", which is a value from 0 to
63. If the low order bit is zero, the action indicates that the
program desires to place the dice in a given row of the Yahtzee score
card; the row selected (0-12) is in the higher order bits. So a value
of 6 (binary 110) indicates that the dice should be played in the
"fours" row (the ones row is zero, etc).
If the low order bit is one, the action indicates which dice the
program wants to "hold". Bit 1 corresponds to the first die
(corresponding to input integer 29), bit 2 to the second die, etc. If
the bit is 1, the die in question is held. If the bit is zero, it is
rerolled. As an example, a value of 45 (binary 101101) indicates that
dice 2, 3 and 5 (of 5) should be held.
The positions will be single-space-separated integers terminated with
a linefeed character (ASCII 10). Your output should be a single
integer terminated by a linefeed character.
Example:
Position:
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
(In this position, you have 8 points in the fours slot, 20 points in
the chance slot, and no bonuses. All your other slots have not yet
been filled. Your opponent has 3 points in the threes slot, 0 points
in the fives slot, and no bonuses. All of your opponents other slots
have not yet been filled. You have rolled the dice one time and they
show the numbers 1, 3, 4, 5, and 6.)
You might play:
18
In binary, this is 010010. Since the low bit is 0, this places the
dice in the row indicated by the higher-order bits: 01001. In decimal,
this is 9. The 9th slot (counting from 0) is small straight.
You might play:
5
In binary, this is 000101, Since the low bit is 1, this holds some
dice and rerolls the rest. In this example, only the three is held;
the 1, 4, 5, and 6 are rerolled.
See the bottom of this description for more examples of legal and
illegal plays.
COMPETITION:
Your program will compete against other programs one-on-one using a
double-elimination knockout format. Each match will consist of 1,000
games.
In order to be considered a contest submission, your program must beat
a Yahtzee player that just plays one random legal move each turn. This
is not hard - we built a very simple greedy player that doesn't even
know about the joker rule, and thus may sometimes attempt to play
illegal moves, thereby forfeiting the game, and it still beats the
random player by a huge margin.
PROGRAM REQUIREMENTS:
We will evaluate your program by having it play matches of 1,000 games
against other Yahtzee programs. You have 10 minutes of CPU time (on a
modern multi-core machine) to play these 1,000 games. If you run out
of time in a match, the remaining unplayed games in that match will be
considered lost. Your program should not print anything to stdout that
is not an action to be played.
Your programs will only be restarted between matches. If your program
crashes during a match the remaining unplayed games in that match will
be considered lost. Your program should not read one position and then
print out one action; it should continue to read positions and print
outputs until stdin reaches EOF.
A player attempting to play an illegal move will forfeit the current
game, though not the match.
For the remainder of this section, "GB" means 2^30 bytes, and "MB"
means 2^20 bytes.
You may not at any point exceed 2GB of memory usage. If you do, your
program will be halted and the remaining unplayed games in the match
will be considered lost.
You may send us a 5MB data file for your program to access while it
runs. You must send us the source code and the build scripts you used
to generate this data file.
If you wish, you may indicate that your program should be run in a
particular way (for instance, by passing it a certain flag) in order
to generate a much larger data file. This larger data file may be no
more than 10GB in size and must take less than 8 wall clock hours to
generate. Generating this file must use no more than 2GB of memory at
any time. Your program, when run in the normal way, may use this
larger data file to play its games.
You must submit all of your source code and build scripts. Include a
file named readme.txt explaining how to build your program. Tell us
the exact compiler and library versions you are using. For instance:
libstdc++ 6.0.9
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
All your code must be original, with the exception of standard
libraries. You may also use Boost, SciPy, or Apache Commons Proper. If
you want to use another library, ask first.
All matches will be run on a Unix-like operating system. Do not assume
anything about the case sensitivity of the file system.
F.A.Q.
Q: Is 5-of-a-kind a legal full house?
A: Not unless the joker rule is active.
Q: Is 4-of-a-kind a legal 3-of-a-kind?
A: Yes.
Q: How are the dice chosen?
A: We use a high-quality pseudorandom number generator and a random
seed.
Q: How often will the program be restarted?
A: Your program will be restarted between matches.
Q: Can my program do some precomputation before reading in the first
position?
A: Yes.
Q: Is the last number for a player's score (i.e. "the number of bonus
points scored for Yahtzees beyond the first") in increments of 1 or
100? That is, does the number represent the bonus chips, per Hasbro
rules, or the actual points?
A: The actual points.
Q: After reading in one position and printing out one action, should
my program quit?
A: No, it should continue to read positions from stdin and print
actions to stdout until stdin reaches EOF.
Q: I have one aggressive program (that may play illegal moves or
crash) and one safer one (that may win fewer games). Can I submit
both?
A: You can submit whatever you like, and we will read it, but you
should pick one that we will run.
APPENDIX - EXAMPLES OF LEGAL AND ILLEGAL PLAYS:
In the examples below, illegal plays are described by the reason for
their illegality. Legal plays are simply described as "legal".
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 2
1
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 3
1
There are no rolls left
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
1
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
-1
Only the first five dice are available for holding
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
63
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
65
Only the first five dice are available for holding
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
0
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 20 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
-2
Invalid row for placement
-------------------------------------
-1 0 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
24
legal
-------------------------------------
-1 0 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
26
Invalid row for placement
-------------------------------------
-1 0 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 1 3 4 5 6 1
22
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
22
This row is already full
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
4
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
0
Under the joker rules, if the appropriate upper section row is empty, it must be used
-------------------------------------
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
12
legal
-------------------------------------
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
2
Under the joker rules, if the appropriate upper section row is full, the lower section must be used unless the whole lower section is filled
-------------------------------------
-1 -1 6 -1 -1 -1 0 0 0 0 0 0 0 0 -1 2 3 -1 0 -1 0 -1 0 -1 0 0 0 0 3 3 3 3 3 1
2
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 50 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
22
This row is already full
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 50 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
4
legal
-------------------------------------
-1 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 50 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
0
Under the joker rules, if the appropriate upper section row is empty, it must be used
-------------------------------------
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 50 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
12
legal
-------------------------------------
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 50 -1 0 -1 -1 3 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 0 3 3 3 3 3 1
2
Under the joker rules, if the appropriate upper section row is full, the lower section must be used unless the whole lower section is filled
-------------------------------------
-1 -1 6 -1 -1 -1 0 0 0 0 0 50 0 0 -1 2 3 -1 0 -1 0 -1 0 -1 0 0 0 0 3 3 3 3 3 1
2
legal