kaggle-environments 1.14.17__py2.py3-none-any.whl → 1.15.0__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.
- kaggle_environments/__init__.py +1 -1
- kaggle_environments/envs/chess/chess.js +73 -0
- kaggle_environments/envs/chess/chess.json +44 -0
- kaggle_environments/envs/chess/chess.py +109 -0
- kaggle_environments/envs/chess/test_chess.py +8 -0
- kaggle_environments/static/player.html +1 -0
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/METADATA +2 -1
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/RECORD +12 -8
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/LICENSE +0 -0
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/WHEEL +0 -0
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/entry_points.txt +0 -0
- {kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/top_level.txt +0 -0
kaggle_environments/__init__.py
CHANGED
|
@@ -20,7 +20,7 @@ from .core import *
|
|
|
20
20
|
from .main import http_request
|
|
21
21
|
from . import errors
|
|
22
22
|
|
|
23
|
-
__version__ = "1.
|
|
23
|
+
__version__ = "1.15.0"
|
|
24
24
|
|
|
25
25
|
__all__ = ["Agent", "environments", "errors", "evaluate", "http_request",
|
|
26
26
|
"make", "register", "utils", "__version__",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
async function renderer(context) {
|
|
2
|
+
const {
|
|
3
|
+
environment,
|
|
4
|
+
frame,
|
|
5
|
+
height = 400,
|
|
6
|
+
parent,
|
|
7
|
+
step,
|
|
8
|
+
width = 400,
|
|
9
|
+
} = context;
|
|
10
|
+
|
|
11
|
+
// Common Dimensions.
|
|
12
|
+
const canvasSize = Math.min(height, width);
|
|
13
|
+
const boardSize = canvasSize * 0.8;
|
|
14
|
+
const squareSize = boardSize / 8;
|
|
15
|
+
const offset = (canvasSize - boardSize) / 2;
|
|
16
|
+
|
|
17
|
+
// Canvas Setup.
|
|
18
|
+
let canvas = parent.querySelector("canvas");
|
|
19
|
+
if (!canvas) {
|
|
20
|
+
canvas = document.createElement("canvas");
|
|
21
|
+
parent.appendChild(canvas);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Canvas setup and reset.
|
|
25
|
+
let c = canvas.getContext("2d");
|
|
26
|
+
canvas.width = canvasSize;
|
|
27
|
+
canvas.height = canvasSize;
|
|
28
|
+
c.clearRect(0, 0, canvas.width, canvas.height);
|
|
29
|
+
|
|
30
|
+
// Draw the Chessboard
|
|
31
|
+
for (let row = 0; row < 8; row++) {
|
|
32
|
+
for (let col = 0; col < 8; col++) {
|
|
33
|
+
const x = col * squareSize + offset;
|
|
34
|
+
const y = row * squareSize + offset;
|
|
35
|
+
|
|
36
|
+
// Alternate colors for squares
|
|
37
|
+
c.fillStyle = (row + col) % 2 === 0 ? '#D18B47' : '#FFCE9E';
|
|
38
|
+
c.fillRect(x, y, squareSize, squareSize);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Draw the Pieces
|
|
43
|
+
const board = environment.steps[step][0].observation.board;
|
|
44
|
+
const chess = new Chess(board);
|
|
45
|
+
const boardObj = chess.board();
|
|
46
|
+
|
|
47
|
+
for (let row = 0; row < 8; row++) {
|
|
48
|
+
for (let col = 0; col < 8; col++) {
|
|
49
|
+
const piece = boardObj[row][col]
|
|
50
|
+
if (piece) {
|
|
51
|
+
const x = col * squareSize + offset;
|
|
52
|
+
const y = row * squareSize + offset;
|
|
53
|
+
drawPiece(c, piece.type, piece.color, x, y, squareSize);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Helper function to draw individual pieces (replace with your own images/logic)
|
|
60
|
+
function drawPiece(c, type, color, x, y, size) {
|
|
61
|
+
const pieceCode = color === 'w' ? type.toUpperCase() : type.toLowerCase();
|
|
62
|
+
// Unicode characters for chess pieces
|
|
63
|
+
const pieceSymbols = {
|
|
64
|
+
'P': '♙', 'R': '♖', 'N': '♘', 'B': '♗', 'Q': '♕', 'K': '♔',
|
|
65
|
+
'p': '♟', 'r': '♜', 'n': '♞', 'b': '♝', 'q': '♛', 'k': '♚',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
c.font = `${size * .8}px Arial`;
|
|
69
|
+
c.textAlign = 'center';
|
|
70
|
+
c.textBaseline = 'middle';
|
|
71
|
+
c.fillStyle = color === 'w' ? 'white' : 'black';
|
|
72
|
+
c.fillText(pieceSymbols[pieceCode], x + size / 2, y + size / 2);
|
|
73
|
+
}
|
|
@@ -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()
|
|
@@ -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.
|
|
3
|
+
Version: 1.15.0
|
|
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=
|
|
1
|
+
kaggle_environments/__init__.py,sha256=D8GE2Oqu9sxHRbEpoUeVb8fPCtt9WHh0CfgQTt6RgVs,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=Ghz6OxKEfvd-54vDn-aZBV3JiI5D5xlE3vPU39uGk4Q,2332
|
|
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=
|
|
180
|
-
kaggle_environments-1.
|
|
181
|
-
kaggle_environments-1.
|
|
182
|
-
kaggle_environments-1.
|
|
183
|
-
kaggle_environments-1.
|
|
184
|
-
kaggle_environments-1.
|
|
185
|
-
kaggle_environments-1.
|
|
183
|
+
kaggle_environments/static/player.html,sha256=XyVoe0XxMa2MO1fTDY_rjyjzPN-JZgbVwJIDoLSnlw0,23016
|
|
184
|
+
kaggle_environments-1.15.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
185
|
+
kaggle_environments-1.15.0.dist-info/METADATA,sha256=sMiuYPjtzELZAt3iR5HOEY_Oy3qpux-QzbCTxNzoS7g,10697
|
|
186
|
+
kaggle_environments-1.15.0.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
|
|
187
|
+
kaggle_environments-1.15.0.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
|
|
188
|
+
kaggle_environments-1.15.0.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
|
|
189
|
+
kaggle_environments-1.15.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{kaggle_environments-1.14.17.dist-info → kaggle_environments-1.15.0.dist-info}/top_level.txt
RENAMED
|
File without changes
|