kaggle-environments 1.16.5__py2.py3-none-any.whl → 1.16.7__py2.py3-none-any.whl

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

Potentially problematic release.


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

@@ -20,7 +20,7 @@ from .core import *
20
20
  from .main import http_request
21
21
  from . import errors
22
22
 
23
- __version__ = "1.16.5"
23
+ __version__ = "1.16.7"
24
24
 
25
25
  __all__ = ["Agent", "environments", "errors", "evaluate", "http_request",
26
26
  "make", "register", "utils", "__version__",
@@ -79,7 +79,7 @@ class UrlAgent:
79
79
  "observation": observation,
80
80
  },
81
81
  }
82
- timeout = float(observation.remainingOverageTime) + float(configuration.actTimeout) + 10
82
+ timeout = float(observation.remainingOverageTime) + float(configuration.actTimeout) + 1
83
83
  try:
84
84
  response = requests.post(url=self.raw, data=json.dumps(data), timeout=timeout)
85
85
  response.raise_for_status()
@@ -8,6 +8,28 @@ async function renderer(context) {
8
8
  width = 400,
9
9
  } = context;
10
10
 
11
+ const OPENINGS = [
12
+ "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
13
+ "rnbqkbnr/1p2pp1p/p2p2p1/8/2PNP3/8/PP3PPP/RNBQKB1R w KQkq - 0 6",
14
+ "r1b1kb1r/ppppq1pp/2n2n2/1B2p3/4N3/5N2/PPPPQPPP/R1B1K2R w KQkq - 3 7",
15
+ "rnbqkb1r/p2ppppp/5n2/2pP4/2p5/2N5/PP2PPPP/R1BQKBNR w KQkq - 0 5",
16
+ "rnbqk1nr/p1p1bppp/1p2p3/3pP3/3P4/2N5/PPP2PPP/R1BQKBNR w KQkq - 0 5",
17
+ "r2qk1nr/ppp2pp1/2np3p/2b1p3/2B1P1b1/2PP1N2/PP3PPP/RNBQ1RK1 w kq - 0 7",
18
+ "rn1qk1nr/pp2ppbp/3p2p1/2p5/2PP2b1/2N1PN2/PP3PPP/R1BQKB1R w KQkq c6 0 6",
19
+ "rnbqkbnr/1p2pp1p/p2p2p1/8/2PNP3/8/PP3PPP/RNBQKB1R w KQkq - 0 6",
20
+ ];
21
+
22
+ const MOVES = [
23
+ "",
24
+ "e2e4 c7c5 g1f3 d7d6 d2d4 c5d4 f3d4 a7a6 c2c4 g7g6",
25
+ "e2e4 e7e5 g1f3 b8c6 f1b5 f7f5 b1c3 f5e4 c3e4 g8f6 d1e2 d8e7",
26
+ "d2d4 g8f6 c2c4 c7c5 d4d5 b7b5 b1c3 b5c4",
27
+ "e2e4 e7e6 d2d4 d7d5 b1c3 f8e7 e4e5 b7b6",
28
+ "e2e4 e7e5 g1f3 b8c6 f1c4 f8c5 e1g1 d7d6 c2c3 c8g4 d2d3 h7h6",
29
+ "d2d4 g7g6 c2c4 f8g7 b1c3 d7d6 g1f3 c8g4 e2e3 c7c5",
30
+ "e2e4 c7c5 g1f3 d7d6 d2d4 c5d4 f3d4 a7a6 c2c4 g7g6",
31
+ ];
32
+
11
33
  // Common Dimensions.
12
34
  const canvasSize = Math.min(height, width);
13
35
  const boardSize = canvasSize * 0.8;
@@ -21,6 +43,76 @@ async function renderer(context) {
21
43
  parent.appendChild(canvas);
22
44
  }
23
45
 
46
+ // Create the Download PGN button
47
+ let downloadButton = parent.querySelector("#copy-pgn");
48
+ if (!downloadButton) {
49
+ try {
50
+ downloadButton = document.createElement("button");
51
+ downloadButton.id = "copy-pgn";
52
+ downloadButton.textContent = "Copy PGN";
53
+ downloadButton.style.position = "absolute";
54
+ downloadButton.style.top = "10px";
55
+ downloadButton.style.left = "10px";
56
+ downloadButton.style.zIndex = 1;
57
+ parent.appendChild(downloadButton);
58
+
59
+ const board = environment.steps[step][0].observation.board;
60
+ const info = environment.info;
61
+ const agent1 = info?.TeamNames?.[0] || "Agent 1";
62
+ const agent2 = info?.TeamNames?.[1] || "Agent 2";
63
+ const game = new Chess(board);
64
+ let result = environment.rewards;
65
+ if (result.some(r => r === undefined || r === null)) {
66
+ result = result.map(r => r === undefined || r === null ? 0 : 1)
67
+ }
68
+
69
+ game.header(
70
+ "Event",
71
+ "FIDE & Google Efficient Chess AI Challenge (https://www.kaggle.com/competitions/fide-google-efficiency-chess-ai-challenge)",
72
+ "White",
73
+ agent1,
74
+ "Black",
75
+ agent2,
76
+ "Result",
77
+ result.join(" - ")
78
+ );
79
+
80
+ const openingIdx = OPENINGS.indexOf(board);
81
+ const moves = MOVES[openingIdx].split(" ");
82
+
83
+ for (let i = 0; i < moves.length; i++) {
84
+ const move = moves[i];
85
+ game.move({ from: move.slice(0, 2), to: move.slice(2, 4) });
86
+ }
87
+
88
+ for (let i = 1; i < environment.steps.length; i++) {
89
+ const move = environment.steps[i][(i - 1) % 2].action;
90
+ if (move.length === 4) {
91
+ game.move({ from: move.slice(0, 2), to: move.slice(2, 4) });
92
+ } else if (move.length === 5) {
93
+ game.move({
94
+ from: move.slice(0, 2),
95
+ to: move.slice(2, 4),
96
+ promotion: move.slice(4, 5),
97
+ });
98
+ }
99
+ }
100
+
101
+ downloadButton.addEventListener("click", async () => {
102
+ try {
103
+ await navigator.clipboard.writeText(game.pgn());
104
+ alert("PGN Copied");
105
+ } catch (err) {
106
+ console.error("Failed to copy: ", err);
107
+ alert("Failed to copy PGN");
108
+ }
109
+ });
110
+ } catch (e) {
111
+ console.error('Cannot create game pgn')
112
+ console.error(e);
113
+ }
114
+ }
115
+
24
116
  // Canvas setup and reset.
25
117
  let c = canvas.getContext("2d");
26
118
  canvas.width = canvasSize;
@@ -41,15 +133,23 @@ async function renderer(context) {
41
133
  const info = environment.info;
42
134
  const agent1 = info?.TeamNames?.[0] || "Agent 1";
43
135
  const agent2 = info?.TeamNames?.[1] || "Agent 2";
44
- const firstGame = environment.steps[step][0].observation.mark == "white"
45
- const fontSize = Math.round(.33 * offset)
136
+ const firstGame = environment.steps[step][0].observation.mark == "white";
137
+ const fontSize = Math.round(0.33 * offset);
46
138
  c.font = `${fontSize}px sans-serif`;
47
139
  c.fillStyle = "#FFFFFF";
48
140
  const agent1Reward = environment.steps[step][0].reward;
49
141
  const agent2Reward = environment.steps[step][1].reward;
50
142
  const charCount = agent1.length + agent2.length + 12;
51
- const title = `${firstGame ? "\u25A0" : "\u25A1"}${agent1} (${agent1Reward}) vs ${firstGame ? "\u25A1" : "\u25A0"}${agent2} (${agent2Reward})`
52
- c.fillText(title, offset + 4 * squareSize - Math.floor(charCount * fontSize / 4), 40)
143
+ const title = `${
144
+ firstGame ? "\u25A0" : "\u25A1"
145
+ }${agent1} (${agent1Reward}) vs ${
146
+ firstGame ? "\u25A1" : "\u25A0"
147
+ }${agent2} (${agent2Reward})`;
148
+ c.fillText(
149
+ title,
150
+ offset + 4 * squareSize - Math.floor((charCount * fontSize) / 4),
151
+ 40
152
+ );
53
153
 
54
154
  // Draw the Pieces
55
155
  const board = environment.steps[step][0].observation.board;
@@ -41,83 +41,87 @@ def enqueue_output(out, queue):
41
41
  out.close()
42
42
 
43
43
  def interpreter(state, env):
44
- from luxai_s3.wrappers import LuxAIS3GymEnv, RecordEpisode
45
- global luxenv, prev_obs, state_obs, default_env_cfg
46
- player_0 = state[0]
47
- player_1 = state[1]
48
- # filter out actions such as debug annotations so they aren't saved
49
- # filter_actions(state, env)
50
-
51
- if env.done:
52
- if "seed" in env.configuration:
53
- seed = int(env.configuration["seed"])
54
- else:
55
- seed = math.floor(random.random() * 1e9);
56
- env.configuration["seed"] = seed
57
-
58
- luxenv = LuxAIS3GymEnv(numpy_output=True)
59
- luxenv = RecordEpisode(luxenv, save_on_close=False, save_on_reset=False)
60
- obs, info = luxenv.reset(seed=seed)
61
-
62
- env_cfg_json = info["params"]
63
-
64
- env.configuration.env_cfg = env_cfg_json
44
+ try:
45
+ from luxai_s3.wrappers import LuxAIS3GymEnv, RecordEpisode
46
+ global luxenv, prev_obs, state_obs, default_env_cfg
47
+ player_0 = state[0]
48
+ player_1 = state[1]
49
+ # filter out actions such as debug annotations so they aren't saved
50
+ # filter_actions(state, env)
51
+
52
+ if env.done:
53
+ if "seed" in env.configuration:
54
+ seed = int(env.configuration["seed"])
55
+ else:
56
+ seed = math.floor(random.random() * 1e9);
57
+ env.configuration["seed"] = seed
58
+
59
+ luxenv = LuxAIS3GymEnv(numpy_output=True)
60
+ luxenv = RecordEpisode(luxenv, save_on_close=False, save_on_reset=False)
61
+ obs, info = luxenv.reset(seed=seed)
62
+
63
+ env_cfg_json = info["params"]
64
+
65
+ env.configuration.env_cfg = env_cfg_json
66
+
67
+ player_0.observation.player = "player_0"
68
+ player_1.observation.player = "player_1"
69
+ player_0.observation.obs = json.dumps(to_json(obs["player_0"]))
70
+ player_1.observation.obs = json.dumps(to_json(obs["player_1"]))
71
+
72
+ replay_frame = luxenv.serialize_episode_data(dict(
73
+ states=[luxenv.episode["states"][-1]],
74
+ metadata=luxenv.episode["metadata"],
75
+ params=luxenv.episode["params"]
76
+ ))
77
+ # don't need to keep metadata/params beyond first step
78
+ player_0.info = dict(replay=replay_frame)
79
+ return state
65
80
 
81
+ new_state_obs, rewards, terminations, truncations, infos = luxenv.step({
82
+ "player_0": np.array(player_0.action["action"]),
83
+ "player_1": np.array(player_1.action["action"])
84
+ })
85
+
86
+ # cannot store np arrays in replay jsons so must convert to list
87
+ player_0.action = player_0.action["action"]
88
+ player_1.action = player_1.action["action"]
89
+
90
+ dones = dict()
91
+ for k in terminations:
92
+ dones[k] = terminations[k] | truncations[k]
93
+
66
94
  player_0.observation.player = "player_0"
67
95
  player_1.observation.player = "player_1"
68
- player_0.observation.obs = json.dumps(to_json(obs["player_0"]))
69
- player_1.observation.obs = json.dumps(to_json(obs["player_1"]))
96
+
97
+ player_0.observation.obs = json.dumps(to_json(new_state_obs["player_0"]))
98
+ player_1.observation.obs = json.dumps(to_json(new_state_obs["player_1"]))
70
99
 
100
+
101
+ player_0.reward = int(rewards["player_0"])
102
+ player_1.reward = int(rewards["player_1"])
103
+
104
+ player_0.observation.reward = int(player_0.reward)
105
+ player_1.observation.reward = int(player_1.reward)
71
106
  replay_frame = luxenv.serialize_episode_data(dict(
72
107
  states=[luxenv.episode["states"][-1]],
108
+ actions=[luxenv.episode["actions"][-1]],
73
109
  metadata=luxenv.episode["metadata"],
74
110
  params=luxenv.episode["params"]
75
111
  ))
76
112
  # don't need to keep metadata/params beyond first step
113
+ del replay_frame["metadata"]
114
+ del replay_frame["params"]
77
115
  player_0.info = dict(replay=replay_frame)
78
- return state
79
-
80
- new_state_obs, rewards, terminations, truncations, infos = luxenv.step({
81
- "player_0": np.array(player_0.action["action"]),
82
- "player_1": np.array(player_1.action["action"])
83
- })
84
-
85
- # cannot store np arrays in replay jsons so must convert to list
86
- player_0.action = player_0.action["action"]
87
- player_1.action = player_1.action["action"]
88
-
89
- dones = dict()
90
- for k in terminations:
91
- dones[k] = terminations[k] | truncations[k]
92
-
93
- player_0.observation.player = "player_0"
94
- player_1.observation.player = "player_1"
95
116
 
96
- player_0.observation.obs = json.dumps(to_json(new_state_obs["player_0"]))
97
- player_1.observation.obs = json.dumps(to_json(new_state_obs["player_1"]))
98
-
99
-
100
- player_0.reward = int(rewards["player_0"])
101
- player_1.reward = int(rewards["player_1"])
102
-
103
- player_0.observation.reward = int(player_0.reward)
104
- player_1.observation.reward = int(player_1.reward)
105
- replay_frame = luxenv.serialize_episode_data(dict(
106
- states=[luxenv.episode["states"][-1]],
107
- actions=[luxenv.episode["actions"][-1]],
108
- metadata=luxenv.episode["metadata"],
109
- params=luxenv.episode["params"]
110
- ))
111
- # don't need to keep metadata/params beyond first step
112
- del replay_frame["metadata"]
113
- del replay_frame["params"]
114
- player_0.info = dict(replay=replay_frame)
115
-
116
- if np.all([dones[k] for k in dones]):
117
- if player_0.status == "ACTIVE":
118
- player_0.status = "DONE"
119
- if player_1.status == "ACTIVE":
120
- player_1.status = "DONE"
117
+ if np.all([dones[k] for k in dones]):
118
+ if player_0.status == "ACTIVE":
119
+ player_0.status = "DONE"
120
+ if player_1.status == "ACTIVE":
121
+ player_1.status = "DONE"
122
+ return state
123
+ except ModuleNotFoundError as e:
124
+ print("Lux AI S3 Dependencies are missing, interpreter will not work")
121
125
  return state
122
126
 
123
127
  def renderer(state, env):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaggle-environments
3
- Version: 1.16.5
3
+ Version: 1.16.7
4
4
  Summary: Kaggle Environments
5
5
  Home-page: https://github.com/Kaggle/kaggle-environments
6
6
  Author: Kaggle
@@ -1,5 +1,5 @@
1
- kaggle_environments/__init__.py,sha256=-eVE3vjMKN29HWhPNvlEhndXJSNlHAHl2HLsLnfRtZI,1682
2
- kaggle_environments/agent.py,sha256=YpzcwcvyykzBL6RvNdZhv4Mdr78iQWtMPPuok3ovRnk,6699
1
+ kaggle_environments/__init__.py,sha256=bwbAjK5CWz6unr-mWc8HFf1bsbRzyJn4tWiK2tP3W3Q,1682
2
+ kaggle_environments/agent.py,sha256=MGBOuCojql8vuODPdyPYJgKRnVAVI_D_YDl53J15aPM,6698
3
3
  kaggle_environments/api.py,sha256=eLBKqr11Ku4tdsMUdUqy74FIVEA_hdV3_QUpX84x3Z8,798
4
4
  kaggle_environments/core.py,sha256=IrEkN9cIA2djBAxI8Sz1GRpGNKjhqbnBdV6irAeTm8Q,27851
5
5
  kaggle_environments/errors.py,sha256=SzKjkZP7pJbf9g0GDjGq4XG194hCQXLMwrlMCcm7Ai8,3336
@@ -8,7 +8,7 @@ kaggle_environments/main.py,sha256=10wtcEFcGIjdOd9AEps5WOAwslc6Wsx3eZ43LXJa8jE,1
8
8
  kaggle_environments/schemas.json,sha256=zGzLyhqPdH6QQ0d48SrP5LKbvupprrWvgfQBerLqmhw,3307
9
9
  kaggle_environments/status_codes.json,sha256=6a8HuS_Vth95W0f2fov21QLdRfA3KbizUvjKmJhYtBc,995
10
10
  kaggle_environments/utils.py,sha256=FcI17PA4QK2-hyNp0dryS0TQ2pFlH9K19zDUMmuF4-E,5713
11
- kaggle_environments/envs/chess/chess.js,sha256=RVwu2meNTKiXxd15WGZXr5NVwm_RgKMlqIFkzKJ7IaM,30743
11
+ kaggle_environments/envs/chess/chess.js,sha256=lMqqAawNyWwDkLeUrlb2DyysXvii3Bcn-7MCdx0Dq8s,34116
12
12
  kaggle_environments/envs/chess/chess.json,sha256=uo0J_Y2DDwv_T8Kyu1xfduUfzAi6T098LTqQm_EqcnU,1548
13
13
  kaggle_environments/envs/chess/chess.py,sha256=fON4l77eR8twHJo1YDcOT2iMxrvHZcIICMB62iYHZUA,7651
14
14
  kaggle_environments/envs/chess/test_chess.py,sha256=ayZEIWRSD3D6BqhJv0q_M5a-j8-pMm8kb4ACAW-DhBE,1748
@@ -166,7 +166,7 @@ kaggle_environments/envs/lux_ai_s2/test_agents/python/lux/utils.py,sha256=k3Cazt
166
166
  kaggle_environments/envs/lux_ai_s3/agents.py,sha256=43bT4pa6t1SsAS4akQ8y2L7wJrs0hZAH0v1M5Nt_vR0,112
167
167
  kaggle_environments/envs/lux_ai_s3/index.html,sha256=ku5-4zEckdKLEJOGrMcYmAUVmdvcn7WmAxGikHdHSeM,1558
168
168
  kaggle_environments/envs/lux_ai_s3/lux_ai_s3.json,sha256=LrYYdwN2zDlCUg33VpGq8oPYLhDxmakPB4yTl6UurX4,1179
169
- kaggle_environments/envs/lux_ai_s3/lux_ai_s3.py,sha256=3lQIbfZqg1S4ikP7X-FQLBWSLRJ-4uqG1OO48Y3dxA4,4351
169
+ kaggle_environments/envs/lux_ai_s3/lux_ai_s3.py,sha256=edBgOiYvBtrPKzvxVfUJMzblChRn3tJbOs-N6q7Yzj4,4769
170
170
  kaggle_environments/envs/lux_ai_s3/test_lux.py,sha256=cfiEv4re7pvZ9TeG9HdvGOhHb0da272w8CDUSZn5bpU,273
171
171
  kaggle_environments/envs/lux_ai_s3/luxai_s3/__init__.py,sha256=2hwayynTiOtSr3V1-gjZfosn0Y3sOSKvNrYHhHeAyhY,28
172
172
  kaggle_environments/envs/lux_ai_s3/luxai_s3/env.py,sha256=pMAof3kYlPQkilFiCTY-JGV7RYO-ODUNCTFvwc1oawg,39437
@@ -201,9 +201,9 @@ kaggle_environments/envs/tictactoe/tictactoe.js,sha256=NZDT-oSG0a6a-rso9Ldh9qkJw
201
201
  kaggle_environments/envs/tictactoe/tictactoe.json,sha256=zMXZ8-fpT7FBhzz2FFBvRLn4XwtngjEqOieMvI6cCj8,1121
202
202
  kaggle_environments/envs/tictactoe/tictactoe.py,sha256=iLNU5V-lz7Xab-d1vpPMfU5jDM3QtgBUH63Y_SU7I9Y,3639
203
203
  kaggle_environments/static/player.html,sha256=XyVoe0XxMa2MO1fTDY_rjyjzPN-JZgbVwJIDoLSnlw0,23016
204
- kaggle_environments-1.16.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
205
- kaggle_environments-1.16.5.dist-info/METADATA,sha256=5xBOK4DgWdKY0lGy17Mgj-jwcWJxEOceOH3FOTuKER8,10699
206
- kaggle_environments-1.16.5.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
207
- kaggle_environments-1.16.5.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
208
- kaggle_environments-1.16.5.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
209
- kaggle_environments-1.16.5.dist-info/RECORD,,
204
+ kaggle_environments-1.16.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
205
+ kaggle_environments-1.16.7.dist-info/METADATA,sha256=PnuAkVHY8z-bSq7uAqSuAzSQOmFiVKYSwWmirOUIgPw,10699
206
+ kaggle_environments-1.16.7.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
207
+ kaggle_environments-1.16.7.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
208
+ kaggle_environments-1.16.7.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
209
+ kaggle_environments-1.16.7.dist-info/RECORD,,