kaggle-environments 1.16.3__py2.py3-none-any.whl → 1.16.5__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.
@@ -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.3"
23
+ __version__ = "1.16.5"
24
24
 
25
25
  __all__ = ["Agent", "environments", "errors", "evaluate", "http_request",
26
26
  "make", "register", "utils", "__version__",
@@ -20,6 +20,7 @@ import sys
20
20
  import traceback
21
21
  from contextlib import redirect_stderr, redirect_stdout
22
22
  from io import StringIO
23
+ from requests.exceptions import Timeout
23
24
  from time import perf_counter
24
25
  from urllib.parse import urlparse
25
26
  from .errors import DeadlineExceeded, InvalidArgument
@@ -78,16 +79,25 @@ class UrlAgent:
78
79
  "observation": observation,
79
80
  },
80
81
  }
81
- response = requests.post(url=self.raw, data=json.dumps(data))
82
- response_json = response.json()
83
- action = response_json["action"]
84
- if action == "DeadlineExceeded":
85
- action = DeadlineExceeded()
86
- elif isinstance(action, str) and action.startswith("BaseException::"):
87
- # Deserialize the exception message
88
- parts = action.split("::", 1)
89
- action = BaseException(parts[1])
90
- return action
82
+ timeout = float(observation.remainingOverageTime) + float(configuration.actTimeout) + 10
83
+ try:
84
+ response = requests.post(url=self.raw, data=json.dumps(data), timeout=timeout)
85
+ response.raise_for_status()
86
+ response_json = response.json()
87
+ action = response_json["action"]
88
+ if action == "DeadlineExceeded":
89
+ action = DeadlineExceeded()
90
+ elif isinstance(action, str) and action.startswith("BaseException::"):
91
+ # Deserialize the exception message
92
+ parts = action.split("::", 1)
93
+ action = BaseException(parts[1])
94
+ return action
95
+ except Timeout:
96
+ print(f"Request timed out after {timeout} seconds")
97
+ return DeadlineExceeded()
98
+ except requests.exceptions.RequestException as e:
99
+ print(f"Request error: {e}")
100
+ return None
91
101
 
92
102
 
93
103
  def build_agent(raw, builtin_agents, environment_name):
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "chess",
3
3
  "title": "Chess",
4
- "description": "Classic Chess with full ruleset",
4
+ "description": "Classic Chess with full rule set",
5
5
  "version": "1.0.0",
6
6
  "agents": [2],
7
7
  "configuration": {
8
8
  "episodeSteps": 1000,
9
9
  "actTimeout": 0.1,
10
10
  "runTimeout": 300,
11
+ "seed": {
12
+ "description": "Integer random value to use to seed the match",
13
+ "type": "number",
14
+ "default": 0
15
+ },
11
16
  "agentTimeout": {
12
17
  "description": "Obsolete field kept for backwards compatibility, please use observation.remainingOverageTime.",
13
18
  "type": "number",
14
19
  "minimum": 0,
15
- "default": 20
20
+ "default": 10
16
21
  }
17
22
  },
18
23
  "reward": {
@@ -32,12 +37,12 @@
32
37
  "defaults": ["white", "black"],
33
38
  "enum": ["white", "black"]
34
39
  },
35
- "remainingOverageTime": 20,
36
40
  "opponentRemainingOverageTime": {
37
41
  "description": "Amount of overage time remaining for the opponent.",
38
42
  "type": "number",
39
- "default": 20
40
- }
43
+ "default": 10
44
+ },
45
+ "remainingOverageTime": 10
41
46
  },
42
47
  "action": {
43
48
  "description": "Move in UCI notation (e.g., e2e4)",
@@ -165,31 +165,19 @@ def square_str_to_int(square_str):
165
165
 
166
166
 
167
167
  seen_positions = defaultdict(int)
168
- game_one_complete = False
169
- game_start_position = math.floor(random.random() * len(OPENINGS))
170
-
171
168
 
172
169
  def interpreter(state, env):
173
170
  global seen_positions
174
- global game_one_complete
175
- global game_start_position
176
171
  if env.done:
177
- game_one_complete = False
178
172
  seen_positions = defaultdict(int)
179
173
  game_start_position = math.floor(random.random() * len(OPENINGS))
174
+ if "seed" in env.configuration:
175
+ seed = int(env.configuration["seed"])
176
+ game_start_position = seed % len(OPENINGS)
180
177
  state[0].observation.board = OPENINGS[game_start_position]
181
178
  state[1].observation.board = OPENINGS[game_start_position]
182
179
  return state
183
180
 
184
- if state[0].status == ACTIVE and state[1].status == ACTIVE:
185
- # set up new game
186
- state[0].observation.mark, state[1].observation.mark = state[1].observation.mark, state[0].observation.mark
187
- state[0].observation.board = OPENINGS[game_start_position]
188
- state[1].observation.board = OPENINGS[game_start_position]
189
- state[0].status = ACTIVE if state[0].observation.mark == WHITE else INACTIVE
190
- state[0].status = ACTIVE if state[0].observation.mark == WHITE else INACTIVE
191
- return state
192
-
193
181
  # Isolate the active and inactive agents.
194
182
  active = state[0] if state[0].status == ACTIVE else state[1]
195
183
  inactive = state[0] if state[0].status == INACTIVE else state[1]
@@ -201,7 +189,7 @@ def interpreter(state, env):
201
189
  # The board is shared, only update the first state.
202
190
  board = state[0].observation.board
203
191
 
204
- # Create a chessnut game object from the FEN string
192
+ # Create a Chessnut game object from the FEN string
205
193
  game = Game(board)
206
194
 
207
195
  # Get the action (move) from the agent
@@ -227,7 +215,6 @@ def interpreter(state, env):
227
215
  state[0].observation.opponentRemainingOverageTime = state[1].observation.remainingOverageTime
228
216
  state[1].observation.opponentRemainingOverageTime = state[0].observation.remainingOverageTime
229
217
 
230
- terminal_state = DONE if game_one_complete else ACTIVE
231
218
  pawn_or_capture_move_count = int(
232
219
  fen.split(" ")[4]) # fen keeps track of this
233
220
  # Check for game end conditions
@@ -235,14 +222,12 @@ def interpreter(state, env):
235
222
  game.board) or seen_positions[board_str] >= 3 or game.status == Game.STALEMATE:
236
223
  active.reward += .5
237
224
  inactive.reward += .5
238
- active.status = terminal_state
239
- inactive.status = terminal_state
240
- game_one_complete = True
225
+ active.status = DONE
226
+ inactive.status = DONE
241
227
  elif game.status == Game.CHECKMATE:
242
228
  active.reward += 1
243
- active.status = terminal_state
244
- inactive.status = terminal_state
245
- game_one_complete = True
229
+ active.status = DONE
230
+ inactive.status = DONE
246
231
  else:
247
232
  # Switch turns
248
233
  active.status = INACTIVE
@@ -15,7 +15,7 @@ def test_chess_three_fold():
15
15
  json = env.toJSON()
16
16
  assert json["name"] == "chess"
17
17
  assert json["statuses"] == ["DONE", "DONE"]
18
- assert json["rewards"] == [1.0, 1.0]
18
+ assert json["rewards"] == [0.5, 0.5]
19
19
 
20
20
  def test_chess_100_move_rule():
21
21
  env = make("chess", debug=True)
@@ -23,7 +23,7 @@ def test_chess_100_move_rule():
23
23
  json = env.toJSON()
24
24
  assert json["name"] == "chess"
25
25
  assert json["statuses"] == ["DONE", "DONE"]
26
- assert json["rewards"] == [1.0, 1.0]
26
+ assert json["rewards"] == [0.5, 0.5]
27
27
 
28
28
  def test_sufficient_material():
29
29
  game = Game()
@@ -12,8 +12,6 @@ from os import path as osp
12
12
  # next two lines enables importing local packages e.g. luxai_s3
13
13
  __dir__ = osp.dirname(__file__)
14
14
  syspath.append(__dir__)
15
-
16
- from luxai_s3.wrappers import LuxAIS3GymEnv, RecordEpisode
17
15
  import numpy as np
18
16
 
19
17
  import copy
@@ -33,7 +31,7 @@ def to_json(state):
33
31
  else:
34
32
  return state
35
33
  prev_step = 0
36
- luxenv: RecordEpisode = None
34
+ luxenv = None
37
35
  prev_obs = None
38
36
  state_obs = None
39
37
  default_env_cfg = None
@@ -43,6 +41,7 @@ def enqueue_output(out, queue):
43
41
  out.close()
44
42
 
45
43
  def interpreter(state, env):
44
+ from luxai_s3.wrappers import LuxAIS3GymEnv, RecordEpisode
46
45
  global luxenv, prev_obs, state_obs, default_env_cfg
47
46
  player_0 = state[0]
48
47
  player_1 = state[1]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaggle-environments
3
- Version: 1.16.3
3
+ Version: 1.16.5
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=uQpIo5wf08JWuDdYt7-vVzpYDXQyjA7PVSeYtE3XFsc,1682
2
- kaggle_environments/agent.py,sha256=BpYrAC6EOhJF3Wzynq-CWg8l-z5uXW1Lq4qUsyOM0ik,6203
1
+ kaggle_environments/__init__.py,sha256=-eVE3vjMKN29HWhPNvlEhndXJSNlHAHl2HLsLnfRtZI,1682
2
+ kaggle_environments/agent.py,sha256=YpzcwcvyykzBL6RvNdZhv4Mdr78iQWtMPPuok3ovRnk,6699
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
@@ -9,9 +9,9 @@ kaggle_environments/schemas.json,sha256=zGzLyhqPdH6QQ0d48SrP5LKbvupprrWvgfQBerLq
9
9
  kaggle_environments/status_codes.json,sha256=6a8HuS_Vth95W0f2fov21QLdRfA3KbizUvjKmJhYtBc,995
10
10
  kaggle_environments/utils.py,sha256=FcI17PA4QK2-hyNp0dryS0TQ2pFlH9K19zDUMmuF4-E,5713
11
11
  kaggle_environments/envs/chess/chess.js,sha256=RVwu2meNTKiXxd15WGZXr5NVwm_RgKMlqIFkzKJ7IaM,30743
12
- kaggle_environments/envs/chess/chess.json,sha256=HaXSPLnC09kzHqHUm_k1e12tEXY5t8oiHpdlsBQdiTE,1402
13
- kaggle_environments/envs/chess/chess.py,sha256=H4ILQ2BRxz7p8a9w6muom5wObo9-WC0ayqzysyqyBeg,8389
14
- kaggle_environments/envs/chess/test_chess.py,sha256=8IhmIJYZ4-PsYh4sKlyT4_UpQpfpRjZ_5HPj06WpzQ0,1748
12
+ kaggle_environments/envs/chess/chess.json,sha256=uo0J_Y2DDwv_T8Kyu1xfduUfzAi6T098LTqQm_EqcnU,1548
13
+ kaggle_environments/envs/chess/chess.py,sha256=fON4l77eR8twHJo1YDcOT2iMxrvHZcIICMB62iYHZUA,7651
14
+ kaggle_environments/envs/chess/test_chess.py,sha256=ayZEIWRSD3D6BqhJv0q_M5a-j8-pMm8kb4ACAW-DhBE,1748
15
15
  kaggle_environments/envs/connectx/connectx.js,sha256=2j4PigyyZYNH5tzKflmj__8-kT9LMfPsRT_hOkbojUE,9236
16
16
  kaggle_environments/envs/connectx/connectx.json,sha256=Tt-vH-em-RKK5scAcjJ82zOvGov42OW6u9IJCPkS9Fo,1783
17
17
  kaggle_environments/envs/connectx/connectx.py,sha256=PeQsALGBUJrUnCvYmc6AE8nIdFFKM5GHs24RrL0-xAU,6928
@@ -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=Pmmw2MrmXZVLgGfnqP5XYRzj1sdnsyy9dTvmv-d291k,4363
169
+ kaggle_environments/envs/lux_ai_s3/lux_ai_s3.py,sha256=3lQIbfZqg1S4ikP7X-FQLBWSLRJ-4uqG1OO48Y3dxA4,4351
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.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
205
- kaggle_environments-1.16.3.dist-info/METADATA,sha256=7o56vSNZlBZa0SmFvMvjMC7kOMY20ZMJHCGumW6xqks,10699
206
- kaggle_environments-1.16.3.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
207
- kaggle_environments-1.16.3.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
208
- kaggle_environments-1.16.3.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
209
- kaggle_environments-1.16.3.dist-info/RECORD,,
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,,