kaggle-environments 0.2.0__py3-none-any.whl → 1.20.0__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 (215) hide show
  1. kaggle_environments/__init__.py +49 -13
  2. kaggle_environments/agent.py +177 -124
  3. kaggle_environments/api.py +31 -0
  4. kaggle_environments/core.py +298 -173
  5. kaggle_environments/envs/cabt/cabt.js +164 -0
  6. kaggle_environments/envs/cabt/cabt.json +28 -0
  7. kaggle_environments/envs/cabt/cabt.py +186 -0
  8. kaggle_environments/envs/cabt/cg/__init__.py +0 -0
  9. kaggle_environments/envs/cabt/cg/cg.dll +0 -0
  10. kaggle_environments/envs/cabt/cg/game.py +75 -0
  11. kaggle_environments/envs/cabt/cg/libcg.so +0 -0
  12. kaggle_environments/envs/cabt/cg/sim.py +48 -0
  13. kaggle_environments/envs/cabt/test_cabt.py +120 -0
  14. kaggle_environments/envs/chess/chess.js +4289 -0
  15. kaggle_environments/envs/chess/chess.json +60 -0
  16. kaggle_environments/envs/chess/chess.py +4241 -0
  17. kaggle_environments/envs/chess/test_chess.py +60 -0
  18. kaggle_environments/envs/connectx/connectx.ipynb +3186 -0
  19. kaggle_environments/envs/connectx/connectx.js +1 -1
  20. kaggle_environments/envs/connectx/connectx.json +15 -1
  21. kaggle_environments/envs/connectx/connectx.py +6 -23
  22. kaggle_environments/envs/connectx/test_connectx.py +70 -24
  23. kaggle_environments/envs/football/football.ipynb +75 -0
  24. kaggle_environments/envs/football/football.json +91 -0
  25. kaggle_environments/envs/football/football.py +277 -0
  26. kaggle_environments/envs/football/helpers.py +95 -0
  27. kaggle_environments/envs/football/test_football.py +360 -0
  28. kaggle_environments/envs/halite/__init__.py +0 -0
  29. kaggle_environments/envs/halite/halite.ipynb +44741 -0
  30. kaggle_environments/envs/halite/halite.js +199 -83
  31. kaggle_environments/envs/halite/halite.json +31 -18
  32. kaggle_environments/envs/halite/halite.py +164 -303
  33. kaggle_environments/envs/halite/helpers.py +720 -0
  34. kaggle_environments/envs/halite/test_halite.py +190 -0
  35. kaggle_environments/envs/hungry_geese/__init__.py +0 -0
  36. kaggle_environments/envs/{battlegeese/battlegeese.js → hungry_geese/hungry_geese.js} +38 -22
  37. kaggle_environments/envs/{battlegeese/battlegeese.json → hungry_geese/hungry_geese.json} +22 -15
  38. kaggle_environments/envs/hungry_geese/hungry_geese.py +316 -0
  39. kaggle_environments/envs/hungry_geese/test_hungry_geese.py +0 -0
  40. kaggle_environments/envs/identity/identity.json +6 -5
  41. kaggle_environments/envs/identity/identity.py +15 -2
  42. kaggle_environments/envs/kore_fleets/__init__.py +0 -0
  43. kaggle_environments/envs/kore_fleets/helpers.py +1005 -0
  44. kaggle_environments/envs/kore_fleets/kore_fleets.ipynb +114 -0
  45. kaggle_environments/envs/kore_fleets/kore_fleets.js +658 -0
  46. kaggle_environments/envs/kore_fleets/kore_fleets.json +164 -0
  47. kaggle_environments/envs/kore_fleets/kore_fleets.py +555 -0
  48. kaggle_environments/envs/kore_fleets/starter_bots/java/Bot.java +54 -0
  49. kaggle_environments/envs/kore_fleets/starter_bots/java/README.md +26 -0
  50. kaggle_environments/envs/kore_fleets/starter_bots/java/jars/hamcrest-core-1.3.jar +0 -0
  51. kaggle_environments/envs/kore_fleets/starter_bots/java/jars/junit-4.13.2.jar +0 -0
  52. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Board.java +518 -0
  53. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Cell.java +61 -0
  54. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Configuration.java +24 -0
  55. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Direction.java +166 -0
  56. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Fleet.java +72 -0
  57. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/KoreJson.java +97 -0
  58. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Observation.java +72 -0
  59. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Pair.java +13 -0
  60. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Player.java +68 -0
  61. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Point.java +65 -0
  62. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/Shipyard.java +70 -0
  63. kaggle_environments/envs/kore_fleets/starter_bots/java/kore/ShipyardAction.java +59 -0
  64. kaggle_environments/envs/kore_fleets/starter_bots/java/main.py +73 -0
  65. kaggle_environments/envs/kore_fleets/starter_bots/java/test/BoardTest.java +567 -0
  66. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ConfigurationTest.java +25 -0
  67. kaggle_environments/envs/kore_fleets/starter_bots/java/test/KoreJsonTest.java +62 -0
  68. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ObservationTest.java +46 -0
  69. kaggle_environments/envs/kore_fleets/starter_bots/java/test/PointTest.java +21 -0
  70. kaggle_environments/envs/kore_fleets/starter_bots/java/test/ShipyardTest.java +22 -0
  71. kaggle_environments/envs/kore_fleets/starter_bots/java/test/configuration.json +1 -0
  72. kaggle_environments/envs/kore_fleets/starter_bots/java/test/fullob.json +1 -0
  73. kaggle_environments/envs/kore_fleets/starter_bots/java/test/observation.json +1 -0
  74. kaggle_environments/envs/kore_fleets/starter_bots/python/__init__.py +0 -0
  75. kaggle_environments/envs/kore_fleets/starter_bots/python/main.py +27 -0
  76. kaggle_environments/envs/kore_fleets/starter_bots/ts/Bot.ts +34 -0
  77. kaggle_environments/envs/kore_fleets/starter_bots/ts/DoNothingBot.ts +12 -0
  78. kaggle_environments/envs/kore_fleets/starter_bots/ts/MinerBot.ts +62 -0
  79. kaggle_environments/envs/kore_fleets/starter_bots/ts/README.md +55 -0
  80. kaggle_environments/envs/kore_fleets/starter_bots/ts/interpreter.ts +402 -0
  81. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Board.ts +514 -0
  82. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Cell.ts +63 -0
  83. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Configuration.ts +25 -0
  84. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Direction.ts +169 -0
  85. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Fleet.ts +76 -0
  86. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/KoreIO.ts +70 -0
  87. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Observation.ts +45 -0
  88. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Pair.ts +11 -0
  89. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Player.ts +68 -0
  90. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Point.ts +65 -0
  91. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/Shipyard.ts +72 -0
  92. kaggle_environments/envs/kore_fleets/starter_bots/ts/kore/ShipyardAction.ts +58 -0
  93. kaggle_environments/envs/kore_fleets/starter_bots/ts/main.py +73 -0
  94. kaggle_environments/envs/kore_fleets/starter_bots/ts/miner.py +73 -0
  95. kaggle_environments/envs/kore_fleets/starter_bots/ts/package.json +23 -0
  96. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/BoardTest.ts +551 -0
  97. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/ConfigurationTest.ts +16 -0
  98. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/ObservationTest.ts +33 -0
  99. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/PointTest.ts +17 -0
  100. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/ShipyardTest.ts +18 -0
  101. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/configuration.json +1 -0
  102. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/fullob.json +1 -0
  103. kaggle_environments/envs/kore_fleets/starter_bots/ts/test/observation.json +1 -0
  104. kaggle_environments/envs/kore_fleets/starter_bots/ts/tsconfig.json +22 -0
  105. kaggle_environments/envs/kore_fleets/test_kore_fleets.py +331 -0
  106. kaggle_environments/envs/lux_ai_2021/README.md +3 -0
  107. kaggle_environments/envs/lux_ai_2021/__init__.py +0 -0
  108. kaggle_environments/envs/lux_ai_2021/agents.py +11 -0
  109. kaggle_environments/envs/lux_ai_2021/dimensions/754.js +2 -0
  110. kaggle_environments/envs/lux_ai_2021/dimensions/754.js.LICENSE.txt +296 -0
  111. kaggle_environments/envs/lux_ai_2021/dimensions/main.js +1 -0
  112. kaggle_environments/envs/lux_ai_2021/index.html +43 -0
  113. kaggle_environments/envs/lux_ai_2021/lux_ai_2021.json +100 -0
  114. kaggle_environments/envs/lux_ai_2021/lux_ai_2021.py +231 -0
  115. kaggle_environments/envs/lux_ai_2021/test_agents/__init__.py +0 -0
  116. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/game_constants.js +6 -0
  117. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/game_constants.json +59 -0
  118. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/game_objects.js +145 -0
  119. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/io.js +14 -0
  120. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/kit.js +209 -0
  121. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/map.js +107 -0
  122. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/lux/parser.js +79 -0
  123. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/main.js +88 -0
  124. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/main.py +75 -0
  125. kaggle_environments/envs/lux_ai_2021/test_agents/js_simple/simple.tar.gz +0 -0
  126. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/__init__.py +0 -0
  127. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/annotate.py +20 -0
  128. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/constants.py +25 -0
  129. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/game.py +86 -0
  130. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/game_constants.json +59 -0
  131. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/game_constants.py +7 -0
  132. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/game_map.py +106 -0
  133. kaggle_environments/envs/lux_ai_2021/test_agents/python/lux/game_objects.py +154 -0
  134. kaggle_environments/envs/lux_ai_2021/test_agents/python/random_agent.py +38 -0
  135. kaggle_environments/envs/lux_ai_2021/test_agents/python/simple_agent.py +82 -0
  136. kaggle_environments/envs/lux_ai_2021/test_lux.py +19 -0
  137. kaggle_environments/envs/lux_ai_2021/testing.md +23 -0
  138. kaggle_environments/envs/lux_ai_2021/todo.md.og +18 -0
  139. kaggle_environments/envs/lux_ai_s3/README.md +21 -0
  140. kaggle_environments/envs/lux_ai_s3/agents.py +5 -0
  141. kaggle_environments/envs/lux_ai_s3/index.html +42 -0
  142. kaggle_environments/envs/lux_ai_s3/lux_ai_s3.json +47 -0
  143. kaggle_environments/envs/lux_ai_s3/lux_ai_s3.py +178 -0
  144. kaggle_environments/envs/lux_ai_s3/luxai_s3/__init__.py +1 -0
  145. kaggle_environments/envs/lux_ai_s3/luxai_s3/env.py +819 -0
  146. kaggle_environments/envs/lux_ai_s3/luxai_s3/globals.py +9 -0
  147. kaggle_environments/envs/lux_ai_s3/luxai_s3/params.py +101 -0
  148. kaggle_environments/envs/lux_ai_s3/luxai_s3/profiler.py +141 -0
  149. kaggle_environments/envs/lux_ai_s3/luxai_s3/pygame_render.py +222 -0
  150. kaggle_environments/envs/lux_ai_s3/luxai_s3/spaces.py +27 -0
  151. kaggle_environments/envs/lux_ai_s3/luxai_s3/state.py +464 -0
  152. kaggle_environments/envs/lux_ai_s3/luxai_s3/utils.py +12 -0
  153. kaggle_environments/envs/lux_ai_s3/luxai_s3/wrappers.py +156 -0
  154. kaggle_environments/envs/lux_ai_s3/test_agents/python/agent.py +78 -0
  155. kaggle_environments/envs/lux_ai_s3/test_agents/python/lux/__init__.py +0 -0
  156. kaggle_environments/envs/lux_ai_s3/test_agents/python/lux/kit.py +31 -0
  157. kaggle_environments/envs/lux_ai_s3/test_agents/python/lux/utils.py +17 -0
  158. kaggle_environments/envs/lux_ai_s3/test_agents/python/main.py +66 -0
  159. kaggle_environments/envs/lux_ai_s3/test_lux.py +9 -0
  160. kaggle_environments/envs/mab/__init__.py +0 -0
  161. kaggle_environments/envs/mab/agents.py +12 -0
  162. kaggle_environments/envs/mab/mab.js +100 -0
  163. kaggle_environments/envs/mab/mab.json +74 -0
  164. kaggle_environments/envs/mab/mab.py +146 -0
  165. kaggle_environments/envs/open_spiel/__init__.py +0 -0
  166. kaggle_environments/envs/open_spiel/games/__init__.py +0 -0
  167. kaggle_environments/envs/open_spiel/games/chess/chess.js +441 -0
  168. kaggle_environments/envs/open_spiel/games/chess/image_config.jsonl +20 -0
  169. kaggle_environments/envs/open_spiel/games/chess/openings.jsonl +20 -0
  170. kaggle_environments/envs/open_spiel/games/connect_four/__init__.py +0 -0
  171. kaggle_environments/envs/open_spiel/games/connect_four/connect_four.js +284 -0
  172. kaggle_environments/envs/open_spiel/games/connect_four/connect_four_proxy.py +86 -0
  173. kaggle_environments/envs/open_spiel/games/go/__init__.py +0 -0
  174. kaggle_environments/envs/open_spiel/games/go/go.js +481 -0
  175. kaggle_environments/envs/open_spiel/games/go/go_proxy.py +99 -0
  176. kaggle_environments/envs/open_spiel/games/tic_tac_toe/__init__.py +0 -0
  177. kaggle_environments/envs/open_spiel/games/tic_tac_toe/tic_tac_toe.js +345 -0
  178. kaggle_environments/envs/open_spiel/games/tic_tac_toe/tic_tac_toe_proxy.py +98 -0
  179. kaggle_environments/envs/open_spiel/games/universal_poker/__init__.py +0 -0
  180. kaggle_environments/envs/open_spiel/games/universal_poker/universal_poker.js +431 -0
  181. kaggle_environments/envs/open_spiel/games/universal_poker/universal_poker_proxy.py +159 -0
  182. kaggle_environments/envs/open_spiel/html_playthrough_generator.py +31 -0
  183. kaggle_environments/envs/open_spiel/observation.py +128 -0
  184. kaggle_environments/envs/open_spiel/open_spiel.py +565 -0
  185. kaggle_environments/envs/open_spiel/proxy.py +138 -0
  186. kaggle_environments/envs/open_spiel/test_open_spiel.py +191 -0
  187. kaggle_environments/envs/rps/__init__.py +0 -0
  188. kaggle_environments/envs/rps/agents.py +84 -0
  189. kaggle_environments/envs/rps/helpers.py +25 -0
  190. kaggle_environments/envs/rps/rps.js +117 -0
  191. kaggle_environments/envs/rps/rps.json +63 -0
  192. kaggle_environments/envs/rps/rps.py +90 -0
  193. kaggle_environments/envs/rps/test_rps.py +110 -0
  194. kaggle_environments/envs/rps/utils.py +7 -0
  195. kaggle_environments/envs/tictactoe/test_tictactoe.py +43 -77
  196. kaggle_environments/envs/tictactoe/tictactoe.ipynb +1397 -0
  197. kaggle_environments/envs/tictactoe/tictactoe.json +10 -2
  198. kaggle_environments/envs/tictactoe/tictactoe.py +1 -1
  199. kaggle_environments/errors.py +2 -4
  200. kaggle_environments/helpers.py +377 -0
  201. kaggle_environments/main.py +214 -50
  202. kaggle_environments/schemas.json +23 -18
  203. kaggle_environments/static/player.html +206 -74
  204. kaggle_environments/utils.py +46 -73
  205. kaggle_environments-1.20.0.dist-info/METADATA +25 -0
  206. kaggle_environments-1.20.0.dist-info/RECORD +211 -0
  207. {kaggle_environments-0.2.0.dist-info → kaggle_environments-1.20.0.dist-info}/WHEEL +1 -2
  208. kaggle_environments-1.20.0.dist-info/entry_points.txt +3 -0
  209. kaggle_environments/envs/battlegeese/battlegeese.py +0 -219
  210. kaggle_environments/temp.py +0 -14
  211. kaggle_environments-0.2.0.dist-info/METADATA +0 -393
  212. kaggle_environments-0.2.0.dist-info/RECORD +0 -33
  213. kaggle_environments-0.2.0.dist-info/entry_points.txt +0 -3
  214. kaggle_environments-0.2.0.dist-info/top_level.txt +0 -1
  215. {kaggle_environments-0.2.0.dist-info → kaggle_environments-1.20.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,219 +0,0 @@
1
- # Copyright 2020 Kaggle Inc
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- import json
16
- from os import path
17
- from random import choice, sample
18
-
19
-
20
- def get_pos(from_pos, direction, columns, rows):
21
- if direction == "N":
22
- if from_pos - columns < 0:
23
- return -1
24
- return from_pos - columns
25
- if direction == "S":
26
- if from_pos + columns >= columns * rows:
27
- return -1
28
- return from_pos + columns
29
- if direction == "E":
30
- if from_pos // columns != (from_pos + 1) // columns:
31
- return -1
32
- return from_pos + 1
33
- if direction == "W":
34
- if from_pos // columns != (from_pos - 1) // columns:
35
- return -1
36
- return from_pos - 1
37
-
38
-
39
- def min_distance(pos, food, config):
40
- cols = config.columns
41
- return min([abs(pos % cols - fpos % cols) + abs(pos // cols - fpos // cols) for fpos in food])
42
-
43
-
44
- def random_agent():
45
- return choice(["N", "S", "E", "W"])
46
-
47
-
48
- def shortest_path_agent(obs, config):
49
- columns = config.columns
50
- rows = config.rows
51
- goose = obs.geese[obs.index]
52
- head = goose[0]
53
- max_value = columns * rows
54
- directions = ["N", "S", "E", "W"]
55
-
56
- geese = [g for g in obs.geese if len(g) > 0]
57
- heads = [g[0] for g in geese]
58
- tails = [g[-1] for g in geese]
59
- bodies = [p for g in geese for p in g[:-1]]
60
-
61
- actions = {}
62
- for d in directions:
63
- # Get new position - or -1 if run into wall.
64
- pos = get_pos(head, d, columns, rows)
65
- if (
66
- pos in bodies or # Hit a body.
67
- (len(goose) > 1 and goose[1] == pos) or # Backwards.
68
- # Hit a tail when head over food.
69
- (pos in tails and heads[tails.index(pos)] in obs.food)
70
- ):
71
- pos = -1
72
- actions[d] = max_value if pos == - \
73
- 1 else min_distance(pos, obs.food, config)
74
- # Possibility of a collision, devalue a valid action.
75
- for h in heads:
76
- if h == head:
77
- continue
78
- for dh in directions:
79
- posh = get_pos(h, dh, columns, rows)
80
- if posh == pos:
81
- actions[d] += 1
82
-
83
- return min(actions, key=actions.get)
84
-
85
-
86
- agents = {"random": random_agent, "shortest": shortest_path_agent}
87
-
88
-
89
- def interpreter(state, env):
90
- config = env.configuration
91
- columns = config.columns
92
- rows = config.rows
93
- hunger_rate = config.hunger_rate
94
- min_food = config.min_food
95
- num_agents = len(state)
96
-
97
- # Clone the geese and food observation between all the agents.
98
- geese = state[0].observation.geese
99
- food = state[0].observation.food
100
- for agent in state:
101
- agent.observation.geese = geese
102
- agent.observation.food = food
103
-
104
- # Reset the environment.
105
- if env.done:
106
- # Distribute food and geese randomly.
107
- starting_positions = sample(range(columns * rows), num_agents * 2)
108
- for index in range(num_agents):
109
- geese.append([starting_positions[index]])
110
- food.append(starting_positions[index + num_agents])
111
- return state
112
-
113
- # Apply the actions from active agents.
114
- for index, agent in enumerate(state):
115
- if agent.status != "ACTIVE":
116
- continue
117
- action = agent.action
118
- goose = geese[index]
119
- head = goose[0]
120
- new_head = get_pos(head, action, columns, rows)
121
-
122
- # Wall Hit.
123
- if new_head == -1:
124
- agent.status = f"Wall Hit: {action}"
125
- agent.reward = 0
126
- geese[index] = []
127
- continue
128
-
129
- # Last Body Hit.
130
- if len(goose) > 1 and goose[1] == new_head:
131
- agent.status = f"Body Hit: {action}"
132
- agent.reward = 0
133
- geese[index] = []
134
- continue
135
-
136
- # Add New Head to the Goose.
137
- goose.insert(0, new_head)
138
-
139
- # Check Food.
140
- if head in food:
141
- food.remove(head)
142
- else:
143
- goose.pop()
144
-
145
- # If hunger strikes remove from the tail.
146
- if len(env.steps) % hunger_rate == 0:
147
- goose.pop()
148
- if len(goose) == 0:
149
- agent.status = f"Goose Starved: {action}"
150
- agent.reward = 0
151
- geese[index] = []
152
- continue
153
-
154
- # Check for collisions.
155
- collisions = {}
156
- for goose in geese:
157
- for pos in goose:
158
- collisions[pos] = collisions.get(pos, 0) + 1
159
- for index, agent in enumerate(state):
160
- for pos in geese[index]:
161
- if collisions[pos] > 1:
162
- agent.status = f"Goose Collision: {agent.action}"
163
- agent.reward = 0
164
- geese[index] = []
165
- continue
166
-
167
- # Add food if min_food threshold reached.
168
- if len(food) < min_food:
169
- available_positions = list(range(rows * columns))
170
- for goose in geese:
171
- for pos in goose:
172
- available_positions.remove(pos)
173
- food.extend(sample(available_positions, min_food - len(food)))
174
-
175
- # If only one ACTIVE agent left, set it's reward to 1 and make INACTIVE.
176
- active_agents = [a for a in state if a.status == "ACTIVE"]
177
- if len(active_agents) == 1:
178
- active_agents[0].status = "INACTIVE"
179
- active_agents[0].reward = 1
180
-
181
- return state
182
-
183
-
184
- def renderer(state, env):
185
- config = env.configuration
186
- columns = config.columns
187
- rows = config.rows
188
-
189
- foodSymbol = "F"
190
- colDivider = "|"
191
- rowDivider = "+" + "+".join(["---"] * columns) + "+\n"
192
-
193
- board = [" "] * (rows * columns)
194
- for pos in state[0].observation.food:
195
- board[pos] = foodSymbol
196
-
197
- for index, goose in enumerate(state[0].observation.geese):
198
- for pos in goose:
199
- board[pos] = index
200
-
201
- out = rowDivider
202
- for row in range(rows):
203
- for col in range(columns):
204
- out += colDivider + f" {board[(row * columns) + col]} "
205
- out += colDivider + "\n" + rowDivider
206
-
207
- return out
208
-
209
-
210
- dirpath = path.dirname(__file__)
211
- jsonpath = path.abspath(path.join(dirpath, "battlegeese.json"))
212
- with open(jsonpath) as f:
213
- specification = json.load(f)
214
-
215
-
216
- def html_renderer():
217
- jspath = path.abspath(path.join(dirpath, "battlegeese.js"))
218
- with open(jspath) as f:
219
- return f.read()
@@ -1,14 +0,0 @@
1
- import time
2
-
3
-
4
- def request(req):
5
- print("request")
6
- time.sleep(2)
7
- req.agents = ["negamax", "random"]
8
- return req
9
-
10
-
11
- def response(req, resp):
12
- print("response")
13
- time.sleep(2)
14
- return resp
@@ -1,393 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: kaggle-environments
3
- Version: 0.2.0
4
- Summary: Kaggle Environments
5
- Home-page: https://github.com/Kaggle/kaggle-environments
6
- Author: Kaggle
7
- Author-email: support@kaggle.com
8
- License: Apache 2.0
9
- Keywords: Kaggle
10
- Platform: UNKNOWN
11
- Requires-Python: >=3.6
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: jsonschema (>=3.0.1)
14
-
15
- # [<img src="https://kaggle.com/static/images/site-logo.png" height="50" style="margin-bottom:-15px" />](https://kaggle.com) Environments
16
-
17
- ```bash
18
- pip install kaggle-environments
19
- ```
20
-
21
- # TLDR;
22
-
23
- ```python
24
- from kaggle_environments import make
25
-
26
- # Setup a tictactoe environment.
27
- env = make("tictactoe")
28
-
29
- # Basic agent which marks the first available cell.
30
- def my_agent(obs):
31
- return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
32
-
33
- # Run the basic agent against a default agent which chooses a "random" move.
34
- env.run([my_agent, "random"])
35
-
36
- # Render an html ipython replay of the tictactoe game.
37
- env.render(mode="ipython")
38
- ```
39
-
40
- # Overview
41
-
42
- Kaggle Environments was created to evaluate episodes. While other libraries have set interface precedents (such as Open.ai Gym), the emphasis of this library focuses on:
43
-
44
- 1. Episode evaluation (compared to training agents).
45
- 2. Configurable environment/agent lifecycles.
46
- 3. Simplified agent and environment creation.
47
- 4. Cross language compatible/transpilable syntax/interfaces.
48
-
49
- ## Help Documentation
50
-
51
- ```python
52
- # Additional documentation (especially interfaces) can be found on all public functions:
53
- from kaggle_environments import make
54
- help(make)
55
- env = make("tictactoe")
56
- dir(env)
57
- help(env.reset)
58
- ```
59
-
60
- # Agents
61
-
62
- > A function which given an observation generates an action.
63
-
64
- ## Writing
65
-
66
- Agent functions can have observation and configuration parameters and must return a valid action. Details about the observation, configuration, and actions can seen by viewing the specification.
67
-
68
- ```python
69
- from kaggle_simulations import make
70
- env = make("connectx", {rows: 10, columns: 8, inarow: 5})
71
-
72
- def agent(observation, configration):
73
- print(observation) # {board: [...], mark: 1}
74
- print(configuration) # {rows: 10, columns: 8, inarow: 5}
75
- return 3 # Action: always place a mark in the 3rd column.
76
-
77
- # Run an episode using the agent above vs the default random agent.
78
- env.run([agent, "random"])
79
-
80
- # Print schemas from the specification.
81
- print(env.specification.observation)
82
- print(env.specification.configuration)
83
- print(env.specification.action)
84
- ```
85
-
86
- ## Loading Agents
87
-
88
- Agents are always functions, however there are some shorthand syntax options to make generating/using them easier.
89
-
90
- ```python
91
- # Agent def accepting an observation and returning an action.
92
- def agent1(obs):
93
- return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
94
-
95
- # Load a default agent called "random".
96
- agent2 = "random"
97
-
98
- # Load an agent from source.
99
- agent3 = """
100
- def act(obs):
101
- return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
102
- """
103
-
104
- # Load an agent from a file.
105
- agent4 = "C:\path\file.py"
106
-
107
- # Return a fixed action.
108
- agent5 = 3
109
-
110
- # Return an action from a url.
111
- agent6 = "http://localhost:8000/run/agent"
112
- ```
113
-
114
- ## Default Agents
115
-
116
- Most environments contain default agents to play against. To see the list of available agents for a specific environment run:
117
-
118
- ```python
119
- from kaggle_simulations import make
120
- env = make("tictactoe")
121
-
122
- # The list of available default agents.
123
- print(*env.agents)
124
-
125
- # Run random agent vs reaction agent.
126
- env.run(["random", "reaction"])
127
- ```
128
-
129
- ## Training
130
-
131
- Open AI Gym interface is used to assist with training agents. The `None` keyword is used below to denote which agent to train (i.e. train as first or second player of connectx).
132
-
133
- ```python
134
- from kaggle_environments import make
135
-
136
- env = make("connectx", debug=True)
137
-
138
- # Training agent in first position (player 1) against the default random agent.
139
- trainer = env.train([None, "random"])
140
-
141
- obs = trainer.reset()
142
- for _ in range(100):
143
- env.render()
144
- action = 0 # Action for the agent being trained.
145
- obs, reward, done, info = trainer.step(action)
146
- if done:
147
- obs = trainer.reset()
148
- ```
149
-
150
- ## Debugging
151
-
152
- There are 3 types of errors which can occur from agent execution:
153
-
154
- 1. **Timeout** - the agent runtime exceeded the allowed limit. There are 2 timeouts:
155
- 1. `agentTimeout` - Used for initialization of an agent on first "act".
156
- 2. `actTimeout` - Used for obtaining an action.
157
- 2. **Error** - the agent raised and error during execution.
158
- 3. **Invalid** - the agent action response didn't match the action specification or the environment deemed it invalid (i.e. playing twice in the same cell in tictactoe).
159
-
160
- To help debug your agent and why it threw the errors above, add the `debug` flag when setting up the environment.
161
-
162
- ```python
163
- from kaggle_simulations import make
164
-
165
- def agent():
166
- return "Something Bad"
167
-
168
- env = make("tictactoe", debug=True)
169
-
170
- env.run([agent, "random"])
171
- # Prints: "Invalid Action: Something Bad"
172
- ```
173
-
174
- # Environments
175
-
176
- > A function which given a state and agent actions generates a new state.
177
-
178
- | Name | Description | Make |
179
- | --------- | ------------------------------------ | ------------------------- |
180
- | connectx | Connect 4 in a row but configurable. | `env = make("connectx")` |
181
- | tictactoe | Classic Tic Tac Toe | `env = make("tictactoe")` |
182
- | identity | For debugging, action is the reward. | `env = make("identity")` |
183
-
184
- ## Making
185
-
186
- An environment instance can be made from an existing specification (such as those listed above).
187
-
188
- ```python
189
- from kaggle_environments import make
190
-
191
- # Create an environment instance.
192
- env = make(
193
- # Specification or name to registered specification.
194
- "connectx",
195
-
196
- # Override default and environment configuration.
197
- configuration={"rows": 9, "columns": 10},
198
-
199
- # Initialize the environment from a prior state (episode resume).
200
- steps=[],
201
-
202
- # Enable verbose logging.
203
- debug=True
204
- )
205
- ```
206
-
207
- ## Configuration
208
-
209
- There are two types of configuration: Defaults applying to every environment and those specific to the environment. The following is a list of the default configuration:
210
-
211
- | Name | Description |
212
- | ------------ | --------------------------------------------------------------- |
213
- | episodeSteps | Maximum number of steps in the episode. |
214
- | agentExec | How the agent is executed alongside the envionment. |
215
- | agentTimeout | Maximum runtime (seconds) to initialize an agent. |
216
- | actTimeout | Maximum runtime (seconds) to obtain an action from an agent. |
217
- | runTimeout | Maximum runtime (seconds) of an episode (not necessarily DONE). |
218
-
219
- ```python
220
- env = make("connectx", configuration={
221
- "columns": 19, # Specific to ConnectX.
222
- "actTimeout": 10,
223
- "agentExec": "LOCAL"
224
- })
225
- ```
226
-
227
- ## Resetting
228
-
229
- Environments are reset by default after "make" (unless starting steps are passed in) as well as when calling "run". Reset can be called at anytime to clear the environment.
230
-
231
- ```python
232
- num_agents = 2
233
- reset_state = env.reset(num_agents)
234
- ```
235
-
236
- ## Running
237
-
238
- Execute an episode against the environment using the passed in agents until they are no longer running (i.e. status != ACTIVE).
239
-
240
- ```python
241
- steps = env.run([agent1, agent2])
242
- print(steps)
243
- ```
244
-
245
- ## Evaluating
246
-
247
- Evaluation is used to run an episode (environment + agents) multiple times and just return the rewards.
248
-
249
- ```python
250
- from kaggle_simulations import evaluate
251
-
252
- # Same definitions as "make" above.
253
- envrionment = "connectx"
254
- configuration = {rows: 10, columns: 8, inarow: 5}
255
- steps = []
256
- debug = False
257
-
258
- # Which agents to run repeatedly. Same as env.run(agents)
259
- agents = ["random", agent1]
260
-
261
- # How many times to run them.
262
- num_episodes = 10
263
-
264
- rewards = evaluate(environment, agents, configuration, steps, num_episodes, debug)
265
- ```
266
-
267
- ## Stepping
268
-
269
- Running above essentially just steps until no agent is still active. To execute a singular game loop, pass in actions directly for each agent. Note that this is normally used for training agents (most useful in a single agent setup such as using the gym interface).
270
-
271
- ```python
272
- agent1_action = agent1(env.state[0].observation)
273
- agent2_action = agent2(env.state[1].observation)
274
- state = env.step(agent1_action, agent2_action)
275
- ```
276
-
277
- ## Playing
278
-
279
- A few environments offer an interactive play against agents within jupyter notebooks. An example of this is using connectx:
280
-
281
- ```python
282
- from kaggle_simulations import make
283
-
284
- env = make("connectx")
285
- # None indicates which agent will be manually played.
286
- env.play([None, "random"])
287
- ```
288
-
289
- ## Rendering
290
-
291
- The following rendering modes are supported:
292
-
293
- - json - Same as doing a json dump of `env.toJSON()`
294
- - ansi - Ascii character representation of the environment.
295
- - human - ansi just printed to stdout
296
- - html - HTML player representation of the environment.
297
- - ipython - html just printed to the output of a ipython notebook.
298
-
299
- ```python
300
- out = env.render(mode="ansi")
301
- print(out)
302
- ```
303
-
304
- # Command Line
305
-
306
- ```sh
307
- > python main.py -h
308
- ```
309
-
310
- ## List Registered Environments
311
-
312
- ```sh
313
- > python main.py list
314
- ```
315
-
316
- ## Evaluate Episode Rewards
317
-
318
- ```sh
319
- python main.py evaluate --environment tictactoe --agents random random --episodes 10
320
- ```
321
-
322
- ## Run an Episode
323
-
324
- ```sh
325
- > python main.py run --environment tictactoe --agents random /pathtomy/agent.py --debug True
326
- ```
327
-
328
- ## Load an Episode
329
-
330
- This is useful when converting an episode json output into html.
331
-
332
- ```sh
333
- python main.py load --environment tictactoe --steps [...] --render '{"mode": "html"}'
334
- ```
335
-
336
- # HTTP Server
337
-
338
- The HTTP server contains the same interface/actions as the CLI above merging both POST body and GET params.
339
-
340
- ## Setup
341
-
342
- ```bash
343
- python main.py http-server --port=8012 --host=0.0.0.0
344
- ```
345
-
346
- ## Adding Middleware
347
-
348
- ```python
349
- # middleware.py
350
- import time
351
-
352
- def request(req):
353
- time.sleep(30)
354
- req.agents = ["random", "random"]
355
- return req
356
-
357
- def response(req, resp):
358
- time.sleep(10)
359
- return resp
360
- ```
361
-
362
- ```bash
363
- python3 main.py http-server --middleware=/path/to/middleware.py
364
- ```
365
-
366
- ### Running Agents on Separate Servers
367
-
368
- ```python
369
- # How to run agent on a separate server.
370
- import requests
371
- import json
372
-
373
- path_to_agent1 = "/home/ajeffries/git/playground/agent1.py"
374
- path_to_agent2 = "/home/ajeffries/git/playground/agent2.py"
375
-
376
- agent1_url = f"http://localhost:5001?agents[]={path_to_agent1}"
377
- agent2_url = f"http://localhost:5002?agents[]={path_to_agent2}"
378
-
379
- body = {
380
- "action": "run",
381
- "environment": "tictactoe",
382
- "agents": [agent1_url, agent2_url]
383
- }
384
- resp = requests.post(url="http://localhost:5000", data=json.dumps(body)).json()
385
-
386
- # Inflate the response replay to visualize.
387
- from kaggle_environments import make
388
- env = make("tictactoe", steps=resp["steps"], debug=True)
389
- env.render(mode="ipython")
390
- print(resp)
391
- ```
392
-
393
-
@@ -1,33 +0,0 @@
1
- kaggle_environments/__init__.py,sha256=bNArFApeAzfg03jpzw0Q0TgP5D_CFqNGiQVuds8n0a0,1329
2
- kaggle_environments/agent.py,sha256=Me52NjPueXq4e8dFcdiLlACRnJX5ppDOoOr1Ec2yTSs,5139
3
- kaggle_environments/core.py,sha256=oGkF_DbBHgC8cgWfG6csgIRoy-Dy82iO6bhGZnn0geI,22873
4
- kaggle_environments/errors.py,sha256=gKgOb2_JcOuBMLw3Ol_NZ4arlsvzBm3xV9fqZN3jeeY,3336
5
- kaggle_environments/main.py,sha256=JQTR9HHOpL1zNj0jUn6p5ppAryEmZ-_bUuWDYiFKvtI,5747
6
- kaggle_environments/schemas.json,sha256=YSHnIhrJ60GjWLminloebVsxQXXINm_Z3Nbew7Wkusc,3070
7
- kaggle_environments/status_codes.json,sha256=6a8HuS_Vth95W0f2fov21QLdRfA3KbizUvjKmJhYtBc,995
8
- kaggle_environments/temp.py,sha256=65fHiopG3pvFMhzh2xukJFqj-1O949m_2LrMow5kFng,208
9
- kaggle_environments/utils.py,sha256=wfeJ4ZZNSA4bOLI0nR383yrcvp2bGvtQPsTfU5jbp5E,6307
10
- kaggle_environments/envs/battlegeese/battlegeese.js,sha256=ZiuDhbn7EXVfrN-rMl3u5TFw9EdujezAVv21ASS5lYc,35551
11
- kaggle_environments/envs/battlegeese/battlegeese.json,sha256=6UOb5vIiSmhO_sCO9KjJ7YCfpKObkzGppAEzBKY_Ejw,2067
12
- kaggle_environments/envs/battlegeese/battlegeese.py,sha256=HukJoUvDh0Lf2XUSrZNGEkohpMAxG088frPpUXeQF8k,6659
13
- kaggle_environments/envs/connectx/connectx.js,sha256=u3zaqpiBfnAaC-fiT3hrNABXRIVTc4mKS3qOjCgNvvc,9227
14
- kaggle_environments/envs/connectx/connectx.json,sha256=mdOj-ED1ld3iIcmK3uAs00xFMbxTdGnHkNhyB1XoJUI,1309
15
- kaggle_environments/envs/connectx/connectx.py,sha256=PeQsALGBUJrUnCvYmc6AE8nIdFFKM5GHs24RrL0-xAU,6928
16
- kaggle_environments/envs/connectx/test_connectx.py,sha256=WzXjuzEUXPRlOd5m_DxpaEqbMZNimjBNOJGsYDYEjHM,6267
17
- kaggle_environments/envs/halite/halite.js,sha256=VQdl4Llro4Mp0bWQwIb6Aj887Yuou9nW1qSfqK136ek,14672
18
- kaggle_environments/envs/halite/halite.json,sha256=Pd2WPtmEpS7UMYVI-FtIddHrDPTFV9L1R603ViXowaA,3795
19
- kaggle_environments/envs/halite/halite.py,sha256=GtXAV0le5uSaWSh7LqVlROoL8qJqVba6wcUUuOY46sg,15943
20
- kaggle_environments/envs/halite/test_halite.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- kaggle_environments/envs/identity/identity.json,sha256=l5M7GnhhEyeOphXU0nS5VoZuIOrzrL9H6rz3lsR3fFk,947
22
- kaggle_environments/envs/identity/identity.py,sha256=SEeei1cDG-brC29cLwlOPWYFTWUzmr7uVWLQsqPuiR4,1829
23
- kaggle_environments/envs/tictactoe/test_tictactoe.py,sha256=PMd6lT1ETNgf4f23teZ6QJ2mJpH9kL1nKyiE8lH-3i8,7770
24
- kaggle_environments/envs/tictactoe/tictactoe.js,sha256=NZDT-oSG0a6a-rso9Ldh9qkJwVrxrAsjKUC3_tJu3tw,8002
25
- kaggle_environments/envs/tictactoe/tictactoe.json,sha256=7OAnLZuLfGzQJa_ZWomAh151KS0qwax4XtU6lFQc0rA,859
26
- kaggle_environments/envs/tictactoe/tictactoe.py,sha256=iLNU5V-lz7Xab-d1vpPMfU5jDM3QtgBUH63Y_SU7I9Y,3639
27
- kaggle_environments/static/player.html,sha256=Hs_SacmEIkXdcuz8eCnZr-UHkjMqvPHcNTJtg0ESRkU,21633
28
- kaggle_environments-0.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
29
- kaggle_environments-0.2.0.dist-info/METADATA,sha256=_YMAtJCB5nlDcnhX4bR30_atCMr2dCCyQrzULNYQSq4,10685
30
- kaggle_environments-0.2.0.dist-info/WHEEL,sha256=p46_5Uhzqz6AzeSosiOnxK-zmFja1i22CrQCjmYe8ec,92
31
- kaggle_environments-0.2.0.dist-info/entry_points.txt,sha256=SblqSc9cehdfGIc8QMCJU9vE4oxe7rBctjpm8f9rONw,71
32
- kaggle_environments-0.2.0.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
33
- kaggle_environments-0.2.0.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- kaggle-environments = kaggle_environments.main:main
3
-
@@ -1 +0,0 @@
1
- kaggle_environments