From 0795b41aae8ce611c74324815c3efdbec2135a7d Mon Sep 17 00:00:00 2001 From: Bovard Doerschuk-Tiberi Date: Fri, 8 Nov 2024 11:45:07 -1000 Subject: [PATCH] Added player visuals on replays (#303) * Added player visuals on replays * bump version --- kaggle_environments/__init__.py | 2 +- kaggle_environments/envs/chess/chess.js | 15 +++++++++++++++ kaggle_environments/envs/chess/chess.py | 9 ++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/kaggle_environments/__init__.py b/kaggle_environments/__init__.py index f4dc5f18..55ff89e7 100644 --- a/kaggle_environments/__init__.py +++ b/kaggle_environments/__init__.py @@ -20,7 +20,7 @@ from .main import http_request from . import errors -__version__ = "1.16.0" +__version__ = "1.16.1" __all__ = ["Agent", "environments", "errors", "evaluate", "http_request", "make", "register", "utils", "__version__", diff --git a/kaggle_environments/envs/chess/chess.js b/kaggle_environments/envs/chess/chess.js index 2b531f71..3f2a5558 100644 --- a/kaggle_environments/envs/chess/chess.js +++ b/kaggle_environments/envs/chess/chess.js @@ -37,6 +37,21 @@ async function renderer(context) { c.fillRect(x, y, squareSize, squareSize); } } + // Draw the team names and game status + const info = environment.info; + const agent1 = info?.TeamNames?.[0] || "Agent 1"; + const agent2 = info?.TeamNames?.[1] || "Agent 2"; + const firstGame = environment.steps[step][0].observation.mark == "white" + const white = firstGame ? agent1 : agent2 + const black = firstGame ? agent2 : agent1 + const fontSize = Math.round(.33 * offset) + c.font = `${fontSize}px sans-serif`; + c.fillStyle = "#FFFFFF"; + const agent1Reward = environment.steps[step][0].reward; + const agent2Reward = environment.steps[step][1].reward; + const charCount = agent1.length + agent2.length + 12; + const title = `${firstGame ? "\u25A0" : "\u25A1"}${agent1} (${agent1Reward}) vs ${firstGame ? "\u25A1" : "\u25A0"}${agent2} (${agent2Reward})` + c.fillText(title, offset + 4 * squareSize - Math.floor(charCount * fontSize / 4), 40) // Draw the Pieces const board = environment.steps[step][0].observation.board; diff --git a/kaggle_environments/envs/chess/chess.py b/kaggle_environments/envs/chess/chess.py index 91fc109a..62c19d42 100644 --- a/kaggle_environments/envs/chess/chess.py +++ b/kaggle_environments/envs/chess/chess.py @@ -168,6 +168,7 @@ def square_str_to_int(square_str): game_one_complete = False game_start_position = math.floor(random.random() * len(OPENINGS)) + def interpreter(state, env): global seen_positions global game_one_complete @@ -227,11 +228,9 @@ def interpreter(state, env): fen.split(" ")[4]) # fen keeps track of this # Check for game end conditions if pawn_or_capture_move_count == 100 or is_insufficient_material( - game.board): - active.status = terminal_state - inactive.status = terminal_state - game_one_complete = True - elif seen_positions[board_str] >= 3 or game.status == Game.STALEMATE: + game.board) or seen_positions[board_str] >= 3 or game.status == Game.STALEMATE: + active.reward += .5 + inactive.reward += .5 active.status = terminal_state inactive.status = terminal_state game_one_complete = True