Skip to content

Commit 3e1cfcb

Browse files
SaschaMannErikSchierboompetertseng
authored
Add exercise: state-of-tic-tac-toe (#1991)
This is based on the research exercise julia-1-a Extensions of this might be possible in the future, hence tic-tac-toe may not be ideal as a slug, so I'm going with state-of-tic-tac-toe. Co-authored-by: Erik Schierboom <[email protected]> Co-authored-by: Peter Tseng <[email protected]>
1 parent e242dd0 commit 3e1cfcb

File tree

4 files changed

+474
-0
lines changed

4 files changed

+474
-0
lines changed

bin/format-array.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
'sieve' => {
7777
'expected' => :padded,
7878
},
79+
'state-of-tic-tac-toe' => {
80+
'board' => :multi_line,
81+
},
7982
'transpose' => {
8083
'lines' => :multi_line,
8184
'expected' => :multi_line,
Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
{
2+
"exercise": "state-of-tic-tac-toe",
3+
"cases": [
4+
{
5+
"description": "Won games",
6+
"cases": [
7+
{
8+
"uuid": "fe8e9fa9-37af-4d7e-aa24-2f4b8517161a",
9+
"description": "Finished game where X won via column victory",
10+
"property": "gamestate",
11+
"input": {
12+
"board": [
13+
"XOO",
14+
"X ",
15+
"X "
16+
]
17+
},
18+
"expected": "win"
19+
},
20+
{
21+
"uuid": "96c30df5-ae23-4cf6-bf09-5ef056dddea1",
22+
"description": "Finished game where X won via column victory",
23+
"property": "gamestate",
24+
"input": {
25+
"board": [
26+
"OXO",
27+
" X ",
28+
" X "
29+
]
30+
},
31+
"expected": "win"
32+
},
33+
{
34+
"uuid": "0d7a4b0a-2afd-4a75-8389-5fb88ab05eda",
35+
"description": "Finished game where X won via column victory",
36+
"property": "gamestate",
37+
"input": {
38+
"board": [
39+
"OOX",
40+
" X",
41+
" X"
42+
]
43+
},
44+
"expected": "win"
45+
},
46+
{
47+
"uuid": "bd1007c0-ec5d-4c60-bb9f-1a4f22177d51",
48+
"description": "Finished game where O won via column victory",
49+
"property": "gamestate",
50+
"input": {
51+
"board": [
52+
"OXX",
53+
"OX ",
54+
"O "
55+
]
56+
},
57+
"expected": "win"
58+
},
59+
{
60+
"uuid": "c032f800-5735-4354-b1b9-46f14d4ee955",
61+
"description": "Finished game where O won via column victory",
62+
"property": "gamestate",
63+
"input": {
64+
"board": [
65+
"XOX",
66+
" OX",
67+
" O "
68+
]
69+
},
70+
"expected": "win"
71+
},
72+
{
73+
"uuid": "662c8902-c94a-4c4c-9d9c-e8ca513db2b4",
74+
"description": "Finished game where O won via column victory",
75+
"property": "gamestate",
76+
"input": {
77+
"board": [
78+
"XXO",
79+
" XO",
80+
" O"
81+
]
82+
},
83+
"expected": "win"
84+
},
85+
{
86+
"uuid": "2d62121f-7e3a-44a0-9032-0d73e3494941",
87+
"description": "Finished game where X won via row victory",
88+
"property": "gamestate",
89+
"input": {
90+
"board": [
91+
"XXX",
92+
"XOO",
93+
"O "
94+
]
95+
},
96+
"expected": "win"
97+
},
98+
{
99+
"uuid": "108a5e82-cc61-409f-aece-d7a18c1beceb",
100+
"description": "Finished game where X won via row victory",
101+
"property": "gamestate",
102+
"input": {
103+
"board": [
104+
"O O",
105+
"XXX",
106+
" O "
107+
]
108+
},
109+
"expected": "win"
110+
},
111+
{
112+
"uuid": "a013c583-75f8-4ab2-8d68-57688ff04574",
113+
"description": "Finished game where X won via row victory",
114+
"property": "gamestate",
115+
"input": {
116+
"board": [
117+
" OO",
118+
"O X",
119+
"XXX"
120+
]
121+
},
122+
"expected": "win"
123+
},
124+
{
125+
"uuid": "2c08e7d7-7d00-487f-9442-e7398c8f1727",
126+
"description": "Finished game where O won via row victory",
127+
"property": "gamestate",
128+
"input": {
129+
"board": [
130+
"OOO",
131+
"XXO",
132+
"XX "
133+
]
134+
},
135+
"expected": "win"
136+
},
137+
{
138+
"uuid": "bb1d6c62-3e3f-4d1a-9766-f8803c8ed70f",
139+
"description": "Finished game where O won via row victory",
140+
"property": "gamestate",
141+
"input": {
142+
"board": [
143+
"XX ",
144+
"OOO",
145+
"X "
146+
]
147+
},
148+
"expected": "win"
149+
},
150+
{
151+
"uuid": "6ef641e9-12ec-44f5-a21c-660ea93907af",
152+
"description": "Finished game where O won via row victory",
153+
"property": "gamestate",
154+
"input": {
155+
"board": [
156+
"XOX",
157+
" XX",
158+
"OOO"
159+
]
160+
},
161+
"expected": "win"
162+
},
163+
{
164+
"uuid": "ab145b7b-26a7-426c-ab71-bf418cd07f81",
165+
"description": "Finished game where X won via diagonal victory",
166+
"property": "gamestate",
167+
"input": {
168+
"board": [
169+
"XOO",
170+
" X ",
171+
" X"
172+
]
173+
},
174+
"expected": "win"
175+
},
176+
{
177+
"uuid": "7450caab-08f5-4f03-a74b-99b98c4b7a4b",
178+
"description": "Finished game where X won via diagonal victory",
179+
"property": "gamestate",
180+
"input": {
181+
"board": [
182+
"O X",
183+
"OX ",
184+
"X "
185+
]
186+
},
187+
"expected": "win"
188+
},
189+
{
190+
"uuid": "c2a652ee-2f93-48aa-a710-a70cd2edce61",
191+
"description": "Finished game where O won via diagonal victory",
192+
"property": "gamestate",
193+
"input": {
194+
"board": [
195+
"OXX",
196+
"OOX",
197+
"X O"
198+
]
199+
},
200+
"expected": "win"
201+
},
202+
{
203+
"uuid": "5b20ceea-494d-4f0c-a986-b99efc163bcf",
204+
"description": "Finished game where O won via diagonal victory",
205+
"property": "gamestate",
206+
"input": {
207+
"board": [
208+
" O",
209+
" OX",
210+
"OXX"
211+
]
212+
},
213+
"expected": "win"
214+
},
215+
{
216+
"uuid": "035a49b9-dc35-47d3-9d7c-de197161b9d4",
217+
"description": "Finished game where X won via a row and a column victory",
218+
"property": "gamestate",
219+
"input": {
220+
"board": [
221+
"XXX",
222+
"XOO",
223+
"XOO"
224+
]
225+
},
226+
"expected": "win"
227+
},
228+
{
229+
"uuid": "e5dfdeb0-d2bf-4b5a-b307-e673f69d4a53",
230+
"description": "Finished game where X won via two diagonal victories",
231+
"property": "gamestate",
232+
"input": {
233+
"board": [
234+
"XOX",
235+
"OXO",
236+
"XOX"
237+
]
238+
},
239+
"expected": "win"
240+
}
241+
]
242+
},
243+
{
244+
"description": "Drawn games",
245+
"cases": [
246+
{
247+
"uuid": "b42ed767-194c-4364-b36e-efbfb3de8788",
248+
"description": "Draw",
249+
"property": "gamestate",
250+
"input": {
251+
"board": [
252+
"XOX",
253+
"XXO",
254+
"OXO"
255+
]
256+
},
257+
"expected": "draw"
258+
},
259+
{
260+
"uuid": "227a76b2-0fef-4e16-a4bd-8f9d7e4c3b13",
261+
"description": "Draw",
262+
"property": "gamestate",
263+
"input": {
264+
"board": [
265+
"XXO",
266+
"OXX",
267+
"XOO"
268+
]
269+
},
270+
"expected": "draw"
271+
}
272+
]
273+
},
274+
{
275+
"description": "Ongoing games",
276+
"cases": [
277+
{
278+
"uuid": "4d93f15c-0c40-43d6-b966-418b040012a9",
279+
"description": "Ongoing game",
280+
"property": "gamestate",
281+
"input": {
282+
"board": [
283+
" ",
284+
"X ",
285+
" "
286+
]
287+
},
288+
"expected": "ongoing"
289+
},
290+
{
291+
"uuid": "c407ae32-4c44-4989-b124-2890cf531f19",
292+
"description": "Ongoing game",
293+
"property": "gamestate",
294+
"input": {
295+
"board": [
296+
"O ",
297+
" X ",
298+
" "
299+
]
300+
},
301+
"expected": "ongoing"
302+
},
303+
{
304+
"uuid": "199b7a8d-e2b6-4526-a85e-78b416e7a8a9",
305+
"description": "Ongoing game",
306+
"property": "gamestate",
307+
"input": {
308+
"board": [
309+
"X ",
310+
" XO",
311+
"OX "
312+
]
313+
},
314+
"expected": "ongoing"
315+
}
316+
]
317+
},
318+
{
319+
"description": "Invalid boards",
320+
"cases": [
321+
{
322+
"uuid": "1670145b-1e3d-4269-a7eb-53cd327b302e",
323+
"description": "Invalid board",
324+
"property": "gamestate",
325+
"input": {
326+
"board": [
327+
"XX ",
328+
" ",
329+
" "
330+
]
331+
},
332+
"expected": {
333+
"error": "Wrong turn order: X went twice"
334+
}
335+
},
336+
{
337+
"uuid": "47c048e8-b404-4bcf-9e51-8acbb3253f3b",
338+
"description": "Invalid board",
339+
"property": "gamestate",
340+
"input": {
341+
"board": [
342+
"OOX",
343+
" ",
344+
" "
345+
]
346+
},
347+
"expected": {
348+
"error": "Wrong turn order: O started"
349+
}
350+
},
351+
{
352+
"uuid": "b1dc8b13-46c4-47db-a96d-aa90eedc4e8d",
353+
"description": "Invalid board",
354+
"property": "gamestate",
355+
"input": {
356+
"board": [
357+
"XXX",
358+
"OOO",
359+
" "
360+
]
361+
},
362+
"expected": {
363+
"error": "Impossible board: game should have ended after X won"
364+
}
365+
}
366+
]
367+
}
368+
]
369+
}

0 commit comments

Comments
 (0)