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
@@ -0,0 +1,154 @@
1
+ from typing import Dict
2
+
3
+ from .constants import Constants
4
+ from .game_constants import GAME_CONSTANTS
5
+ from .game_map import Position
6
+
7
+ UNIT_TYPES = Constants.UNIT_TYPES
8
+
9
+
10
+ class Player:
11
+ def __init__(self, team):
12
+ self.team = team
13
+ self.research_points = 0
14
+ self.units: list[Unit] = []
15
+ self.cities: Dict[str, City] = {}
16
+ self.city_tile_count = 0
17
+
18
+ def researched_coal(self) -> bool:
19
+ return self.research_points >= GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["COAL"]
20
+
21
+ def researched_uranium(self) -> bool:
22
+ return self.research_points >= GAME_CONSTANTS["PARAMETERS"]["RESEARCH_REQUIREMENTS"]["URANIUM"]
23
+
24
+
25
+ class City:
26
+ def __init__(self, teamid, cityid, fuel, light_upkeep):
27
+ self.cityid = cityid
28
+ self.team = teamid
29
+ self.fuel = fuel
30
+ self.citytiles: list[CityTile] = []
31
+ self.light_upkeep = light_upkeep
32
+
33
+ def _add_city_tile(self, x, y, cooldown):
34
+ ct = CityTile(self.team, self.cityid, x, y, cooldown)
35
+ self.citytiles.append(ct)
36
+ return ct
37
+
38
+ def get_light_upkeep(self):
39
+ return self.light_upkeep
40
+
41
+
42
+ class CityTile:
43
+ def __init__(self, teamid, cityid, x, y, cooldown):
44
+ self.cityid = cityid
45
+ self.team = teamid
46
+ self.pos = Position(x, y)
47
+ self.cooldown = cooldown
48
+
49
+ def can_act(self) -> bool:
50
+ """
51
+ Whether or not this unit can research or build
52
+ """
53
+ return self.cooldown < 1
54
+
55
+ def research(self) -> str:
56
+ """
57
+ returns command to ask this tile to research this turn
58
+ """
59
+ return "r {} {}".format(self.pos.x, self.pos.y)
60
+
61
+ def build_worker(self) -> str:
62
+ """
63
+ returns command to ask this tile to build a worker this turn
64
+ """
65
+ return "bw {} {}".format(self.pos.x, self.pos.y)
66
+
67
+ def build_cart(self) -> str:
68
+ """
69
+ returns command to ask this tile to build a cart this turn
70
+ """
71
+ return "bc {} {}".format(self.pos.x, self.pos.y)
72
+
73
+
74
+ class Cargo:
75
+ def __init__(self):
76
+ self.wood = 0
77
+ self.coal = 0
78
+ self.uranium = 0
79
+
80
+ def __str__(self) -> str:
81
+ return f"Cargo | Wood: {self.wood}, Coal: {self.coal}, Uranium: {self.uranium}"
82
+
83
+
84
+ class Unit:
85
+ def __init__(self, teamid, u_type, unitid, x, y, cooldown, wood, coal, uranium):
86
+ self.pos = Position(x, y)
87
+ self.team = teamid
88
+ self.id = unitid
89
+ self.type = u_type
90
+ self.cooldown = cooldown
91
+ self.cargo = Cargo()
92
+ self.cargo.wood = wood
93
+ self.cargo.coal = coal
94
+ self.cargo.uranium = uranium
95
+
96
+ def is_worker(self) -> bool:
97
+ return self.type == UNIT_TYPES.WORKER
98
+
99
+ def is_cart(self) -> bool:
100
+ return self.type == UNIT_TYPES.CART
101
+
102
+ def get_cargo_space_left(self):
103
+ """
104
+ get cargo space left in this unit
105
+ """
106
+ spaceused = self.cargo.wood + self.cargo.coal + self.cargo.uranium
107
+ if self.type == UNIT_TYPES.WORKER:
108
+ return GAME_CONSTANTS["PARAMETERS"]["RESOURCE_CAPACITY"]["WORKER"] - spaceused
109
+ else:
110
+ return GAME_CONSTANTS["PARAMETERS"]["RESOURCE_CAPACITY"]["CART"] - spaceused
111
+
112
+ def can_build(self, game_map) -> bool:
113
+ """
114
+ whether or not the unit can build where it is right now
115
+ """
116
+ cell = game_map.get_cell_by_pos(self.pos)
117
+ if (
118
+ not cell.has_resource()
119
+ and self.can_act()
120
+ and (self.cargo.wood + self.cargo.coal + self.cargo.uranium)
121
+ >= GAME_CONSTANTS["PARAMETERS"]["CITY_BUILD_COST"]
122
+ ):
123
+ return True
124
+ return False
125
+
126
+ def can_act(self) -> bool:
127
+ """
128
+ whether or not the unit can move or not. This does not check for potential collisions into other units or enemy cities
129
+ """
130
+ return self.cooldown < 1
131
+
132
+ def move(self, dir) -> str:
133
+ """
134
+ return the command to move unit in the given direction
135
+ """
136
+ return "m {} {}".format(self.id, dir)
137
+
138
+ def transfer(self, dest_id, resourceType, amount) -> str:
139
+ """
140
+ return the command to transfer a resource from a source unit to a destination unit as specified by their ids
141
+ """
142
+ return "t {} {} {} {}".format(self.id, dest_id, resourceType, amount)
143
+
144
+ def build_city(self) -> str:
145
+ """
146
+ return the command to build a city right under the worker
147
+ """
148
+ return "bcity {}".format(self.id)
149
+
150
+ def pillage(self) -> str:
151
+ """
152
+ return the command to pillage whatever is underneath the worker
153
+ """
154
+ return "p {}".format(self.id)
@@ -0,0 +1,38 @@
1
+ import random
2
+
3
+ if __package__ == "":
4
+ # for kaggle-environments
5
+ from lux.constants import Constants
6
+ from lux.game import Game
7
+ else:
8
+ # for CLI tool
9
+ from .lux.constants import Constants
10
+ from .lux.game import Game
11
+ DIRECTIONS = Constants.DIRECTIONS
12
+ game_state = None
13
+
14
+
15
+ def random_agent(observation, configuration):
16
+ """
17
+ a blank, completely empty agent, usually incapable of surviving past the first night
18
+ """
19
+ global game_state
20
+
21
+ ### Do not edit ###
22
+ if observation["step"] == 0:
23
+ game_state = Game()
24
+ game_state._initialize(observation["updates"])
25
+ game_state._update(observation["updates"][2:])
26
+ else:
27
+ game_state._update(observation["updates"])
28
+
29
+ actions = []
30
+
31
+ ### AI Code goes down here! ###
32
+ player = game_state.players[observation.player]
33
+ for unit in player.units:
34
+ dirs = [DIRECTIONS.NORTH, DIRECTIONS.WEST, DIRECTIONS.EAST, DIRECTIONS.SOUTH]
35
+ action = unit.move(random.choice(dirs))
36
+ actions.append(action)
37
+
38
+ return actions
@@ -0,0 +1,82 @@
1
+ import math
2
+
3
+ if __package__ == "":
4
+ # for kaggle-environments
5
+ from lux.constants import Constants
6
+ from lux.game import Game
7
+ from lux.game_map import Cell
8
+ else:
9
+ # for CLI tool
10
+ from .lux.constants import Constants
11
+ from .lux.game import Game
12
+ from .lux.game_map import Cell
13
+
14
+ DIRECTIONS = Constants.DIRECTIONS
15
+ game_state = None
16
+
17
+
18
+ def agent(observation, configuration):
19
+ global game_state
20
+
21
+ ### Do not edit ###
22
+ if observation["step"] == 0:
23
+ game_state = Game()
24
+ game_state._initialize(observation["updates"])
25
+ game_state._update(observation["updates"][2:])
26
+ else:
27
+ game_state._update(observation["updates"])
28
+
29
+ actions = []
30
+
31
+ ### AI Code goes down here! ###
32
+ player = game_state.players[observation.player]
33
+ opponent = game_state.players[(observation.player + 1) % 2]
34
+ width, height = game_state.map.width, game_state.map.height
35
+
36
+ resource_tiles: list[Cell] = []
37
+ for y in range(height):
38
+ for x in range(width):
39
+ cell = game_state.map.get_cell(x, y)
40
+ if cell.has_resource():
41
+ resource_tiles.append(cell)
42
+
43
+ # we iterate over all our units and do something with them
44
+ for unit in player.units:
45
+ if unit.is_worker() and unit.can_act():
46
+ closest_dist = math.inf
47
+ closest_resource_tile = None
48
+ if unit.get_cargo_space_left() > 0:
49
+ # if the unit is a worker and we have space in cargo, lets find the nearest resource tile and try to mine it
50
+ for resource_tile in resource_tiles:
51
+ if resource_tile.resource.type == Constants.RESOURCE_TYPES.COAL and not player.researched_coal():
52
+ continue
53
+ if (
54
+ resource_tile.resource.type == Constants.RESOURCE_TYPES.URANIUM
55
+ and not player.researched_uranium()
56
+ ):
57
+ continue
58
+ dist = resource_tile.pos.distance_to(unit.pos)
59
+ if dist < closest_dist:
60
+ closest_dist = dist
61
+ closest_resource_tile = resource_tile
62
+ if closest_resource_tile is not None:
63
+ actions.append(unit.move(unit.pos.direction_to(closest_resource_tile.pos)))
64
+ else:
65
+ # if unit is a worker and there is no cargo space left, and we have cities, lets return to them
66
+ if len(player.cities) > 0:
67
+ closest_dist = math.inf
68
+ closest_city_tile = None
69
+ for k, city in player.cities.items():
70
+ for city_tile in city.citytiles:
71
+ dist = city_tile.pos.distance_to(unit.pos)
72
+ if dist < closest_dist:
73
+ closest_dist = dist
74
+ closest_city_tile = city_tile
75
+ if closest_city_tile is not None:
76
+ move_dir = unit.pos.direction_to(closest_city_tile.pos)
77
+ actions.append(unit.move(move_dir))
78
+
79
+ # you can add debug annotations using the functions in the annotate object
80
+ # actions.append(annotate.circle(0, 0))
81
+
82
+ return actions
@@ -0,0 +1,19 @@
1
+ from kaggle_environments import make
2
+
3
+ from .agents import js_simple_agent, random_agent, simple_agent
4
+
5
+
6
+ def test_lux_completes():
7
+ env = make("lux_ai_2021", configuration={})
8
+ env.run([random_agent, simple_agent])
9
+ json = env.toJSON()
10
+ assert json["name"] == "lux_ai_2021"
11
+ assert json["statuses"] == ["DONE", "DONE"]
12
+
13
+
14
+ def test_js_agents():
15
+ env = make("lux_ai_2021", configuration={})
16
+ env.run([simple_agent, js_simple_agent])
17
+ json = env.toJSON()
18
+ assert json["name"] == "lux_ai_2021"
19
+ assert json["statuses"] == ["DONE", "DONE"]
@@ -0,0 +1,23 @@
1
+ Unfortunately at this moment, there isn't a progammatic way to test if the Kaggle Engine is the exact same as the engine competitors use when local testing. This is part of a TODO to make kaggle replays match the local replays players generate when they develop locally using https://github.com/Lux-AI-Challenge/Lux-Design-2021
2
+
3
+ The following steps work for now:
4
+
5
+ First download the simple kit from https://github.com/Lux-AI-Challenge/Lux-Design-2021/tree/master/kits/python (or another language) or use your own bot
6
+
7
+ First run a game in Kaggle like so:
8
+
9
+ ```
10
+ kaggle-environments run --environment lux_ai_2021 --agents path/to/bot/main.py path/to/bot/main.py --render '{"mode": "json"}' --out out.json --debug=True
11
+ ```
12
+
13
+ Then upload the out.json to https://2021vis.lux-ai.org/ and go to the final turn.
14
+
15
+ Then install the local engine `npm i -g install @lux-ai/2021-challenge` if you haven't done so already (you can remove `-g` and do `npx lux-ai-2021` as opposed to `lux-ai-2021`)
16
+
17
+ Then run
18
+
19
+ ```
20
+ lux-ai-2021 path/to/bot/main.py path/to/bot/main.py --out=replay.json
21
+ ```
22
+
23
+ upload `replay.json` to the replay viewer again in a new tab and compare the final state with the other kaggle produced match. If the statistics and layout of units on the map match, then the engine is working correctly. (Given the complexity of the game and that `lux-ai-2021` generates action based replays, should a single thing be wrong, the differences in the final turn would be fairly massive so this is generally a sufficient test)
@@ -0,0 +1,18 @@
1
+ # TODOs
2
+
3
+
4
+ [x] Setup Visualizer
5
+
6
+ [x] Keep dimensions engine results consistent with kaggle-env integated version
7
+
8
+ [ ] Verify rewards work correctly
9
+
10
+ [ ] display correct agent names
11
+
12
+ [ ] default turn debug mode off
13
+
14
+ [ ] add tests for more bots
15
+
16
+ [ ] allow user to pass in custom configurations
17
+
18
+ [ ] allow user to specify debug mode level for the dimensions engine
@@ -0,0 +1,21 @@
1
+ # Lux AI Challenge Season 3
2
+
3
+ Welcome to the Kaggle Environments wrapped around the Lux AI Challenge Season 3! For more information or if you have an issues or want to make contributes, check out the main repository at https://github.com/Lux-AI-Challenge/Lux-Design-S3
4
+
5
+ ## Test scripts
6
+
7
+ ```
8
+ kaggle-environments run --environment lux_ai_s3 --agents path/to/bot/main.py path/to/bot/main.py --render '{"mode": "json"}' --out out.json --debug=True
9
+ ```
10
+
11
+ ```
12
+ kaggle-environments run --environment lux_ai_s3 --agents ../LuxAI/Lux-Design-S3/kits/python/main.py ../LuxAI/Lux-Design-S3/kits/python/main.py --render '{"mode": "json"}' --out out.json --debug=True
13
+ ```
14
+ <!--
15
+ ## Packaging external packages locally
16
+
17
+ git clone open_simplex and petting zoo directly and move them into here -->
18
+
19
+ ## Visualizer
20
+
21
+ Ensure that the script module is at the bottom of <body> tag.
@@ -0,0 +1,5 @@
1
+ from .test_agents.python.main import agent_fn as random_agent
2
+
3
+ all_agents = {
4
+ "random_agent": random_agent,
5
+ }
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="https://s3vis.lux-ai.org/eye.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+
8
+ <title>Lux Eye S3</title>
9
+
10
+ <!-- Start Single Page Apps for GitHub Pages -->
11
+ <script type="text/javascript">
12
+ // Single Page Apps for GitHub Pages
13
+ // MIT License
14
+ // https://github.com/rafgraph/spa-github-pages
15
+ // This script checks to see if a redirect is present in the query string,
16
+ // converts it back into the correct url and adds it to the
17
+ // browser's history using window.history.replaceState(...),
18
+ // which won't cause the browser to attempt to load the new url.
19
+ // When the single page app is loaded further down in this file,
20
+ // the correct url will be waiting in the browser's history for
21
+ // the single page app to route accordingly.
22
+ (function (l) {
23
+ if (l.search[1] === '/') {
24
+ const decoded = l.search
25
+ .slice(1)
26
+ .split('&')
27
+ .map(function (s) {
28
+ return s.replace(/~and~/g, '&');
29
+ })
30
+ .join('?');
31
+ window.history.replaceState(null, null, l.pathname.slice(0, -1) + decoded + l.hash);
32
+ }
33
+ })(window.location);
34
+ </script>
35
+ <!-- End Single Page Apps for GitHub Pages -->
36
+ <script type="module" crossorigin src="https://s3vis.lux-ai.org/index.js"></script>
37
+ </head>
38
+ <body>
39
+ <div id="root"></div>
40
+
41
+ </body>
42
+ </html>
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "lux_ai_s3",
3
+ "title": "Lux AI Challenge Season 3",
4
+ "description": "A Novel AI Programming Challenge about Lux",
5
+ "version": "0.0.1",
6
+ "agents": [2],
7
+ "configuration": {
8
+ "episodeSteps": 506,
9
+ "seed": {
10
+ "description": "Seed to use for episodes",
11
+ "type": "integer"
12
+ },
13
+ "actTimeout": 3,
14
+ "runTimeout": 1600,
15
+ "env_cfg": {
16
+ "description": "Environment configuration. Not to be filled out by user as it is randomly generated.",
17
+ "type": "object"
18
+ }
19
+ },
20
+ "reward": {
21
+ "description": "Reward of the agent. Equal to number of games won.",
22
+ "type": "integer",
23
+ "default": 0
24
+ },
25
+ "observation": {
26
+ "remainingOverageTime": 60,
27
+ "reward": {
28
+ "description": "Current reward of the agent. Equal to amount of lichen grown.",
29
+ "type": "integer",
30
+ "default": 0
31
+ },
32
+ "obs": {
33
+ "description": "String containing the observations",
34
+ "type": "string",
35
+ "shared": false
36
+ },
37
+ "player": {
38
+ "description": "Current player's index / team id",
39
+ "type": "string",
40
+ "defaults": "player_0"
41
+ }
42
+ },
43
+ "action": {
44
+ "description": "Actions",
45
+ "type": "object"
46
+ }
47
+ }
@@ -0,0 +1,178 @@
1
+ import json
2
+ import math
3
+ import random
4
+ from os import path
5
+ from os import path as osp
6
+ from sys import path as syspath
7
+
8
+ from .agents import all_agents
9
+
10
+ # next two lines enables importing local packages e.g. luxai_s3
11
+ __dir__ = osp.dirname(__file__)
12
+ syspath.append(__dir__)
13
+ import numpy as np
14
+
15
+
16
+ def to_json(state):
17
+ if isinstance(state, np.ndarray):
18
+ return state.tolist()
19
+ elif isinstance(state, np.int64):
20
+ return state.tolist()
21
+ elif isinstance(state, list):
22
+ return [to_json(s) for s in state]
23
+ elif isinstance(state, dict):
24
+ out = {}
25
+ for k in state:
26
+ out[k] = to_json(state[k])
27
+ return out
28
+ else:
29
+ return state
30
+
31
+
32
+ prev_step = 0
33
+ luxenv = None
34
+ prev_obs = None
35
+ state_obs = None
36
+ default_env_cfg = None
37
+
38
+
39
+ def enqueue_output(out, queue):
40
+ for line in iter(out.readline, b""):
41
+ queue.put(line)
42
+ out.close()
43
+
44
+
45
+ def interpreter(state, env):
46
+ try:
47
+ from luxai_s3.wrappers import LuxAIS3GymEnv, RecordEpisode
48
+
49
+ global luxenv, prev_obs, state_obs, default_env_cfg
50
+ player_0 = state[0]
51
+ player_1 = state[1]
52
+ # filter out actions such as debug annotations so they aren't saved
53
+ # filter_actions(state, env)
54
+
55
+ if env.done:
56
+ if "seed" in env.configuration:
57
+ seed = int(env.configuration["seed"])
58
+ else:
59
+ seed = math.floor(random.random() * 1e9)
60
+ env.configuration["seed"] = seed
61
+
62
+ luxenv = LuxAIS3GymEnv(numpy_output=True)
63
+ luxenv = RecordEpisode(luxenv, save_on_close=False, save_on_reset=False)
64
+ obs, info = luxenv.reset(seed=seed)
65
+
66
+ env_cfg_json = info["params"]
67
+
68
+ env.configuration.env_cfg = env_cfg_json
69
+
70
+ player_0.observation.player = "player_0"
71
+ player_1.observation.player = "player_1"
72
+ player_0.observation.obs = json.dumps(to_json(obs["player_0"]))
73
+ player_1.observation.obs = json.dumps(to_json(obs["player_1"]))
74
+
75
+ replay_frame = luxenv.serialize_episode_data(
76
+ dict(
77
+ states=[luxenv.episode["states"][-1]],
78
+ metadata=luxenv.episode["metadata"],
79
+ params=luxenv.episode["params"],
80
+ )
81
+ )
82
+ # don't need to keep metadata/params beyond first step
83
+ player_0.info = dict(replay=replay_frame)
84
+ return state
85
+
86
+ # validate actions
87
+ player_0_valid_action = True
88
+ player_1_valid_action = True
89
+
90
+ def validate_action(action):
91
+ valid = True
92
+ if action.shape != (luxenv.action_space["player_0"].shape):
93
+ valid = False
94
+ return valid
95
+
96
+ try:
97
+ player_0_action = np.array(player_0.action["action"])
98
+ assert validate_action(player_0_action)
99
+ except:
100
+ player_0_valid_action = False
101
+ player_0_action = luxenv.action_space.sample()["player_0"] * 0
102
+
103
+ try:
104
+ player_1_action = np.array(player_1.action["action"])
105
+ assert validate_action(player_1_action)
106
+ except:
107
+ player_1_valid_action = False
108
+ player_1_action = luxenv.action_space.sample()["player_1"] * 0
109
+
110
+ new_state_obs, rewards, terminations, truncations, infos = luxenv.step(
111
+ {"player_0": player_0_action, "player_1": player_1_action}
112
+ )
113
+
114
+ # cannot store np arrays in replay jsons so must convert to list
115
+ player_0.action = player_0_action.tolist()
116
+ player_1.action = player_1_action.tolist()
117
+
118
+ dones = dict()
119
+ for k in terminations:
120
+ dones[k] = terminations[k] | truncations[k]
121
+
122
+ player_0.observation.player = "player_0"
123
+ player_1.observation.player = "player_1"
124
+
125
+ player_0.observation.obs = json.dumps(to_json(new_state_obs["player_0"]))
126
+ player_1.observation.obs = json.dumps(to_json(new_state_obs["player_1"]))
127
+
128
+ player_0.reward = int(rewards["player_0"])
129
+ player_1.reward = int(rewards["player_1"])
130
+
131
+ player_0.observation.reward = int(player_0.reward)
132
+ player_1.observation.reward = int(player_1.reward)
133
+ replay_frame = luxenv.serialize_episode_data(
134
+ dict(
135
+ states=[luxenv.episode["states"][-1]],
136
+ actions=[luxenv.episode["actions"][-1]],
137
+ metadata=luxenv.episode["metadata"],
138
+ params=luxenv.episode["params"],
139
+ )
140
+ )
141
+ # don't need to keep metadata/params beyond first step
142
+ del replay_frame["metadata"]
143
+ del replay_frame["params"]
144
+ player_0.info = dict(replay=replay_frame)
145
+
146
+ if np.all([dones[k] for k in dones]):
147
+ if player_0.status == "ACTIVE":
148
+ player_0.status = "DONE"
149
+ if player_1.status == "ACTIVE":
150
+ player_1.status = "DONE"
151
+ # if player submits invalid action we need to mark the game as failed.
152
+ if not player_0_valid_action:
153
+ player_0.status = "ERROR"
154
+ if not player_1_valid_action:
155
+ player_1.status = "ERROR"
156
+ return state
157
+ except ModuleNotFoundError as e:
158
+ print(e)
159
+ print("Lux AI S3 Dependencies are missing, interpreter will not work")
160
+ return state
161
+
162
+
163
+ def renderer(state, env):
164
+ raise NotImplementedError("To render the replay, please set the render mode to json or html")
165
+
166
+
167
+ dir_path = path.dirname(__file__)
168
+ json_path = path.abspath(path.join(dir_path, "lux_ai_s3.json"))
169
+ with open(json_path) as json_file:
170
+ specification = json.load(json_file)
171
+
172
+
173
+ def html_renderer():
174
+ html_path = path.abspath(path.join(dir_path, "index.html"))
175
+ return ("html_path", html_path)
176
+
177
+
178
+ agents = all_agents
@@ -0,0 +1 @@
1
+ from .env import LuxAIS3Env