kaggle-environments 1.16.10__py2.py3-none-any.whl → 1.16.11__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaggle-environments might be problematic. Click here for more details.

Files changed (49) hide show
  1. kaggle_environments/__init__.py +1 -1
  2. kaggle_environments/envs/chess/chess.js +4000 -0
  3. kaggle_environments/envs/chess/chess.py +4000 -17
  4. kaggle_environments/envs/lux_ai_s3/lux_ai_s3.py +32 -4
  5. kaggle_environments/envs/lux_ai_s3/luxai_s3/env.py +2 -2
  6. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/METADATA +1 -1
  7. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/RECORD +11 -49
  8. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/WHEEL +1 -1
  9. kaggle_environments/envs/connectx/connectx.ipynb +0 -3183
  10. kaggle_environments/envs/football/football.ipynb +0 -75
  11. kaggle_environments/envs/halite/halite.ipynb +0 -44736
  12. kaggle_environments/envs/kore_fleets/kore_fleets.ipynb +0 -112
  13. kaggle_environments/envs/kore_fleets/starter_bots/java/Bot.java +0 -54
  14. kaggle_environments/envs/kore_fleets/starter_bots/java/README.md +0 -26
  15. kaggle_environments/envs/kore_fleets/starter_bots/java/jars/hamcrest-core-1.3.jar +0 -0
  16. kaggle_environments/envs/kore_fleets/starter_bots/java/jars/junit-4.13.2.jar +0 -0
  17. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Board.java +0 -518
  18. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Cell.java +0 -61
  19. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Configuration.java +0 -24
  20. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Direction.java +0 -166
  21. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Fleet.java +0 -72
  22. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/KoreJson.java +0 -97
  23. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Observation.java +0 -72
  24. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Pair.java +0 -13
  25. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Player.java +0 -68
  26. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Point.java +0 -65
  27. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Shipyard.java +0 -70
  28. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/ShipyardAction.java +0 -59
  29. kaggle_environments/envs/kore_fleets/starter_bots/java/test/BoardTest.java +0 -567
  30. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ConfigurationTest.java +0 -25
  31. kaggle_environments/envs/kore_fleets/starter_bots/java/test/KoreJsonTest.java +0 -62
  32. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ObservationTest.java +0 -46
  33. kaggle_environments/envs/kore_fleets/starter_bots/java/test/PointTest.java +0 -21
  34. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ShipyardTest.java +0 -22
  35. kaggle_environments/envs/kore_fleets/starter_bots/ts/README.md +0 -55
  36. kaggle_environments/envs/lux_ai_2021/README.md +0 -3
  37. kaggle_environments/envs/lux_ai_2021/dimensions/754.js.LICENSE.txt +0 -296
  38. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/simple.tar.gz +0 -0
  39. kaggle_environments/envs/lux_ai_2021/testing.md +0 -23
  40. kaggle_environments/envs/lux_ai_2021/todo.md.og +0 -18
  41. kaggle_environments/envs/lux_ai_s2/.gitignore +0 -1
  42. kaggle_environments/envs/lux_ai_s2/README.md +0 -21
  43. kaggle_environments/envs/lux_ai_s2/luxai_s2/.DS_Store +0 -0
  44. kaggle_environments/envs/lux_ai_s2/luxai_s2/map_generator/.DS_Store +0 -0
  45. kaggle_environments/envs/lux_ai_s3/README.md +0 -21
  46. kaggle_environments/envs/tictactoe/tictactoe.ipynb +0 -1393
  47. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/LICENSE +0 -0
  48. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/entry_points.txt +0 -0
  49. {kaggle_environments-1.16.10.dist-info → kaggle_environments-1.16.11.dist-info}/top_level.txt +0 -0
@@ -1,1393 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Tic Tac Toe - Kaggle Environment"
8
- ]
9
- },
10
- {
11
- "cell_type": "code",
12
- "execution_count": 10,
13
- "metadata": {},
14
- "outputs": [
15
- {
16
- "name": "stdout",
17
- "output_type": "stream",
18
- "text": [
19
- "tictactoe 1.0.0\n",
20
- "Default Agents: random reaction\n"
21
- ]
22
- }
23
- ],
24
- "source": [
25
- "from kaggle_environments import make\n",
26
- "env = make(\"tictactoe\")\n",
27
- "print(env.name, env.version)\n",
28
- "print(\"Default Agents: \", *env.agents)"
29
- ]
30
- },
31
- {
32
- "cell_type": "markdown",
33
- "metadata": {},
34
- "source": [
35
- "## TLDR;"
36
- ]
37
- },
38
- {
39
- "cell_type": "code",
40
- "execution_count": 2,
41
- "metadata": {},
42
- "outputs": [
43
- {
44
- "data": {
45
- "text/html": [
46
- "<iframe srcdoc=\"<!--\n",
47
- " Copyright 2020 Kaggle Inc\n",
48
- "\n",
49
- " Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n",
50
- " you may not use this file except in compliance with the License.\n",
51
- " You may obtain a copy of the License at\n",
52
- "\n",
53
- " http://www.apache.org/licenses/LICENSE-2.0\n",
54
- "\n",
55
- " Unless required by applicable law or agreed to in writing, software\n",
56
- " distributed under the License is distributed on an &quot;AS IS&quot; BASIS,\n",
57
- " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
58
- " See the License for the specific language governing permissions and\n",
59
- " limitations under the License.\n",
60
- "-->\n",
61
- "<!DOCTYPE html>\n",
62
- "<html lang=&quot;en&quot;>\n",
63
- " <head>\n",
64
- " <title>Kaggle Simulation Player</title>\n",
65
- " <meta name=&quot;viewport&quot; content=&quot;width=device-width,initial-scale=1&quot; />\n",
66
- " <link\n",
67
- " rel=&quot;stylesheet&quot;\n",
68
- " href=&quot;https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css&quot;\n",
69
- " crossorigin=&quot;anonymous&quot;\n",
70
- " />\n",
71
- " <style type=&quot;text/css&quot;>\n",
72
- " html,\n",
73
- " body {\n",
74
- " height: 100%;\n",
75
- " font-family: sans-serif;\n",
76
- " }\n",
77
- " canvas {\n",
78
- " position: absolute;\n",
79
- " top: 0;\n",
80
- " left: 0;\n",
81
- " width: 100%;\n",
82
- " height: 100%;\n",
83
- " /* image-rendering: -moz-crisp-edges;\n",
84
- " image-rendering: -webkit-crisp-edges;\n",
85
- " image-rendering: pixelated;\n",
86
- " image-rendering: crisp-edges; */\n",
87
- " }\n",
88
- " </style>\n",
89
- " <script src=&quot;https://unpkg.com/preact@10.0.1/dist/preact.umd.js&quot;></script>\n",
90
- " <script src=&quot;https://unpkg.com/preact@10.0.1/hooks/dist/hooks.umd.js&quot;></script>\n",
91
- " <script src=&quot;https://unpkg.com/htm@2.2.1/dist/htm.umd.js&quot;></script>\n",
92
- " <script>\n",
93
- " // Polyfill for Styled Components\n",
94
- " window.React = {\n",
95
- " ...preact,\n",
96
- " createElement: preact.h,\n",
97
- " PropTypes: { func: {} },\n",
98
- " };\n",
99
- " </script>\n",
100
- " <script src=&quot;https://unpkg.com/styled-components@3.5.0-0/dist/styled-components.min.js&quot;></script>\n",
101
- " <link rel=&quot;canonical&quot; href=&quot;someurl&quot; />\n",
102
- " </head>\n",
103
- " <body>\n",
104
- " <script>\n",
105
- " \n",
106
- "window.kaggle = {\n",
107
- " &quot;debug&quot;: true,\n",
108
- " &quot;autoplay&quot;: true,\n",
109
- " &quot;step&quot;: 0,\n",
110
- " &quot;controls&quot;: true,\n",
111
- " &quot;environment&quot;: {\n",
112
- " &quot;name&quot;: &quot;tictactoe&quot;,\n",
113
- " &quot;title&quot;: &quot;Tic Tac Toe&quot;,\n",
114
- " &quot;description&quot;: &quot;Classic Tic Tac Toe&quot;,\n",
115
- " &quot;version&quot;: &quot;1.0.0&quot;,\n",
116
- " &quot;configuration&quot;: {\n",
117
- " &quot;steps&quot;: 10,\n",
118
- " &quot;timeout&quot;: 2\n",
119
- " },\n",
120
- " &quot;specification&quot;: {\n",
121
- " &quot;action&quot;: {\n",
122
- " &quot;description&quot;: &quot;Position to place a mark on the board.&quot;,\n",
123
- " &quot;type&quot;: &quot;integer&quot;,\n",
124
- " &quot;minimum&quot;: 0,\n",
125
- " &quot;maximum&quot;: 8,\n",
126
- " &quot;default&quot;: 0\n",
127
- " },\n",
128
- " &quot;agents&quot;: [\n",
129
- " 2\n",
130
- " ],\n",
131
- " &quot;configuration&quot;: {\n",
132
- " &quot;steps&quot;: {\n",
133
- " &quot;description&quot;: &quot;Maximum number of steps the environment can run.&quot;,\n",
134
- " &quot;type&quot;: &quot;integer&quot;,\n",
135
- " &quot;minimum&quot;: 10,\n",
136
- " &quot;default&quot;: 10\n",
137
- " },\n",
138
- " &quot;timeout&quot;: {\n",
139
- " &quot;description&quot;: &quot;Seconds an agent can run before timing out.&quot;,\n",
140
- " &quot;type&quot;: &quot;integer&quot;,\n",
141
- " &quot;minimum&quot;: 1,\n",
142
- " &quot;default&quot;: 2\n",
143
- " }\n",
144
- " },\n",
145
- " &quot;info&quot;: {},\n",
146
- " &quot;observation&quot;: {\n",
147
- " &quot;board&quot;: {\n",
148
- " &quot;description&quot;: &quot;Serialized 3x3 grid. 0 = Empty, 1 = X, 2 = O&quot;,\n",
149
- " &quot;type&quot;: &quot;array&quot;,\n",
150
- " &quot;default&quot;: [\n",
151
- " 0,\n",
152
- " 0,\n",
153
- " 0,\n",
154
- " 0,\n",
155
- " 0,\n",
156
- " 0,\n",
157
- " 0,\n",
158
- " 0,\n",
159
- " 0\n",
160
- " ],\n",
161
- " &quot;minItems&quot;: 9,\n",
162
- " &quot;maxItems&quot;: 9\n",
163
- " },\n",
164
- " &quot;mark&quot;: {\n",
165
- " &quot;description&quot;: &quot;Mark for the agent to use&quot;,\n",
166
- " &quot;enum&quot;: [\n",
167
- " 1,\n",
168
- " 2\n",
169
- " ]\n",
170
- " }\n",
171
- " },\n",
172
- " &quot;reward&quot;: {\n",
173
- " &quot;description&quot;: &quot;0 = Lost, 0.5 = Draw, 1 = Won&quot;,\n",
174
- " &quot;enum&quot;: [\n",
175
- " 0,\n",
176
- " 0.5,\n",
177
- " 1\n",
178
- " ],\n",
179
- " &quot;default&quot;: 0.5,\n",
180
- " &quot;type&quot;: [\n",
181
- " &quot;number&quot;,\n",
182
- " &quot;null&quot;\n",
183
- " ]\n",
184
- " },\n",
185
- " &quot;reset&quot;: {\n",
186
- " &quot;status&quot;: [\n",
187
- " &quot;ACTIVE&quot;,\n",
188
- " &quot;INACTIVE&quot;\n",
189
- " ],\n",
190
- " &quot;observation&quot;: [\n",
191
- " {\n",
192
- " &quot;mark&quot;: 1\n",
193
- " },\n",
194
- " {\n",
195
- " &quot;mark&quot;: 2\n",
196
- " }\n",
197
- " ],\n",
198
- " &quot;reward&quot;: 0.5\n",
199
- " }\n",
200
- " },\n",
201
- " &quot;steps&quot;: [\n",
202
- " [\n",
203
- " {\n",
204
- " &quot;action&quot;: 0,\n",
205
- " &quot;reward&quot;: 0.5,\n",
206
- " &quot;info&quot;: {},\n",
207
- " &quot;observation&quot;: {\n",
208
- " &quot;board&quot;: [\n",
209
- " 0,\n",
210
- " 0,\n",
211
- " 0,\n",
212
- " 0,\n",
213
- " 0,\n",
214
- " 0,\n",
215
- " 0,\n",
216
- " 0,\n",
217
- " 0\n",
218
- " ],\n",
219
- " &quot;mark&quot;: 1\n",
220
- " },\n",
221
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
222
- " },\n",
223
- " {\n",
224
- " &quot;action&quot;: 0,\n",
225
- " &quot;reward&quot;: 0.5,\n",
226
- " &quot;info&quot;: {},\n",
227
- " &quot;observation&quot;: {\n",
228
- " &quot;board&quot;: [\n",
229
- " 0,\n",
230
- " 0,\n",
231
- " 0,\n",
232
- " 0,\n",
233
- " 0,\n",
234
- " 0,\n",
235
- " 0,\n",
236
- " 0,\n",
237
- " 0\n",
238
- " ],\n",
239
- " &quot;mark&quot;: 2\n",
240
- " },\n",
241
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
242
- " }\n",
243
- " ],\n",
244
- " [\n",
245
- " {\n",
246
- " &quot;action&quot;: 4,\n",
247
- " &quot;reward&quot;: 0.5,\n",
248
- " &quot;info&quot;: {},\n",
249
- " &quot;observation&quot;: {\n",
250
- " &quot;board&quot;: [\n",
251
- " 0,\n",
252
- " 0,\n",
253
- " 0,\n",
254
- " 0,\n",
255
- " 1,\n",
256
- " 0,\n",
257
- " 0,\n",
258
- " 0,\n",
259
- " 0\n",
260
- " ],\n",
261
- " &quot;mark&quot;: 1\n",
262
- " },\n",
263
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
264
- " },\n",
265
- " {\n",
266
- " &quot;action&quot;: 0,\n",
267
- " &quot;reward&quot;: 0.5,\n",
268
- " &quot;info&quot;: {},\n",
269
- " &quot;observation&quot;: {\n",
270
- " &quot;board&quot;: [\n",
271
- " 0,\n",
272
- " 0,\n",
273
- " 0,\n",
274
- " 0,\n",
275
- " 1,\n",
276
- " 0,\n",
277
- " 0,\n",
278
- " 0,\n",
279
- " 0\n",
280
- " ],\n",
281
- " &quot;mark&quot;: 2\n",
282
- " },\n",
283
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
284
- " }\n",
285
- " ],\n",
286
- " [\n",
287
- " {\n",
288
- " &quot;action&quot;: 0,\n",
289
- " &quot;reward&quot;: 0.5,\n",
290
- " &quot;info&quot;: {},\n",
291
- " &quot;observation&quot;: {\n",
292
- " &quot;board&quot;: [\n",
293
- " 0,\n",
294
- " 0,\n",
295
- " 0,\n",
296
- " 0,\n",
297
- " 1,\n",
298
- " 0,\n",
299
- " 0,\n",
300
- " 2,\n",
301
- " 0\n",
302
- " ],\n",
303
- " &quot;mark&quot;: 1\n",
304
- " },\n",
305
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
306
- " },\n",
307
- " {\n",
308
- " &quot;action&quot;: 7,\n",
309
- " &quot;reward&quot;: 0.5,\n",
310
- " &quot;info&quot;: {},\n",
311
- " &quot;observation&quot;: {\n",
312
- " &quot;board&quot;: [\n",
313
- " 0,\n",
314
- " 0,\n",
315
- " 0,\n",
316
- " 0,\n",
317
- " 1,\n",
318
- " 0,\n",
319
- " 0,\n",
320
- " 2,\n",
321
- " 0\n",
322
- " ],\n",
323
- " &quot;mark&quot;: 2\n",
324
- " },\n",
325
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
326
- " }\n",
327
- " ],\n",
328
- " [\n",
329
- " {\n",
330
- " &quot;action&quot;: 0,\n",
331
- " &quot;reward&quot;: 0.5,\n",
332
- " &quot;info&quot;: {},\n",
333
- " &quot;observation&quot;: {\n",
334
- " &quot;board&quot;: [\n",
335
- " 1,\n",
336
- " 0,\n",
337
- " 0,\n",
338
- " 0,\n",
339
- " 1,\n",
340
- " 0,\n",
341
- " 0,\n",
342
- " 2,\n",
343
- " 0\n",
344
- " ],\n",
345
- " &quot;mark&quot;: 1\n",
346
- " },\n",
347
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
348
- " },\n",
349
- " {\n",
350
- " &quot;action&quot;: 0,\n",
351
- " &quot;reward&quot;: 0.5,\n",
352
- " &quot;info&quot;: {},\n",
353
- " &quot;observation&quot;: {\n",
354
- " &quot;board&quot;: [\n",
355
- " 1,\n",
356
- " 0,\n",
357
- " 0,\n",
358
- " 0,\n",
359
- " 1,\n",
360
- " 0,\n",
361
- " 0,\n",
362
- " 2,\n",
363
- " 0\n",
364
- " ],\n",
365
- " &quot;mark&quot;: 2\n",
366
- " },\n",
367
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
368
- " }\n",
369
- " ],\n",
370
- " [\n",
371
- " {\n",
372
- " &quot;action&quot;: 0,\n",
373
- " &quot;reward&quot;: 0.5,\n",
374
- " &quot;info&quot;: {},\n",
375
- " &quot;observation&quot;: {\n",
376
- " &quot;board&quot;: [\n",
377
- " 1,\n",
378
- " 0,\n",
379
- " 0,\n",
380
- " 2,\n",
381
- " 1,\n",
382
- " 0,\n",
383
- " 0,\n",
384
- " 2,\n",
385
- " 0\n",
386
- " ],\n",
387
- " &quot;mark&quot;: 1\n",
388
- " },\n",
389
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
390
- " },\n",
391
- " {\n",
392
- " &quot;action&quot;: 3,\n",
393
- " &quot;reward&quot;: 0.5,\n",
394
- " &quot;info&quot;: {},\n",
395
- " &quot;observation&quot;: {\n",
396
- " &quot;board&quot;: [\n",
397
- " 1,\n",
398
- " 0,\n",
399
- " 0,\n",
400
- " 2,\n",
401
- " 1,\n",
402
- " 0,\n",
403
- " 0,\n",
404
- " 2,\n",
405
- " 0\n",
406
- " ],\n",
407
- " &quot;mark&quot;: 2\n",
408
- " },\n",
409
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
410
- " }\n",
411
- " ],\n",
412
- " [\n",
413
- " {\n",
414
- " &quot;action&quot;: 2,\n",
415
- " &quot;reward&quot;: 0.5,\n",
416
- " &quot;info&quot;: {},\n",
417
- " &quot;observation&quot;: {\n",
418
- " &quot;board&quot;: [\n",
419
- " 1,\n",
420
- " 0,\n",
421
- " 1,\n",
422
- " 2,\n",
423
- " 1,\n",
424
- " 0,\n",
425
- " 0,\n",
426
- " 2,\n",
427
- " 0\n",
428
- " ],\n",
429
- " &quot;mark&quot;: 1\n",
430
- " },\n",
431
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
432
- " },\n",
433
- " {\n",
434
- " &quot;action&quot;: 0,\n",
435
- " &quot;reward&quot;: 0.5,\n",
436
- " &quot;info&quot;: {},\n",
437
- " &quot;observation&quot;: {\n",
438
- " &quot;board&quot;: [\n",
439
- " 1,\n",
440
- " 0,\n",
441
- " 1,\n",
442
- " 2,\n",
443
- " 1,\n",
444
- " 0,\n",
445
- " 0,\n",
446
- " 2,\n",
447
- " 0\n",
448
- " ],\n",
449
- " &quot;mark&quot;: 2\n",
450
- " },\n",
451
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
452
- " }\n",
453
- " ],\n",
454
- " [\n",
455
- " {\n",
456
- " &quot;action&quot;: 0,\n",
457
- " &quot;reward&quot;: 0.5,\n",
458
- " &quot;info&quot;: {},\n",
459
- " &quot;observation&quot;: {\n",
460
- " &quot;board&quot;: [\n",
461
- " 1,\n",
462
- " 0,\n",
463
- " 1,\n",
464
- " 2,\n",
465
- " 1,\n",
466
- " 0,\n",
467
- " 0,\n",
468
- " 2,\n",
469
- " 2\n",
470
- " ],\n",
471
- " &quot;mark&quot;: 1\n",
472
- " },\n",
473
- " &quot;status&quot;: &quot;ACTIVE&quot;\n",
474
- " },\n",
475
- " {\n",
476
- " &quot;action&quot;: 8,\n",
477
- " &quot;reward&quot;: 0.5,\n",
478
- " &quot;info&quot;: {},\n",
479
- " &quot;observation&quot;: {\n",
480
- " &quot;board&quot;: [\n",
481
- " 1,\n",
482
- " 0,\n",
483
- " 1,\n",
484
- " 2,\n",
485
- " 1,\n",
486
- " 0,\n",
487
- " 0,\n",
488
- " 2,\n",
489
- " 2\n",
490
- " ],\n",
491
- " &quot;mark&quot;: 2\n",
492
- " },\n",
493
- " &quot;status&quot;: &quot;INACTIVE&quot;\n",
494
- " }\n",
495
- " ],\n",
496
- " [\n",
497
- " {\n",
498
- " &quot;action&quot;: 6,\n",
499
- " &quot;reward&quot;: 1,\n",
500
- " &quot;info&quot;: {},\n",
501
- " &quot;observation&quot;: {\n",
502
- " &quot;board&quot;: [\n",
503
- " 1,\n",
504
- " 0,\n",
505
- " 1,\n",
506
- " 2,\n",
507
- " 1,\n",
508
- " 0,\n",
509
- " 1,\n",
510
- " 2,\n",
511
- " 2\n",
512
- " ],\n",
513
- " &quot;mark&quot;: 1\n",
514
- " },\n",
515
- " &quot;status&quot;: &quot;DONE&quot;\n",
516
- " },\n",
517
- " {\n",
518
- " &quot;action&quot;: 0,\n",
519
- " &quot;reward&quot;: 0,\n",
520
- " &quot;info&quot;: {},\n",
521
- " &quot;observation&quot;: {\n",
522
- " &quot;board&quot;: [\n",
523
- " 1,\n",
524
- " 0,\n",
525
- " 1,\n",
526
- " 2,\n",
527
- " 1,\n",
528
- " 0,\n",
529
- " 1,\n",
530
- " 2,\n",
531
- " 2\n",
532
- " ],\n",
533
- " &quot;mark&quot;: 2\n",
534
- " },\n",
535
- " &quot;status&quot;: &quot;DONE&quot;\n",
536
- " }\n",
537
- " ]\n",
538
- " ],\n",
539
- " &quot;rewards&quot;: [\n",
540
- " 1,\n",
541
- " 0\n",
542
- " ],\n",
543
- " &quot;statuses&quot;: [\n",
544
- " &quot;DONE&quot;,\n",
545
- " &quot;DONE&quot;\n",
546
- " ],\n",
547
- " &quot;schema_version&quot;: 1\n",
548
- " },\n",
549
- " &quot;mode&quot;: &quot;ipython&quot;\n",
550
- "};\n",
551
- "\n",
552
- "\n",
553
- "window.kaggle.renderer = // Copyright 2020 Kaggle Inc\n",
554
- "//\n",
555
- "// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);\n",
556
- "// you may not use this file except in compliance with the License.\n",
557
- "// You may obtain a copy of the License at\n",
558
- "//\n",
559
- "// http://www.apache.org/licenses/LICENSE-2.0\n",
560
- "//\n",
561
- "// Unless required by applicable law or agreed to in writing, software\n",
562
- "// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,\n",
563
- "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
564
- "// See the License for the specific language governing permissions and\n",
565
- "// limitations under the License.\n",
566
- "\n",
567
- "function renderer({\n",
568
- " parent,\n",
569
- " step,\n",
570
- " frame,\n",
571
- " environment,\n",
572
- " width = 400,\n",
573
- " height = 400,\n",
574
- "}) {\n",
575
- " // Canvas Setup.\n",
576
- " let canvas = parent.querySelector(&quot;canvas&quot;);\n",
577
- " if (!canvas) {\n",
578
- " canvas = document.createElement(&quot;canvas&quot;);\n",
579
- " parent.appendChild(canvas);\n",
580
- "\n",
581
- " canvas.addEventListener(&quot;click&quot;, () => {\n",
582
- " console.log(&quot;canvas click&quot;);\n",
583
- " });\n",
584
- " }\n",
585
- "\n",
586
- " // Common Dimensions.\n",
587
- " const canvasSize = Math.min(height, width);\n",
588
- " const unit = 8;\n",
589
- " const offset = canvasSize > 400 ? canvasSize * 0.1 : unit / 2;\n",
590
- " const cellSize = (canvasSize - offset * 2) / 3;\n",
591
- "\n",
592
- " // Canvas setup and reset.\n",
593
- " const c = canvas.getContext(&quot;2d&quot;);\n",
594
- " canvas.width = canvasSize;\n",
595
- " canvas.height = canvasSize;\n",
596
- " c.clearRect(0, 0, canvas.width, canvas.height);\n",
597
- "\n",
598
- " const drawStyle = ({\n",
599
- " lineWidth = 1,\n",
600
- " lineCap,\n",
601
- " strokeStyle = &quot;#FFF&quot;,\n",
602
- " shadow,\n",
603
- " }) => {\n",
604
- " c.lineWidth = lineWidth;\n",
605
- " c.strokeStyle = strokeStyle;\n",
606
- " if (lineCap) c.lineCap = lineCap;\n",
607
- " if (shadow) {\n",
608
- " c.shadowOffsetX = shadow.offsetX || 0;\n",
609
- " c.shadowOffsetY = shadow.offsetY || 0;\n",
610
- " c.shadowColor = shadow.color || strokeStyle;\n",
611
- " c.shadowBlur = shadow.blur || 0;\n",
612
- " }\n",
613
- " };\n",
614
- "\n",
615
- " const drawLine = ({ x1, y1, x2, y2, style }) => {\n",
616
- " c.beginPath();\n",
617
- " drawStyle(style || {});\n",
618
- " c.moveTo((x1 || 0) + offset, (y1 || 0) + offset);\n",
619
- " c.lineTo((x2 || x1) + offset, (y2 || y1) + offset);\n",
620
- " c.stroke();\n",
621
- " };\n",
622
- "\n",
623
- " const drawArc = ({ x, y, radius, sAngle, eAngle, style }) => {\n",
624
- " drawStyle(style || {});\n",
625
- " c.beginPath();\n",
626
- " c.arc(x, y, radius, sAngle, eAngle);\n",
627
- " c.stroke();\n",
628
- " };\n",
629
- "\n",
630
- " // Draw the Grid.\n",
631
- " const gridFrame = step === 0 ? frame : 1;\n",
632
- " const drawGridLine = ({\n",
633
- " x1s = 0,\n",
634
- " y1s = 0,\n",
635
- " x2s,\n",
636
- " y2s,\n",
637
- " x1o = 0,\n",
638
- " x2o = 0,\n",
639
- " y1o = 0,\n",
640
- " y2o = 0,\n",
641
- " }) =>\n",
642
- " drawLine({\n",
643
- " x1: x1s * cellSize + x1o * unit,\n",
644
- " x2: (x2s || x1s) * cellSize + x2o * unit,\n",
645
- " y1: y1s * cellSize + y1o * unit,\n",
646
- " y2: (y2s || y1s) * cellSize + y2o * unit,\n",
647
- " style: { strokeStyle: &quot;#046BBF&quot; },\n",
648
- " });\n",
649
- "\n",
650
- " // Vertical.\n",
651
- " drawGridLine({ x1s: 1, y1s: 0, y2s: gridFrame, y2o: -1 });\n",
652
- " drawGridLine({ x1s: 2, y1s: 0, y2s: gridFrame, y2o: -1 });\n",
653
- " drawGridLine({ x1s: 1, y1s: 1, y2s: 1 + gridFrame, y1o: 1, y2o: -1 });\n",
654
- " drawGridLine({ x1s: 2, y1s: 1, y2s: 1 + gridFrame, y1o: 1, y2o: -1 });\n",
655
- " drawGridLine({ x1s: 1, y1s: 2, y2s: 2 + gridFrame, y1o: 1 });\n",
656
- " drawGridLine({ x1s: 2, y1s: 2, y2s: 2 + gridFrame, y1o: 1 });\n",
657
- "\n",
658
- " // Horizontal.\n",
659
- " drawGridLine({ x1s: 0, y1s: 1, x2s: gridFrame, x2o: -1 });\n",
660
- " drawGridLine({ x1s: 1, y1s: 1, x2s: 1 + gridFrame, x1o: 1, x2o: -1 });\n",
661
- " drawGridLine({ x1s: 2, y1s: 1, x2s: 2 + gridFrame, x1o: 1 });\n",
662
- " drawGridLine({ x1s: 0, y1s: 2, x2s: gridFrame, x2o: -1 });\n",
663
- " drawGridLine({ x1s: 1, y1s: 2, x2s: 1 + gridFrame, x1o: 1, x2o: -1 });\n",
664
- " drawGridLine({ x1s: 2, y1s: 2, x2s: 2 + gridFrame, x1o: 1 });\n",
665
- "\n",
666
- " // Draw the Pieces.\n",
667
- " const drawX = (cell, cellFrame) => {\n",
668
- " const part = cellSize / 4;\n",
669
- " const gap = Math.min(Math.sqrt((unit * unit) / 2), canvasSize / 50);\n",
670
- " const row = Math.floor(cell / 3);\n",
671
- " const col = cell % 3;\n",
672
- "\n",
673
- " const drawXLine = ({ x1, y1, x2, y2 }) =>\n",
674
- " drawLine({\n",
675
- " x1: col * cellSize + x1,\n",
676
- " y1: row * cellSize + y1,\n",
677
- " x2: col * cellSize + x2,\n",
678
- " y2: row * cellSize + y2,\n",
679
- " style: {\n",
680
- " strokeStyle: &quot;#00FFFF&quot;,\n",
681
- " lineWidth: 2,\n",
682
- " lineCap: &quot;round&quot;,\n",
683
- " shadow: { blur: 8 },\n",
684
- " },\n",
685
- " });\n",
686
- "\n",
687
- " drawXLine({\n",
688
- " x1: part,\n",
689
- " y1: part,\n",
690
- " x2: part + part * 2 * cellFrame,\n",
691
- " y2: part + part * 2 * cellFrame,\n",
692
- " });\n",
693
- " if (Math.round(cellFrame) === 1) {\n",
694
- " drawXLine({\n",
695
- " x1: part,\n",
696
- " y1: part * 3,\n",
697
- " x2: part * 2 - gap,\n",
698
- " y2: part * 2 + gap,\n",
699
- " });\n",
700
- " drawXLine({\n",
701
- " x1: part * 2 + gap,\n",
702
- " y1: part * 2 - gap,\n",
703
- " x2: part * 3,\n",
704
- " y2: part,\n",
705
- " });\n",
706
- " }\n",
707
- " };\n",
708
- " const drawO = (cell, cellFrame) => {\n",
709
- " const row = Math.floor(cell / 3);\n",
710
- " const col = cell % 3;\n",
711
- " const radius = cellSize / 4 + 1; // +1 is for optical illusion.\n",
712
- " const gap =\n",
713
- " (Math.acos((2 * (radius ^ 2) - (unit ^ 2)) / (2 * radius * radius)) /\n",
714
- " 180) *\n",
715
- " Math.PI *\n",
716
- " unit;\n",
717
- " const x = cellSize * col + cellSize / 2 + offset;\n",
718
- " const y = cellSize * row + cellSize / 2 + offset;\n",
719
- "\n",
720
- " const drawOArc = (sAngle, eAngle) =>\n",
721
- " drawArc({\n",
722
- " x,\n",
723
- " y,\n",
724
- " radius,\n",
725
- " sAngle,\n",
726
- " eAngle,\n",
727
- " style: {\n",
728
- " lineWidth: 2,\n",
729
- " strokeStyle: &quot;#FFF&quot;,\n",
730
- " shadow: { blur: 8 },\n",
731
- " },\n",
732
- " });\n",
733
- "\n",
734
- " drawOArc(\n",
735
- " -Math.PI / 2 + gap,\n",
736
- " -Math.PI / 2 + gap + (Math.PI - gap * 2) * cellFrame\n",
737
- " );\n",
738
- " drawOArc(\n",
739
- " Math.PI / 2 + gap,\n",
740
- " Math.PI / 2 + gap + (Math.PI - gap * 2) * cellFrame\n",
741
- " );\n",
742
- " };\n",
743
- "\n",
744
- " const board = environment.steps[step][0].observation.board;\n",
745
- "\n",
746
- " board.forEach((value, cell) => {\n",
747
- " const cellFrame =\n",
748
- " step <= 1 ||\n",
749
- " environment.steps[step - 1][0].observation.board[cell] !== value\n",
750
- " ? frame\n",
751
- " : 1;\n",
752
- " if (value === 1) drawX(cell, cellFrame);\n",
753
- " if (value === 2) drawO(cell, cellFrame);\n",
754
- " });\n",
755
- "\n",
756
- " // Draw the winning line.\n",
757
- " // [cell1, cell2, cell3, x1, y1, x2, y2]\n",
758
- " const checks = [\n",
759
- " [0, 1, 2, 1 / 19, 1 / 6, 18 / 19, 1 / 6],\n",
760
- " [3, 4, 5, 1 / 19, 1 / 2, 18 / 19, 1 / 2],\n",
761
- " [6, 7, 8, 1 / 19, 5 / 6, 18 / 19, 5 / 6],\n",
762
- " [0, 3, 6, 1 / 6, 1 / 19, 1 / 6, 18 / 19],\n",
763
- " [1, 4, 7, 1 / 2, 1 / 19, 1 / 2, 18 / 19],\n",
764
- " [2, 5, 8, 5 / 6, 1 / 19, 5 / 6, 18 / 19],\n",
765
- " [0, 4, 8, 1 / 19, 1 / 19, 18 / 19, 18 / 19],\n",
766
- " [2, 4, 6, 18 / 19, 1 / 19, 1 / 19, 18 / 19],\n",
767
- " ];\n",
768
- " for (const check of checks) {\n",
769
- " if (\n",
770
- " board[check[0]] !== 0 &&\n",
771
- " board[check[0]] === board[check[1]] &&\n",
772
- " board[check[0]] === board[check[2]]\n",
773
- " ) {\n",
774
- " const x1 = check[3] * (cellSize * 3);\n",
775
- " const y1 = check[4] * (cellSize * 3);\n",
776
- " const winFrame = frame < 0.5 ? 0 : (frame - 0.5) / 0.5;\n",
777
- " if (winFrame > 0) {\n",
778
- " drawLine({\n",
779
- " x1,\n",
780
- " y1,\n",
781
- " x2: x1 + (check[5] * (cellSize * 3) - x1) * winFrame,\n",
782
- " y2: y1 + (check[6] * (cellSize * 3) - y1) * winFrame,\n",
783
- " style: {\n",
784
- " strokeStyle: &quot;#FFF&quot;,\n",
785
- " lineWidth: 3 * winFrame,\n",
786
- " shadow: { blur: 8 * winFrame },\n",
787
- " },\n",
788
- " });\n",
789
- " }\n",
790
- " break;\n",
791
- " }\n",
792
- " }\n",
793
- "};\n",
794
- "\n",
795
- "\n",
796
- " \n",
797
- " </script>\n",
798
- " <script>\n",
799
- " const h = htm.bind(preact.h);\n",
800
- " const { useContext, useEffect, useRef, useState } = preactHooks;\n",
801
- " const styled = window.styled.default;\n",
802
- "\n",
803
- " const Context = preact.createContext({});\n",
804
- "\n",
805
- " const Loading = styled.div`\n",
806
- " animation: rotate360 1.1s infinite linear;\n",
807
- " border: 8px solid rgba(255, 255, 255, 0.2);\n",
808
- " border-left-color: #0cb1ed;\n",
809
- " border-radius: 50%;\n",
810
- " height: 40px;\n",
811
- " position: relative;\n",
812
- " transform: translateZ(0);\n",
813
- " width: 40px;\n",
814
- "\n",
815
- " @keyframes rotate360 {\n",
816
- " 0% {\n",
817
- " transform: rotate(0deg);\n",
818
- " }\n",
819
- " 100% {\n",
820
- " transform: rotate(360deg);\n",
821
- " }\n",
822
- " }\n",
823
- " `;\n",
824
- "\n",
825
- " const Logo = styled(\n",
826
- " props => h`\n",
827
- " <a href=&quot;https://kaggle.com&quot; target=&quot;_blank&quot; className=${props.className}>\n",
828
- " <svg width=&quot;62px&quot; height=&quot;20px&quot; viewBox=&quot;0 0 62 24&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;>\n",
829
- " <g fill=&quot;#1EBEFF&quot; fill-rule=&quot;nonzero&quot;>\n",
830
- " <path d=&quot;M10.2,17.8c0,0.1-0.1,0.1-0.2,0.1H7.7c-0.1,0-0.3-0.1-0.4-0.2l-3.8-4.9l-1.1,1v3.8 c0,0.2-0.1,0.3-0.3,0.3H0.3c-0.2,0-0.3-0.1-0.3-0.3V0.3C0.1,0.1,0.2,0,0.3,0h1.8c0.2,0,0.3,0.1,0.3,0.3V11L7,6.3 c0.1-0.1,0.2-0.2,0.4-0.2h2.4c0.1,0,0.2,0,0.2,0.1c0,0.1,0,0.2,0,0.2l-4.9,4.7l5.1,6.3C10.2,17.6,10.2,17.7,10.2,17.8z&quot;/>\n",
831
- " <path d=&quot;M19.6,17.9h-1.8c-0.2,0-0.3-0.1-0.3-0.3v-0.4c-0.8,0.6-1.8,0.9-3,0.9c-1.1,0-2-0.3-2.8-1 c-0.8-0.7-1.2-1.6-1.2-2.7c0-1.7,1.1-2.9,3.2-3.5c0.8-0.2,2.1-0.5,3.8-0.6c0.1-0.6-0.1-1.2-0.5-1.7c-0.4-0.5-1-0.7-1.7-0.7 c-1,0-2,0.4-3,1C12.2,9.1,12.1,9.1,12,9l-0.9-1.3C11,7.5,11,7.4,11.1,7.3c1.3-0.9,2.7-1.4,4.2-1.4c1.1,0,2.1,0.3,2.8,0.8 c1.1,0.8,1.7,2,1.7,3.7v7.3C19.9,17.8,19.8,17.9,19.6,17.9z M17.5,12.4c-1.7,0.2-2.9,0.4-3.5,0.7c-0.9,0.4-1.2,0.9-1.1,1.6 c0.1,0.4,0.2,0.7,0.6,0.9c0.3,0.2,0.7,0.4,1.1,0.4c1.2,0.1,2.2-0.2,2.9-1V12.4z&quot;/>\n",
832
- " <path d=&quot;M30.6,22.5c-0.9,1-2.3,1.5-4,1.5c-1,0-2-0.3-2.9-0.8c-0.2-0.1-0.4-0.3-0.7-0.5 c-0.3-0.2-0.6-0.5-0.9-0.7c-0.1-0.1-0.1-0.2,0-0.4l1.2-1.2c0.1-0.1,0.1-0.1,0.2-0.1c0.1,0,0.1,0,0.2,0.1c1,1,1.9,1.5,2.8,1.5 c2.1,0,3.2-1.1,3.2-3.3v-1.4c-0.8,0.7-1.9,1-3.3,1c-1.7,0-3-0.6-4-1.9c-0.8-1.1-1.3-2.5-1.3-4.2c0-1.6,0.4-3,1.2-4.1 c0.9-1.3,2.3-2,4-2c1.3,0,2.4,0.3,3.3,1V6.4c0-0.2,0.1-0.3,0.3-0.3h1.8c0.2,0,0.3,0.1,0.3,0.3v11.7C32,20,31.5,21.5,30.6,22.5z M29.7,9.9c-0.4-1.1-1.4-1.7-3-1.7c-2,0-3.1,1.3-3.1,3.8c0,1.4,0.3,2.4,1,3.1c0.5,0.5,1.2,0.8,2,0.8c1.6,0,2.7-0.6,3.1-1.7V9.9z&quot;/>\n",
833
- " <path d=&quot;M42.9,22.5c-0.9,1-2.3,1.5-4,1.5c-1,0-2-0.3-2.9-0.8c-0.2-0.1-0.4-0.3-0.7-0.5 c-0.3-0.2-0.6-0.5-0.9-0.7c-0.1-0.1-0.1-0.2,0-0.4l1.2-1.2c0.1-0.1,0.1-0.1,0.2-0.1c0.1,0,0.1,0,0.2,0.1c1,1,1.9,1.5,2.8,1.5 c2.1,0,3.2-1.1,3.2-3.3v-1.4c-0.8,0.7-1.9,1-3.3,1c-1.7,0-3-0.6-4-1.9c-0.8-1.1-1.3-2.5-1.3-4.2c0-1.6,0.4-3,1.2-4.1 c0.9-1.3,2.3-2,4-2c1.3,0,2.4,0.3,3.3,1V6.4c0-0.2,0.1-0.3,0.3-0.3H44c0.2,0,0.3,0.1,0.3,0.3v11.7C44.3,20,43.8,21.5,42.9,22.5z M42,9.9c-0.4-1.1-1.4-1.7-3-1.7c-2,0-3.1,1.3-3.1,3.8c0,1.4,0.3,2.4,1,3.1c0.5,0.5,1.2,0.8,2,0.8c1.6,0,2.7-0.6,3.1-1.7L42,9.9 L42,9.9z&quot;/>\n",
834
- " <path d=&quot;M48.3,17.9h-1.8c-0.2,0-0.3-0.1-0.3-0.3V0.3c0-0.2,0.1-0.3,0.3-0.3h1.8c0.2,0,0.3,0.1,0.3,0.3 v17.3C48.5,17.8,48.5,17.9,48.3,17.9z&quot;/>\n",
835
- " <path d=&quot;M61.4,12.6c0,0.2-0.1,0.3-0.3,0.3h-8.5c0.1,0.9,0.5,1.6,1.1,2.2c0.7,0.6,1.6,0.9,2.7,0.9 c1,0,1.8-0.3,2.6-0.8c0.2-0.1,0.3-0.1,0.4,0l1.2,1.3c0.1,0.1,0.1,0.3,0,0.4c-1.3,0.9-2.7,1.4-4.4,1.4c-1.8,0-3.3-0.6-4.4-1.8 c-1.1-1.2-1.7-2.7-1.7-4.5c0-1.7,0.6-3.2,1.7-4.4c1-1.1,2.4-1.6,4.1-1.6c1.6,0,2.9,0.6,4,1.7c1.1,1.2,1.6,2.6,1.5,4.4L61.4,12.6 z M58,8.7c-0.6-0.5-1.3-0.8-2.1-0.8c-0.8,0-1.5,0.3-2.1,0.8c-0.6,0.5-1,1.2-1.1,2H59C59,9.9,58.6,9.3,58,8.7z&quot;/>\n",
836
- " </g>\n",
837
- " </svg>\n",
838
- " </a>\n",
839
- " `\n",
840
- " )`\n",
841
- " display: inline-flex;\n",
842
- " `;\n",
843
- "\n",
844
- " const Header = styled(props => {\n",
845
- " const { environment } = useContext(Context);\n",
846
- "\n",
847
- " return h`<div className=${props.className} >\n",
848
- " <${Logo} />\n",
849
- " ${environment.title}\n",
850
- " </div>`;\n",
851
- " })`\n",
852
- " align-items: center;\n",
853
- " border-bottom: 4px solid #212121;\n",
854
- " box-sizing: border-box;\n",
855
- " color: #fff;\n",
856
- " display: flex;\n",
857
- " flex: 0 0 36px;\n",
858
- " font-size: 14px;\n",
859
- " justify-content: space-between;\n",
860
- " padding: 0 8px;\n",
861
- " width: 100%;\n",
862
- " `;\n",
863
- "\n",
864
- " const Viewer = styled(props => {\n",
865
- " const {\n",
866
- " animate,\n",
867
- " debug,\n",
868
- " playing,\n",
869
- " renderer,\n",
870
- " step,\n",
871
- " speed,\n",
872
- " environment,\n",
873
- " } = useContext(Context);\n",
874
- " const ref = preact.createRef();\n",
875
- " const stepRef = useRef(-1);\n",
876
- " stepRef.current = step;\n",
877
- "\n",
878
- " useEffect(async () => {\n",
879
- " if (!ref.current) return;\n",
880
- "\n",
881
- " const renderFrame = async (start, startStep, lastFrame) => {\n",
882
- " if (startStep !== stepRef.current) return;\n",
883
- " if (lastFrame === 1) {\n",
884
- " if (!animate) return;\n",
885
- " start = Date.now();\n",
886
- " }\n",
887
- " const frame =\n",
888
- " playing || animate\n",
889
- " ? Math.min((Date.now() - start) / speed, 1)\n",
890
- " : 1;\n",
891
- " try {\n",
892
- " if (debug) console.time(&quot;render&quot;);\n",
893
- " await renderer({\n",
894
- " parent: ref.current,\n",
895
- " environment,\n",
896
- " step,\n",
897
- " frame,\n",
898
- " width: ref.current.clientWidth,\n",
899
- " height: ref.current.clientHeight,\n",
900
- " styled,\n",
901
- " preact,\n",
902
- " hooks: preactHooks,\n",
903
- " });\n",
904
- " } catch (e) {\n",
905
- " console.log(\n",
906
- " &quot;Frame:&quot;,\n",
907
- " frame,\n",
908
- " &quot;Step:&quot;,\n",
909
- " step,\n",
910
- " &quot;Environment:&quot;,\n",
911
- " environment,\n",
912
- " &quot;Error:&quot;,\n",
913
- " e\n",
914
- " );\n",
915
- " } finally {\n",
916
- " if (debug) console.timeEnd(&quot;render&quot;);\n",
917
- " }\n",
918
- " window.requestAnimationFrame(() =>\n",
919
- " renderFrame(start, startStep, frame)\n",
920
- " );\n",
921
- " };\n",
922
- "\n",
923
- " await renderFrame(Date.now(), stepRef.current);\n",
924
- " }, [ref.current, step]);\n",
925
- "\n",
926
- " return h`<div className=${props.className} ref=${ref} />`;\n",
927
- " })`\n",
928
- " align-items: center;\n",
929
- " background-color: #000b2a;\n",
930
- " background-image: radial-gradient(\n",
931
- " circle closest-side,\n",
932
- " #000b49,\n",
933
- " #000b2a\n",
934
- " );\n",
935
- " box-sizing: border-box;\n",
936
- " display: flex;\n",
937
- " flex: 1;\n",
938
- " justify-content: center;\n",
939
- " overflow: auto;\n",
940
- " position: relative;\n",
941
- " width: 100%;\n",
942
- " `;\n",
943
- "\n",
944
- " const StepInput = styled.input.attrs({\n",
945
- " type: &quot;range&quot;,\n",
946
- " })`\n",
947
- " appearance: none;\n",
948
- " background: rgba(255, 255, 255, 0.15);\n",
949
- " border-radius: 2px;\n",
950
- " display: block;\n",
951
- " flex: 1;\n",
952
- " height: 4px;\n",
953
- " opacity: 0.8;\n",
954
- " outline: none;\n",
955
- " transition: opacity 0.2s;\n",
956
- " width: 100%;\n",
957
- "\n",
958
- " &:hover {\n",
959
- " opacity: 1;\n",
960
- " }\n",
961
- "\n",
962
- " &::-webkit-slider-thumb {\n",
963
- " appearance: none;\n",
964
- " background: #1ebeff;\n",
965
- " border-radius: 100%;\n",
966
- " cursor: pointer;\n",
967
- " height: 12px;\n",
968
- " margin: 0;\n",
969
- " position: relative;\n",
970
- " width: 12px;\n",
971
- "\n",
972
- " &::after {\n",
973
- " content: &quot;hello&quot;;\n",
974
- " position: absolute;\n",
975
- " top: 0px;\n",
976
- " left: 0px;\n",
977
- " width: 200px;\n",
978
- " height: 8px;\n",
979
- " background: green;\n",
980
- " }\n",
981
- " }\n",
982
- " `;\n",
983
- "\n",
984
- " const PlayButton = styled.button`\n",
985
- " align-items: center;\n",
986
- " background: none;\n",
987
- " border: none;\n",
988
- " color: white;\n",
989
- " cursor: pointer;\n",
990
- " display: flex;\n",
991
- " flex: 0 0 56px;\n",
992
- " font-size: 20px;\n",
993
- " height: 40px;\n",
994
- " justify-content: center;\n",
995
- " opacity: 0.8;\n",
996
- " outline: none;\n",
997
- " transition: opacity 0.2s;\n",
998
- "\n",
999
- " &:hover {\n",
1000
- " opacity: 1;\n",
1001
- " }\n",
1002
- " `;\n",
1003
- "\n",
1004
- " const StepCount = styled.span`\n",
1005
- " align-items: center;\n",
1006
- " color: white;\n",
1007
- " display: flex;\n",
1008
- " font-size: 14px;\n",
1009
- " justify-content: center;\n",
1010
- " opacity: 0.8;\n",
1011
- " padding: 0 16px;\n",
1012
- " pointer-events: none;\n",
1013
- " `;\n",
1014
- "\n",
1015
- " const Controls = styled(props => {\n",
1016
- " const { environment, pause, play, playing, setStep, step } = useContext(\n",
1017
- " Context\n",
1018
- " );\n",
1019
- " const value = step + 1;\n",
1020
- " const onClick = () => (playing ? pause() : play());\n",
1021
- " const onInput = e => {\n",
1022
- " pause();\n",
1023
- " setStep(parseInt(e.target.value) - 1);\n",
1024
- " };\n",
1025
- "\n",
1026
- " return h`\n",
1027
- " <div className=${props.className}>\n",
1028
- " <${PlayButton} onClick=${onClick}><svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24px&quot; height=&quot;24px&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;#FFFFFF&quot;>${\n",
1029
- " playing\n",
1030
- " ? h`<path d=&quot;M6 19h4V5H6v14zm8-14v14h4V5h-4z&quot;/><path d=&quot;M0 0h24v24H0z&quot; fill=&quot;none&quot;/>`\n",
1031
- " : h`<path d=&quot;M8 5v14l11-7z&quot;/><path d=&quot;M0 0h24v24H0z&quot; fill=&quot;none&quot;/>`\n",
1032
- " }</svg><//>\n",
1033
- " <${StepInput} min=&quot;1&quot; max=${\n",
1034
- " environment.steps.length\n",
1035
- " } value=&quot;${value}&quot; onInput=${onInput} />\n",
1036
- " <${StepCount}>${value} / ${environment.steps.length}<//>\n",
1037
- " </div>\n",
1038
- " `;\n",
1039
- " })`\n",
1040
- " align-items: center;\n",
1041
- " border-top: 4px solid #212121;\n",
1042
- " display: flex;\n",
1043
- " flex: 0 0 44px;\n",
1044
- " width: 100%;\n",
1045
- " `;\n",
1046
- "\n",
1047
- " const Info = styled(props => {\n",
1048
- " const {\n",
1049
- " environment,\n",
1050
- " playing,\n",
1051
- " step,\n",
1052
- " speed,\n",
1053
- " animate,\n",
1054
- " header,\n",
1055
- " controls,\n",
1056
- " settings,\n",
1057
- " } = useContext(Context);\n",
1058
- "\n",
1059
- " return h`\n",
1060
- " <div className=${props.className}>\n",
1061
- " info:\n",
1062
- " step(${step}),\n",
1063
- " playing(${playing ? &quot;T&quot; : &quot;F&quot;}),\n",
1064
- " speed(${speed}),\n",
1065
- " animate(${animate ? &quot;T&quot; : &quot;F&quot;})\n",
1066
- " </div>`;\n",
1067
- " })`\n",
1068
- " color: #888;\n",
1069
- " font-family: monospace;\n",
1070
- " font-size: 12px;\n",
1071
- " `;\n",
1072
- "\n",
1073
- " const Settings = styled(props => {\n",
1074
- " const { environment, pause, play, playing, setStep, step } = useContext(\n",
1075
- " Context\n",
1076
- " );\n",
1077
- "\n",
1078
- " return h`\n",
1079
- " <div className=${props.className}>\n",
1080
- " <${Info} />\n",
1081
- " </div>\n",
1082
- " `;\n",
1083
- " })`\n",
1084
- " background: #fff;\n",
1085
- " border-top: 4px solid #212121;\n",
1086
- " box-sizing: border-box;\n",
1087
- " padding: 20px;\n",
1088
- " width: 100%;\n",
1089
- "\n",
1090
- " h1 {\n",
1091
- " font-size: 20px;\n",
1092
- " }\n",
1093
- " `;\n",
1094
- "\n",
1095
- " const Player = styled(props => {\n",
1096
- " const context = useContext(Context);\n",
1097
- " const { controls, header, loading, settings } = context;\n",
1098
- " return h`\n",
1099
- " <div className=${props.className}>\n",
1100
- " ${loading && h`<${Loading} />`}\n",
1101
- " ${!loading && header && h`<${Header} />`}\n",
1102
- " ${!loading && h`<${Viewer} />`}\n",
1103
- " ${!loading && controls && h`<${Controls} />`}\n",
1104
- " ${!loading && settings && h`<${Settings} />`}\n",
1105
- " </div>`;\n",
1106
- " })`\n",
1107
- " align-items: center;\n",
1108
- " background: #212121;\n",
1109
- " border: 4px solid #212121;\n",
1110
- " box-sizing: border-box;\n",
1111
- " display: flex;\n",
1112
- " flex-direction: column;\n",
1113
- " height: 100%;\n",
1114
- " justify-content: center;\n",
1115
- " position: relative;\n",
1116
- " width: 100%;\n",
1117
- " `;\n",
1118
- "\n",
1119
- " const App = () => {\n",
1120
- " const renderCountRef = useRef(0);\n",
1121
- " const [_, setRenderCount] = useState(0);\n",
1122
- "\n",
1123
- " const contextRef = useRef({\n",
1124
- " animate: false,\n",
1125
- " autoplay: false,\n",
1126
- " controls: false,\n",
1127
- " debug: false,\n",
1128
- " header: window.innerHeight >= 600,\n",
1129
- " loading: false,\n",
1130
- " environment: { steps: [] },\n",
1131
- " playing: false,\n",
1132
- " renderer: () => &quot;DNE&quot;,\n",
1133
- " settings: false,\n",
1134
- " speed: 500,\n",
1135
- " step: 0,\n",
1136
- " });\n",
1137
- "\n",
1138
- " // Context helpers.\n",
1139
- " const rerender = (contextRef.current.rerender = () =>\n",
1140
- " setRenderCount((renderCountRef.current += 1)));\n",
1141
- " const setStep = (contextRef.current.setStep = newStep => {\n",
1142
- " contextRef.current.step = newStep;\n",
1143
- " rerender();\n",
1144
- " });\n",
1145
- " const setPlaying = (contextRef.current.setPlaying = playing => {\n",
1146
- " contextRef.current.playing = playing;\n",
1147
- " rerender();\n",
1148
- " });\n",
1149
- " const pause = (contextRef.current.pause = () => setPlaying(false));\n",
1150
- "\n",
1151
- " const playNext = () => {\n",
1152
- " const context = contextRef.current;\n",
1153
- "\n",
1154
- " if (\n",
1155
- " context.playing &&\n",
1156
- " context.step < context.environment.steps.length - 1\n",
1157
- " ) {\n",
1158
- " setStep(context.step + 1);\n",
1159
- " play(true);\n",
1160
- " } else {\n",
1161
- " pause();\n",
1162
- " }\n",
1163
- " };\n",
1164
- "\n",
1165
- " const play = (contextRef.current.play = continuing => {\n",
1166
- " const context = contextRef.current;\n",
1167
- " if (context.playing && !continuing) return;\n",
1168
- " if (!context.playing) setPlaying(true);\n",
1169
- " if (\n",
1170
- " !continuing &&\n",
1171
- " context.step === context.environment.steps.length - 1\n",
1172
- " ) {\n",
1173
- " setStep(0);\n",
1174
- " }\n",
1175
- " setTimeout(playNext, context.speed);\n",
1176
- " });\n",
1177
- "\n",
1178
- " const updateContext = o => {\n",
1179
- " const context = contextRef.current;\n",
1180
- " Object.assign(context, o, {\n",
1181
- " environment: { ...context.environment, ...(o.environment || {}) },\n",
1182
- " });\n",
1183
- " rerender();\n",
1184
- "\n",
1185
- " // If autoplay, toggle to playing.\n",
1186
- " if (context.autoplay) play();\n",
1187
- " };\n",
1188
- "\n",
1189
- " // First time setup.\n",
1190
- " useEffect(() => {\n",
1191
- " // Timeout is used to ensure useEffect renders once.\n",
1192
- " setTimeout(() => {\n",
1193
- " // Initialize context with window.kaggle.\n",
1194
- " updateContext(window.kaggle || {});\n",
1195
- " // Listen for messages received to update the context.\n",
1196
- " window.addEventListener(\n",
1197
- " &quot;message&quot;,\n",
1198
- " event => {\n",
1199
- " // Ensure the environment names match before updating.\n",
1200
- " try {\n",
1201
- " if (\n",
1202
- " event.data.environment.name ==\n",
1203
- " contextRef.current.environment.name\n",
1204
- " ) {\n",
1205
- " updateContext(event.data);\n",
1206
- " }\n",
1207
- " } catch {}\n",
1208
- " },\n",
1209
- " false\n",
1210
- " );\n",
1211
- " }, 1);\n",
1212
- " }, []);\n",
1213
- "\n",
1214
- " if (contextRef.current.debug) {\n",
1215
- " console.log(&quot;context&quot;, contextRef.current);\n",
1216
- " }\n",
1217
- "\n",
1218
- " return h`\n",
1219
- " <${Context.Provider} value=${contextRef.current}>\n",
1220
- " <${Player} />\n",
1221
- " <//>`;\n",
1222
- " };\n",
1223
- "\n",
1224
- " preact.render(h`<${App} />`, document.body);\n",
1225
- " </script>\n",
1226
- " </body>\n",
1227
- "</html>\n",
1228
- "\" width=\"300\" height=\"300\" frameborder=\"0\"></iframe> "
1229
- ],
1230
- "text/plain": [
1231
- "<IPython.core.display.HTML object>"
1232
- ]
1233
- },
1234
- "metadata": {},
1235
- "output_type": "display_data"
1236
- }
1237
- ],
1238
- "source": [
1239
- "def agent(observation):\n",
1240
- " board = observation.board\n",
1241
- " play_order = [4,0,2,6,8,1,3,5,7]\n",
1242
- " EMPTY = 0\n",
1243
- " return [c for c in play_order if board[c] == EMPTY][0]\n",
1244
- "\n",
1245
- "env = make(\"tictactoe\", debug=True)\n",
1246
- "\n",
1247
- "# play agent above vs default random agent.\n",
1248
- "env.run([agent, \"random\"])\n",
1249
- "env.render(mode=\"ipython\")"
1250
- ]
1251
- },
1252
- {
1253
- "cell_type": "markdown",
1254
- "metadata": {},
1255
- "source": [
1256
- "## Specification"
1257
- ]
1258
- },
1259
- {
1260
- "cell_type": "code",
1261
- "execution_count": 3,
1262
- "metadata": {
1263
- "scrolled": false
1264
- },
1265
- "outputs": [
1266
- {
1267
- "name": "stdout",
1268
- "output_type": "stream",
1269
- "text": [
1270
- "Observation: {\n",
1271
- " \"board\": {\n",
1272
- " \"default\": [\n",
1273
- " 0,\n",
1274
- " 0,\n",
1275
- " 0,\n",
1276
- " 0,\n",
1277
- " 0,\n",
1278
- " 0,\n",
1279
- " 0,\n",
1280
- " 0,\n",
1281
- " 0\n",
1282
- " ],\n",
1283
- " \"description\": \"Serialized 3x3 grid. 0 = Empty, 1 = X, 2 = O\",\n",
1284
- " \"maxItems\": 9,\n",
1285
- " \"minItems\": 9,\n",
1286
- " \"type\": \"array\"\n",
1287
- " },\n",
1288
- " \"mark\": {\n",
1289
- " \"description\": \"Mark for the agent to use\",\n",
1290
- " \"enum\": [\n",
1291
- " 1,\n",
1292
- " 2\n",
1293
- " ]\n",
1294
- " }\n",
1295
- "}\n",
1296
- "Action: {\n",
1297
- " \"default\": 0,\n",
1298
- " \"description\": \"Position to place a mark on the board.\",\n",
1299
- " \"maximum\": 8,\n",
1300
- " \"minimum\": 0,\n",
1301
- " \"type\": \"integer\"\n",
1302
- "}\n"
1303
- ]
1304
- }
1305
- ],
1306
- "source": [
1307
- "import json\n",
1308
- "print(\"Observation:\", json.dumps(env.specification.observation, indent=4, sort_keys=True))\n",
1309
- "print(\"Action:\", json.dumps(env.specification.action, indent=4, sort_keys=True))"
1310
- ]
1311
- },
1312
- {
1313
- "cell_type": "markdown",
1314
- "metadata": {},
1315
- "source": [
1316
- "## Training using Gym"
1317
- ]
1318
- },
1319
- {
1320
- "cell_type": "code",
1321
- "execution_count": 9,
1322
- "metadata": {},
1323
- "outputs": [
1324
- {
1325
- "name": "stdout",
1326
- "output_type": "stream",
1327
- "text": [
1328
- " X | X | O \n",
1329
- "---+---+---\n",
1330
- " X | O | \n",
1331
- "---+---+---\n",
1332
- " O | | \n"
1333
- ]
1334
- }
1335
- ],
1336
- "source": [
1337
- "from kaggle_environments import make\n",
1338
- "import gym\n",
1339
- "\n",
1340
- "class TicTacToe(gym.Env):\n",
1341
- "\n",
1342
- " def __init__(self):\n",
1343
- " self.env = make(\"tictactoe\", debug=True)\n",
1344
- " self.trainer = self.env.train([None, \"random\"])\n",
1345
- " \n",
1346
- " # Define required gym fields (examples):\n",
1347
- " self.action_space = gym.spaces.Discrete(9)\n",
1348
- " self.observation_space = gym.spaces.Discrete(27)\n",
1349
- "\n",
1350
- " def step(self, action):\n",
1351
- " return self.trainer.step(action)\n",
1352
- " \n",
1353
- " def reset(self):\n",
1354
- " return self.trainer.reset()\n",
1355
- " \n",
1356
- " def render(self, **kwargs):\n",
1357
- " return self.env.render(**kwargs)\n",
1358
- " \n",
1359
- " \n",
1360
- "env = TicTacToe()\n",
1361
- "\n",
1362
- "done = False\n",
1363
- "obs = env.reset()\n",
1364
- "while not done:\n",
1365
- " # Choose first available empty cell as the action.\n",
1366
- " action = [i for i in range(len(obs.board)) if obs.board[i] == 0][0]\n",
1367
- " obs, reward, done, info = env.step(action)\n",
1368
- "env.render()"
1369
- ]
1370
- }
1371
- ],
1372
- "metadata": {
1373
- "kernelspec": {
1374
- "display_name": "Python 3",
1375
- "language": "python",
1376
- "name": "python3"
1377
- },
1378
- "language_info": {
1379
- "codemirror_mode": {
1380
- "name": "ipython",
1381
- "version": 3
1382
- },
1383
- "file_extension": ".py",
1384
- "mimetype": "text/x-python",
1385
- "name": "python",
1386
- "nbconvert_exporter": "python",
1387
- "pygments_lexer": "ipython3",
1388
- "version": "3.7.6"
1389
- }
1390
- },
1391
- "nbformat": 4,
1392
- "nbformat_minor": 2
1393
- }