kaggle-environments 0.2.1__py3-none-any.whl → 1.20.1__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 (214) 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 +295 -170
  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} +21 -14
  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 +340 -0
  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-0.2.1.dist-info → kaggle_environments-1.20.1.dist-info}/METADATA +36 -114
  206. kaggle_environments-1.20.1.dist-info/RECORD +211 -0
  207. {kaggle_environments-0.2.1.dist-info → kaggle_environments-1.20.1.dist-info}/WHEEL +1 -2
  208. kaggle_environments-1.20.1.dist-info/entry_points.txt +3 -0
  209. kaggle_environments/envs/battlegeese/battlegeese.py +0 -223
  210. kaggle_environments/temp.py +0 -14
  211. kaggle_environments-0.2.1.dist-info/RECORD +0 -32
  212. kaggle_environments-0.2.1.dist-info/entry_points.txt +0 -3
  213. kaggle_environments-0.2.1.dist-info/top_level.txt +0 -1
  214. {kaggle_environments-0.2.1.dist-info → kaggle_environments-1.20.1.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,169 @@
1
+ import {Point} from "./Point";
2
+
3
+ export class Direction extends Point {
4
+
5
+ public static readonly NORTH = new Direction(0, 1);
6
+ public static readonly EAST = new Direction(1, 0);
7
+ public static readonly SOUTH = new Direction(0, -1);
8
+ public static readonly WEST = new Direction(-1, 0);
9
+
10
+ private constructor(x: number, y: number) {
11
+ super(x, y);
12
+ }
13
+
14
+ public equals(other: Direction): boolean {
15
+ return this.x == other.x && this.y == other.y;
16
+ }
17
+
18
+ public rotateLeft(): Direction {
19
+ if (this.equals(Direction.NORTH)) {
20
+ return Direction.WEST;
21
+ }
22
+ if (this.equals(Direction.WEST)) {
23
+ return Direction.SOUTH;
24
+ }
25
+ if (this.equals(Direction.SOUTH)) {
26
+ return Direction.EAST;
27
+ }
28
+ if (this.equals(Direction.EAST)) {
29
+ return Direction.NORTH;
30
+ }
31
+ throw new Error("invalid direction");
32
+ }
33
+
34
+ public rotateRight(): Direction {
35
+ if (this.equals(Direction.NORTH)) {
36
+ return Direction.EAST;
37
+ }
38
+ if (this.equals(Direction.EAST)) {
39
+ return Direction.SOUTH;
40
+ }
41
+ if (this.equals(Direction.SOUTH)) {
42
+ return Direction.WEST;
43
+ }
44
+ if (this.equals(Direction.WEST)) {
45
+ return Direction.NORTH;
46
+ }
47
+ throw new Error("invalid direction");
48
+ }
49
+
50
+ public opposite(): Direction {
51
+ if (this.equals(Direction.NORTH)) {
52
+ return Direction.SOUTH;
53
+ }
54
+ if (this.equals(Direction.EAST)) {
55
+ return Direction.WEST;
56
+ }
57
+ if (this.equals(Direction.SOUTH)) {
58
+ return Direction.NORTH;
59
+ }
60
+ if (this.equals(Direction.WEST)) {
61
+ return Direction.EAST;
62
+ }
63
+ throw new Error("invalid direction");
64
+ }
65
+
66
+ public toChar(): string {
67
+ if (this.equals(Direction.NORTH)) {
68
+ return "N";
69
+ }
70
+ if (this.equals(Direction.EAST)) {
71
+ return "E";
72
+ }
73
+ if (this.equals(Direction.SOUTH)) {
74
+ return "S";
75
+ }
76
+ if (this.equals(Direction.WEST)) {
77
+ return "W";
78
+ }
79
+ throw new Error("invalid direction");
80
+ }
81
+
82
+ public toString(): string {
83
+ if (this.equals(Direction.NORTH)) {
84
+ return "NORTH";
85
+ }
86
+ if (this.equals(Direction.EAST)) {
87
+ return "EAST";
88
+ }
89
+ if (this.equals(Direction.SOUTH)) {
90
+ return "SOUTH";
91
+ }
92
+ if (this.equals(Direction.WEST)) {
93
+ return "WEST";
94
+ }
95
+ throw new Error("invalid direction");
96
+ }
97
+
98
+ public toIndex(): number {
99
+ if (this.equals(Direction.NORTH)) {
100
+ return 0;
101
+ }
102
+ if (this.equals(Direction.EAST)) {
103
+ return 1;
104
+ }
105
+ if (this.equals(Direction.SOUTH)) {
106
+ return 2;
107
+ }
108
+ if (this.equals(Direction.WEST)) {
109
+ return 3;
110
+ }
111
+ throw new Error("invalid direction");
112
+ }
113
+
114
+ public static fromString(dirStr: string): Direction {
115
+ switch(dirStr) {
116
+ case "NORTH":
117
+ return Direction.NORTH;
118
+ case "EAST":
119
+ return Direction.EAST;
120
+ case "SOUTH":
121
+ return Direction.SOUTH;
122
+ case "WEST":
123
+ return Direction.WEST;
124
+ }
125
+ throw new Error("invalid direction");
126
+ }
127
+
128
+ public static fromChar(dirChar: string): Direction {
129
+ switch(dirChar) {
130
+ case 'N':
131
+ return Direction.NORTH;
132
+ case 'E':
133
+ return Direction.EAST;
134
+ case 'S':
135
+ return Direction.SOUTH;
136
+ case 'W':
137
+ return Direction.WEST;
138
+ }
139
+ throw new Error("invalid direction");
140
+ }
141
+
142
+ public static fromIndex(index: number): Direction {
143
+ switch(index) {
144
+ case 0:
145
+ return Direction.NORTH;
146
+ case 1:
147
+ return Direction.EAST;
148
+ case 2:
149
+ return Direction.SOUTH;
150
+ case 3:
151
+ return Direction.WEST;
152
+ }
153
+ throw new Error("invalid direction");
154
+ }
155
+
156
+ public static randomDirection(): Direction {
157
+ return Direction.fromIndex(Math.floor(Math.random() * 4));
158
+ }
159
+
160
+ public static listDirections(): Direction[] {
161
+ return [
162
+ Direction.NORTH,
163
+ Direction.EAST,
164
+ Direction.SOUTH,
165
+ Direction.WEST
166
+ ];
167
+ }
168
+
169
+ }
@@ -0,0 +1,76 @@
1
+ import {Board} from "./Board";
2
+ import {Cell} from "./Cell";
3
+ import {Direction} from "./Direction";
4
+ import {Player} from "./Player";
5
+ import {Point} from "./Point";
6
+
7
+ export class Fleet {
8
+
9
+ public readonly id: string;
10
+ public shipCount: number;
11
+ public direction: Direction;
12
+ public position: Point;
13
+ public flightPlan: string;
14
+ public kore: number;
15
+ public readonly playerId: number;
16
+ public readonly board: Board;
17
+
18
+ public constructor(fleetId: string, shipCount: number, direction: Direction, position: Point, kore: number, flightPlan: string, playerId: number, board: Board) {
19
+ this.id = fleetId;
20
+ this.shipCount = shipCount;
21
+ this.direction = direction;
22
+ this.position = position;
23
+ this.flightPlan = flightPlan;
24
+ this.kore = kore;
25
+ this.playerId = playerId;
26
+ this.board = board;
27
+ }
28
+
29
+ public cloneToBoard(board: Board): Fleet {
30
+ return new Fleet(this.id, this.shipCount, this.direction, this.position, this.kore, this.flightPlan, this.playerId, board);
31
+ }
32
+
33
+ public get cell(): Cell {
34
+ return this.board.getCellAtPosition(this.position);
35
+ }
36
+
37
+ public get player(): Player {
38
+ return this.board.players[this.playerId];
39
+ }
40
+
41
+ public get collectionRate(): number {
42
+ return Math.min(Math.log(this.shipCount) / 10, .99);
43
+ }
44
+
45
+ /**
46
+ * Returns the length of the longest possible flight plan this fleet can be assigned
47
+ * @return
48
+ */
49
+ public static maxFlightPlanLenForShipCount(shipCount: number): number {
50
+ return (Math.floor(2 * Math.log(shipCount)) + 1);
51
+ }
52
+
53
+ /**
54
+ * Converts a fleet back to the normalized observation subset that constructed it.
55
+ */
56
+ public observation(): string[] {
57
+ return [
58
+ this.position.toIndex(this.board.configuration.size).toString(),
59
+ this.kore.toString(),
60
+ this.shipCount.toString(),
61
+ this.direction.toIndex().toString(),
62
+ this.flightPlan
63
+ ];
64
+ }
65
+
66
+ public lessThanOtherAlliedFleet(other: Fleet): boolean {
67
+ if (this.shipCount != other.shipCount) {
68
+ return this.shipCount < other.shipCount;
69
+ }
70
+ if (this.kore != other.kore) {
71
+ return this.kore < other.kore;
72
+ }
73
+ return this.direction.toIndex() > other.direction.toIndex();
74
+ }
75
+
76
+ }
@@ -0,0 +1,70 @@
1
+ import readline from 'readline';
2
+ import { Board } from './Board';
3
+ import { ShipyardAction } from './ShipyardAction';
4
+
5
+ export class KoreIO {
6
+ public getLine: () => Promise<string>;
7
+
8
+ public _setup(): void {
9
+ // Prepare to read input
10
+ const rl = readline.createInterface({
11
+ input: process.stdin,
12
+ output: null,
13
+ });
14
+
15
+ const buffer = [];
16
+ let currentResolve: () => void;
17
+ let currentPromise;
18
+ const makePromise = function () {
19
+ return new Promise<void>((resolve) => {
20
+ currentResolve = resolve;
21
+ });
22
+ };
23
+ // on each line, push line to buffer
24
+ rl.on('line', (line) => {
25
+ buffer.push(line);
26
+ currentResolve();
27
+ currentPromise = makePromise();
28
+ });
29
+ // The current promise for retrieving the next line
30
+ currentPromise = makePromise();
31
+
32
+ // with await, we pause process until there is input
33
+ this.getLine = async () => {
34
+ return new Promise(async (resolve) => {
35
+ while (buffer.length === 0) {
36
+ // pause while buffer is empty, continue if new line read
37
+ await currentPromise;
38
+ }
39
+ // once buffer is not empty, resolve the most recent line in stdin, and remove it
40
+ resolve(buffer.shift());
41
+ });
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Constructor for a new agent
47
+ * User should edit this according to the `Design` this agent will compete under
48
+ */
49
+ public constructor() {
50
+ this._setup(); // DO NOT REMOVE
51
+ }
52
+
53
+ public async run(loop: (board: Board) => Promise<Board>): Promise<void> {
54
+ while (true) {
55
+ const rawObservation = await this.getLine();
56
+ const rawConfiguration = await this.getLine();
57
+ const board = Board.fromRaw(rawObservation, rawConfiguration);
58
+ try {
59
+ const nextBoard = await loop(board);
60
+ let actions = [];
61
+ board.currentPlayer.nextActions.forEach((action: ShipyardAction, id: string) =>
62
+ actions.push(`${id}:${action.toString()}`)
63
+ );
64
+ console.log(actions.join(','));
65
+ } catch (err) {
66
+ console.log(err);
67
+ }
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,45 @@
1
+
2
+ export class Observation {
3
+ public readonly kore: number[];
4
+ public readonly playerHlt: number[];
5
+ public readonly playerShipyards: Map<string, number[]>[];
6
+ public readonly playerFleets: Map<string, string[]>[];
7
+ public readonly player: number;
8
+ public readonly step: number;
9
+ public readonly remainingOverageTime: number;
10
+
11
+ public constructor(rawObservation: string) {
12
+ const json = JSON.parse(rawObservation);
13
+ this.kore = json["kore"];
14
+ this.player = json["player"];
15
+ this.step = json["step"];
16
+ this.remainingOverageTime = rawObservation["remainingOverageTime"];
17
+ const playerParts = json["players"];
18
+ this.playerHlt = [];
19
+ this.playerShipyards = [];
20
+ this.playerFleets = [];
21
+
22
+ for (var i = 0; i < playerParts.length; i ++) {
23
+ const playerPart = playerParts[i];
24
+ this.playerHlt.push(parseInt(playerPart[0]));
25
+
26
+ const shipyards = new Map<string, number[]>();
27
+ Object.entries(playerPart[1]).forEach(entry => {
28
+ const shipyardId = entry[0];
29
+ const shipyardInts = entry[1];
30
+ shipyards.set(shipyardId, shipyardInts as number[]);
31
+ });
32
+ this.playerShipyards.push(shipyards);
33
+
34
+ const fleets = new Map<string, string[]>();
35
+ Object.entries(playerPart[2]).forEach(entry => {
36
+ const fleetId = entry[0];
37
+ const fleetStrs = entry[1];
38
+ fleets.set(fleetId, fleetStrs as string[])
39
+ })
40
+ this.playerFleets.push(fleets)
41
+ }
42
+ }
43
+
44
+
45
+ }
@@ -0,0 +1,11 @@
1
+ export class Pair<F, S> {
2
+
3
+ public readonly first: F;
4
+ public readonly second: S;
5
+
6
+ public constructor(first: F, second: S) {
7
+ this.first = first;
8
+ this.second = second;
9
+ }
10
+
11
+ }
@@ -0,0 +1,68 @@
1
+ import {Board} from "./Board";
2
+ import {Fleet} from "./Fleet";
3
+ import {Shipyard} from "./Shipyard";
4
+ import {ShipyardAction} from "./ShipyardAction";
5
+
6
+ export class Player {
7
+ public readonly id: number;
8
+ public kore: number;
9
+ public readonly shipyardIds: string[];
10
+ public readonly fleetIds: string[];
11
+ public readonly board: Board;
12
+
13
+ public constructor(playerId: number, kore: number, shipyardIds: string[], fleetIds: string[], board: Board) {
14
+ this.id = playerId;
15
+ this.kore = kore;
16
+ this.shipyardIds = shipyardIds;
17
+ this.fleetIds = fleetIds;
18
+ this.board = board;
19
+ }
20
+
21
+ public cloneToBoard(board: Board): Player {
22
+ return new Player(this.id, this.kore, this.shipyardIds.slice(), this.fleetIds.slice(), board);
23
+ }
24
+
25
+ /**
26
+ * Returns all shipyards owned by this player.
27
+ * @return
28
+ */
29
+ public get shipyards(): Shipyard[] {
30
+ return Array.from(this.board.shipyards.values())
31
+ .filter(shipyard => this.shipyardIds.some(sId => sId == shipyard.id));
32
+ }
33
+
34
+ /**
35
+ * Returns all fleets owned by this player.
36
+ */
37
+ public get fleets(): Fleet[] {
38
+ return Array.from(this.board.fleets.values())
39
+ .filter(fleet => this.fleetIds.some(fId => fId == fleet.id));
40
+ }
41
+
42
+ /**
43
+ * Returns whether this player is the current player (generally if this returns True, this player is you.
44
+ */
45
+ public isCurrentPlayer(): boolean {
46
+ return this.id == this.board.currentPlayerId;
47
+ }
48
+
49
+ /**
50
+ * Returns all queued fleet and shipyard actions for this player formatted for the kore interpreter to receive as an agent response.
51
+ */
52
+ public get nextActions(): Map<String, ShipyardAction> {
53
+ const result = new Map<String, ShipyardAction>();
54
+ this.shipyards.filter(shipyard => shipyard.nextAction).forEach(shipyard => result.set(shipyard.id, shipyard.nextAction as ShipyardAction));
55
+ return result;
56
+ }
57
+
58
+ /**
59
+ * Converts a player back to the normalized observation subset that constructed it.
60
+ */
61
+ public observation(): any[] {
62
+ const shipyards = new Map<string, number[]>();
63
+ this.shipyards.forEach(shipyard => shipyards.set(shipyard.id, shipyard.observation()));
64
+ const fleets = new Map<string, string[]>();
65
+ this.fleets.forEach(fleet => fleets.set(fleet.id, fleet.observation()));
66
+ return [this.kore, shipyards, fleets];
67
+ }
68
+ }
@@ -0,0 +1,65 @@
1
+ export class Point {
2
+ public readonly x: number;
3
+ public readonly y: number;
4
+
5
+ public constructor(x: number, y: number) {
6
+ this.x = x;
7
+ this.y = y;
8
+ }
9
+
10
+ public translate(offset: Point, size: number): Point {
11
+ return this.add(offset).mod(size);
12
+ }
13
+
14
+ public add(other: Point): Point {
15
+ return new Point(this.x + other.x, this.y + other.y);
16
+ }
17
+
18
+ public mod(size: number): Point {
19
+ // handle cases where the point is negative due to translation offset being negative
20
+ return new Point((this.x + size) % size, (this.y + size) % size);
21
+ }
22
+
23
+ /**
24
+ * Gets the manhatten distance between two points
25
+ */
26
+ public distanceTo(other: Point, size: number): number {
27
+ const abs_x = Math.abs(this.x - other.x);
28
+ const dist_x = abs_x < size/2 ? abs_x : size - abs_x;
29
+ const abs_y = Math.abs(this.y - other.y);
30
+ const dist_y = abs_y < size/2 ? abs_y : size - abs_y;
31
+ return dist_x + dist_y;
32
+ }
33
+
34
+ /**
35
+ * Converts a 2d position in the form (x, y) to an index in the observation.kore list.
36
+ * See fromIndex for the inverse.
37
+ */
38
+ public toIndex(size: number) {
39
+ return (size - this.y - 1) * size + this.x;
40
+ }
41
+
42
+ public static fromIndex(index: number, size: number): Point {
43
+ return new Point(index % size, size - Math.floor(index/size) - 1);
44
+ }
45
+
46
+ public abs(): Point {
47
+ return new Point(Math.abs(this.x), Math.abs(this.y));
48
+ }
49
+
50
+ public equals(other: Point): boolean {
51
+ return this.x == other.x && this.y == other.y;
52
+ }
53
+
54
+ public toString(): string {
55
+ return "(" + this.x + "," + this.y + ")";
56
+ }
57
+
58
+ public multiply(factor: number): Point {
59
+ return new Point(factor * this.x, factor * this.y);
60
+ }
61
+
62
+ public subtract(other: Point): Point {
63
+ return new Point(this.x - other.x, this.y - other.y);
64
+ }
65
+ }
@@ -0,0 +1,72 @@
1
+
2
+ import {Board} from "./Board";
3
+ import {Cell} from "./Cell";
4
+ import {Player} from "./Player";
5
+ import {Point} from "./Point";
6
+ import {ShipyardAction} from "./ShipyardAction";
7
+
8
+ const SPAWN_VALUES = [];
9
+ const upgradeTimes: number[] = [];
10
+ for(let i = 1; i < 10; i++) {
11
+ upgradeTimes[i-1] = Math.pow(i, 2) + 1;
12
+ }
13
+ let current = 0;
14
+ for(let i = 1; i < 10; i++) {
15
+ current += upgradeTimes[i-1];
16
+ SPAWN_VALUES[i-1] = current;
17
+ }
18
+
19
+ export class Shipyard {
20
+ public readonly id: string;
21
+ public shipCount: number;
22
+ public position: Point;
23
+ public playerId: number;
24
+ public turnsControlled: number;
25
+ public readonly board: Board;
26
+ public nextAction: ShipyardAction | undefined;
27
+
28
+ public constructor(shipyardId: string, shipCount: number, position: Point, playerId: number, turnsControlled: number, board: Board, nextAction: ShipyardAction | undefined) {
29
+ this.id = shipyardId;
30
+ this.shipCount = shipCount;
31
+ this.position = position;
32
+ this.playerId = playerId;
33
+ this.turnsControlled = turnsControlled;
34
+ this.board = board;
35
+ this.nextAction = nextAction;
36
+ }
37
+
38
+ public cloneToBoard(board: Board): Shipyard {
39
+ return new Shipyard(this.id, this.shipCount, this.position, this.playerId, this.turnsControlled, board, this.nextAction);
40
+ }
41
+
42
+ public setNextAction(action: ShipyardAction): void {
43
+ this.nextAction = action;
44
+ }
45
+
46
+ public get maxSpawn(): number {
47
+ for (let i = 0; i < SPAWN_VALUES.length; i++) {
48
+ if (this.turnsControlled < SPAWN_VALUES[i]) {
49
+ return i + 1;
50
+ }
51
+ }
52
+ return SPAWN_VALUES.length + 1;
53
+ }
54
+
55
+ /**
56
+ * Returns the cell this shipyard is on.
57
+ */
58
+ public get cell(): Cell {
59
+ return this.board.getCellAtPosition(this.position);
60
+ }
61
+
62
+ public get player(): Player {
63
+ return this.board.players[this.playerId];
64
+ }
65
+
66
+ /**
67
+ * Converts a shipyard back to the normalized observation subset that constructed it.
68
+ */
69
+ public observation(): number[] {
70
+ return [this.position.toIndex(this.board.configuration.size), this.shipCount, this.turnsControlled];
71
+ }
72
+ }
@@ -0,0 +1,58 @@
1
+
2
+ export class ShipyardAction {
3
+ public static readonly SPAWN = "SPAWN";
4
+ public static readonly LAUNCH = "LAUNCH";
5
+ public readonly actionType: string;
6
+ public readonly shipCount: number;
7
+ public readonly flightPlan: string;
8
+
9
+ public static spawnShips(shipCount: number): ShipyardAction {
10
+ return new ShipyardAction(ShipyardAction.SPAWN, shipCount, "");
11
+ }
12
+
13
+ public static launchFleetWithFlightPlan(shipCount: number, flightPlan: string): ShipyardAction {
14
+ return new ShipyardAction(ShipyardAction.LAUNCH, shipCount, flightPlan);
15
+ }
16
+
17
+ public static fromstring(raw: string): ShipyardAction {
18
+ if (raw.length == 0) {
19
+ throw new Error("invalid raw shipyard empty string");
20
+ }
21
+ const shipCount = parseInt(raw.split("_")[1]);
22
+ if (raw.startsWith(ShipyardAction.LAUNCH)) {
23
+ return ShipyardAction.spawnShips(shipCount);
24
+ }
25
+ if (raw.startsWith(ShipyardAction.SPAWN)) {
26
+ const flightPlan = raw.split("_")[2];
27
+ return ShipyardAction.launchFleetWithFlightPlan(shipCount, flightPlan);
28
+ }
29
+ throw new Error("invalid Shipyard Action raw " + raw);
30
+ }
31
+
32
+ public constructor(type: string, shipCount: number, flightPlan: string) {
33
+ // assert type.equals(SPAWN) || type.equals(LAUNCH) : "Type must be SPAWN or LAUNCH";
34
+ // assert shipCount > 0 : "numShips must be a non-negative number";
35
+ this.actionType = type;
36
+ this.shipCount = shipCount;
37
+ this.flightPlan = flightPlan;
38
+ }
39
+
40
+ private get isSpawn(): boolean {
41
+ return this.actionType == ShipyardAction.SPAWN;
42
+ }
43
+
44
+ private get isLaunch(): boolean {
45
+ return this.actionType == ShipyardAction.LAUNCH;
46
+ }
47
+
48
+ public toString(): string {
49
+ if (this.isSpawn) {
50
+ return `${ShipyardAction.SPAWN}_${this.shipCount}`;
51
+ }
52
+ if (this.isLaunch) {
53
+ return `${ShipyardAction.LAUNCH}_${this.shipCount}_${this.flightPlan}`;
54
+ }
55
+ throw new Error("invalid Shpyard Action");
56
+ }
57
+
58
+ }