kaggle-environments 1.14.17__py2.py3-none-any.whl → 1.15.1__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.14.17"
23
+ __version__ = "1.15.1"
24
24
 
25
25
  __all__ = ["Agent", "environments", "errors", "evaluate", "http_request",
26
26
  "make", "register", "utils", "__version__",
@@ -0,0 +1,75 @@
1
+ async function renderer(context) {
2
+ const {
3
+ environment,
4
+ frame,
5
+ height = 800,
6
+ parent,
7
+ step,
8
+ width = 1200,
9
+ } = context;
10
+
11
+ // Common Dimensions.
12
+ const maxWidth = 1200;
13
+ const maxHeight = 800;
14
+ const canvasSize = Math.min(height, width);
15
+ const boardSize = canvasSize * 0.8;
16
+ const squareSize = boardSize / 8;
17
+ const offset = (canvasSize - boardSize) / 2;
18
+
19
+ // Canvas Setup.
20
+ let canvas = parent.querySelector("canvas");
21
+ if (!canvas) {
22
+ canvas = document.createElement("canvas");
23
+ parent.appendChild(canvas);  
24
+ }
25
+
26
+ // Canvas setup and reset.
27
+ let c = canvas.getContext("2d");
28
+ canvas.width = Math.min(maxWidth, width);
29
+ canvas.height = Math.min(maxHeight, height);
30
+ c.clearRect(0, 0, canvas.width, canvas.height);  
31
+
32
+ // Draw the Chessboard
33
+ for (let row = 0; row < 8; row++) {
34
+ for (let col = 0; col < 8; col++) {
35
+ const x = col * squareSize + offset;
36
+ const y = row * squareSize + offset;
37
+
38
+ // Alternate colors for squares
39
+ c.fillStyle = (row + col) % 2 === 0 ? '#D18B47' : '#FFCE9E';
40
+ c.fillRect(x, y, squareSize, squareSize);
41
+ }
42
+ }
43
+
44
+ // Draw the Pieces
45
+ const board = environment.steps[step][0].observation.board;
46
+ const chess = new Chess(board);
47
+ const boardObj = chess.board();
48
+
49
+ for (let row = 0; row < 8; row++) {
50
+ for (let col = 0; col < 8; col++) {
51
+ const piece = boardObj[row][col]
52
+ if (piece) {
53
+ const x = col * squareSize + offset;
54
+ const y = row * squareSize + offset;
55
+ drawPiece(c, piece.type, piece.color, x, y, squareSize);
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ // Helper function to draw individual pieces (replace with your own images/logic)
62
+ function drawPiece(c, type, color, x, y, size) {
63
+ const pieceCode = color === 'w' ? type.toUpperCase() : type.toLowerCase();
64
+ // Unicode characters for chess pieces
65
+ const pieceSymbols = {
66
+ 'P': 'P', 'R': 'R', 'N': 'N', 'B': 'B', 'Q': 'Q', 'K': 'K',
67
+ 'p': 'p', 'r': 'r', 'n': 'n', 'b': 'b', 'q': 'q', 'k': 'k',
68
+ };
69
+
70
+ c.font = `${size * .8}px Arial`;
71
+ c.textAlign = 'center';
72
+ c.textBaseline = 'middle';
73
+ c.fillStyle = color === 'w' ? 'white' : 'black';
74
+ c.fillText(pieceSymbols[pieceCode], x + size / 2, y + size / 2);
75
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "chess",
3
+ "title": "Chess",
4
+ "description": "Classic Chess with full ruleset",
5
+ "version": "1.0.0",
6
+ "agents": [2],
7
+ "configuration": {
8
+ "episodeSteps": 1000,
9
+ "actTimeout": 1,
10
+ "agentTimeout": {
11
+ "description": "Obsolete field kept for backwards compatibility, please use observation.remainingOverageTime.",
12
+ "type": "number",
13
+ "minimum": 0,
14
+ "default": 60
15
+ }
16
+ },
17
+ "reward": {
18
+ "description": "-1 = Lost, 0 = Draw/Ongoing, 1 = Won",
19
+ "enum": [-1, 0, 1],
20
+ "default": 0
21
+ },
22
+ "observation": {
23
+ "board": {
24
+ "description": "FEN string representation of the board",
25
+ "type": "string",
26
+ "shared": true,
27
+ "default": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
28
+ },
29
+ "mark": {
30
+ "description": "Player color, white or black",
31
+ "defaults": ["white", "black"],
32
+ "enum": ["white", "black"]
33
+ },
34
+ "remainingOverageTime": 60
35
+ },
36
+ "action": {
37
+ "description": "Move in UCI notation (e.g., e2e4)",
38
+ "type": "string",
39
+ "default": ""
40
+ },
41
+ "status": {
42
+ "defaults": ["ACTIVE", "INACTIVE"]
43
+ }
44
+ }
@@ -0,0 +1,109 @@
1
+ import chess
2
+ import random
3
+ import json
4
+ from os import path
5
+
6
+ ERROR = "ERROR"
7
+ DONE = "DONE"
8
+ INACTIVE = "INACTIVE"
9
+ ACTIVE = "ACTIVE"
10
+
11
+ def random_agent(obs):
12
+ """
13
+ Selects a random legal move from the board.
14
+ Returns:
15
+ A string representing the chosen move in UCI notation (e.g., "e2e4").
16
+ """
17
+ board = obs.board
18
+ board_obj = chess.Board(board)
19
+ moves = list(board_obj.legal_moves)
20
+ return random.choice(moves).uci()
21
+
22
+ agents = {"random": random_agent}
23
+
24
+ def interpreter(state, env):
25
+ if env.done:
26
+ return state
27
+
28
+ # Isolate the active and inactive agents.
29
+ active = state[0] if state[0].status == ACTIVE else state[1]
30
+ inactive = state[0] if state[0].status == INACTIVE else state[1]
31
+ if active.status != ACTIVE or inactive.status != INACTIVE:
32
+ active.status = DONE if active.status == ACTIVE else active.status
33
+ inactive.status = DONE if inactive.status == INACTIVE else inactive.status
34
+ return state
35
+
36
+ # The board is shared, only update the first state.
37
+ board = state[0].observation.board
38
+
39
+ # Create a chess board object from the FEN string
40
+ board_obj = chess.Board(board)
41
+
42
+ # Get the action (move) from the agent
43
+ action = active.action
44
+
45
+ # Check if the move is legal
46
+ try:
47
+ move = chess.Move.from_uci(action)
48
+ if not board_obj.is_legal(move):
49
+ raise ValueError("Illegal move")
50
+ except:
51
+ active.status = ERROR
52
+ active.reward = -1
53
+ inactive.status = DONE
54
+ return state
55
+
56
+ # Make the move
57
+ board_obj.push(move)
58
+
59
+ # Update the board in the observation
60
+ state[0].observation.board = board_obj.fen()
61
+ state[1].observation.board = board_obj.fen()
62
+
63
+ # Check for game end conditions
64
+ if board_obj.is_checkmate():
65
+ active.reward = 1
66
+ active.status = DONE
67
+ inactive.reward = -1
68
+ inactive.status = DONE
69
+ elif board_obj.is_stalemate() or board_obj.is_insufficient_material() or board_obj.is_game_over():
70
+ active.status = DONE
71
+ inactive.status = DONE
72
+ else:
73
+ # Switch turns
74
+ active.status = INACTIVE
75
+ inactive.status = ACTIVE
76
+
77
+ return state
78
+
79
+ def renderer(state, env):
80
+ board_str = state[0].observation.board
81
+ board_obj = chess.Board(board_str)
82
+
83
+ # Unicode characters for chess pieces
84
+ piece_symbols = {
85
+ 'P': '♙', 'R': '♖', 'N': '♘', 'B': '♗', 'Q': '♕', 'K': '♔',
86
+ 'p': '♟', 'r': '♜', 'n': '♞', 'b': '♝', 'q': '♛', 'k': '♚',
87
+ '.': ' ' # Empty square
88
+ }
89
+
90
+ board_repr = ""
91
+ for square in chess.SQUARES:
92
+ piece = board_obj.piece_at(square)
93
+ if piece:
94
+ board_repr += piece_symbols[piece.symbol()]
95
+ else:
96
+ board_repr += piece_symbols['.']
97
+ if chess.square_file(square) == 7: # End of a rank
98
+ board_repr += "\n"
99
+
100
+ return board_repr
101
+
102
+ jsonpath = path.abspath(path.join(path.dirname(__file__), "chess.json"))
103
+ with open(jsonpath) as f:
104
+ specification = json.load(f)
105
+
106
+ def html_renderer():
107
+ jspath = path.abspath(path.join(path.dirname(__file__), "chess.js"))
108
+ with open(jspath) as f:
109
+ return f.read()
@@ -0,0 +1,8 @@
1
+ from kaggle_environments import make
2
+
3
+ def test_chess_inits():
4
+ env = make("chess", debug=True)
5
+ env.run(["random", "random"])
6
+ json = env.toJSON()
7
+ assert json["name"] == "chess"
8
+ assert json["statuses"] == ["ERROR", "DONE"]
@@ -40,6 +40,7 @@
40
40
  <script src="https://unpkg.com/preact@10.0.1/dist/preact.umd.js"></script>
41
41
  <script src="https://unpkg.com/preact@10.0.1/hooks/dist/hooks.umd.js"></script>
42
42
  <script src="https://unpkg.com/htm@2.2.1/dist/htm.umd.js"></script>
43
+ <script src="https://unpkg.com/chess.js@0.12.0/chess.js"></script>
43
44
  <script>
44
45
  // Polyfill for Styled Components
45
46
  window.React = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaggle-environments
3
- Version: 1.14.17
3
+ Version: 1.15.1
4
4
  Summary: Kaggle Environments
5
5
  Home-page: https://github.com/Kaggle/kaggle-environments
6
6
  Author: Kaggle
@@ -11,6 +11,7 @@ Requires-Python: >=3.8
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
13
  Requires-Dist: Flask >=1.1.2
14
+ Requires-Dist: chess >=1.11.0
14
15
  Requires-Dist: gymnasium ==0.29.0
15
16
  Requires-Dist: jsonschema >=3.0.1
16
17
  Requires-Dist: numpy >=1.19.5
@@ -1,4 +1,4 @@
1
- kaggle_environments/__init__.py,sha256=lwlAR2-uWed7GhdK8f7ZBxXZAGdrXxlt59oj7mebPEE,1683
1
+ kaggle_environments/__init__.py,sha256=xeLbwI8_AQBKy8XCoR7mGOkZjlb4622jDfIU8YYiAlE,1682
2
2
  kaggle_environments/agent.py,sha256=BpYrAC6EOhJF3Wzynq-CWg8l-z5uXW1Lq4qUsyOM0ik,6203
3
3
  kaggle_environments/api.py,sha256=eLBKqr11Ku4tdsMUdUqy74FIVEA_hdV3_QUpX84x3Z8,798
4
4
  kaggle_environments/core.py,sha256=IrEkN9cIA2djBAxI8Sz1GRpGNKjhqbnBdV6irAeTm8Q,27851
@@ -8,6 +8,10 @@ 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=zxWiMp_EN_84nGF_4UJT2SwWelWwcJKvu_ud9rGzOQU,2395
12
+ kaggle_environments/envs/chess/chess.json,sha256=fmyEm7slLKlykbj-Rm_x7wvHAoJXa_JePU1rjA8gwxo,1201
13
+ kaggle_environments/envs/chess/chess.py,sha256=0K42aiigMt0NSwzbMkCqzGf4zXFiuUzb_jaBsJq4r0M,3095
14
+ kaggle_environments/envs/chess/test_chess.py,sha256=L8C88clpAOiJcP9BVQjDlVtsBu_8eRw3YH5ShGScciQ,239
11
15
  kaggle_environments/envs/connectx/connectx.js,sha256=2j4PigyyZYNH5tzKflmj__8-kT9LMfPsRT_hOkbojUE,9236
12
16
  kaggle_environments/envs/connectx/connectx.json,sha256=Tt-vH-em-RKK5scAcjJ82zOvGov42OW6u9IJCPkS9Fo,1783
13
17
  kaggle_environments/envs/connectx/connectx.py,sha256=PeQsALGBUJrUnCvYmc6AE8nIdFFKM5GHs24RrL0-xAU,6928
@@ -176,10 +180,10 @@ kaggle_environments/envs/tictactoe/test_tictactoe.py,sha256=6CgQbRz-yxNoMfD5tzmC
176
180
  kaggle_environments/envs/tictactoe/tictactoe.js,sha256=NZDT-oSG0a6a-rso9Ldh9qkJwVrxrAsjKUC3_tJu3tw,8002
177
181
  kaggle_environments/envs/tictactoe/tictactoe.json,sha256=zMXZ8-fpT7FBhzz2FFBvRLn4XwtngjEqOieMvI6cCj8,1121
178
182
  kaggle_environments/envs/tictactoe/tictactoe.py,sha256=iLNU5V-lz7Xab-d1vpPMfU5jDM3QtgBUH63Y_SU7I9Y,3639
179
- kaggle_environments/static/player.html,sha256=HH8qvFfTIDw8eZvw5W88jcCu58Lo4_eUQ1ak46KWVGQ,22945
180
- kaggle_environments-1.14.17.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
181
- kaggle_environments-1.14.17.dist-info/METADATA,sha256=rXVCarDaXovcFalC6IOC9ExWKakTK6p8W80ceMe6ZXY,10668
182
- kaggle_environments-1.14.17.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
183
- kaggle_environments-1.14.17.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
184
- kaggle_environments-1.14.17.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
185
- kaggle_environments-1.14.17.dist-info/RECORD,,
183
+ kaggle_environments/static/player.html,sha256=XyVoe0XxMa2MO1fTDY_rjyjzPN-JZgbVwJIDoLSnlw0,23016
184
+ kaggle_environments-1.15.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
185
+ kaggle_environments-1.15.1.dist-info/METADATA,sha256=UVOMydibMkRPa-8w3vNWZ69LzH0i0asL68S1-gIDQ9g,10697
186
+ kaggle_environments-1.15.1.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
187
+ kaggle_environments-1.15.1.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
188
+ kaggle_environments-1.15.1.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
189
+ kaggle_environments-1.15.1.dist-info/RECORD,,