Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChessEnvironment.reset()decides whether the opponent moves first from the agent's color alone (self._agent_color == chess.BLACK), not from whose turn it is on the board. With a customfenwhere the other side is to move, the agent ends up playing the opponent's pieces, and the reward is computed for the wrong side:opponent="random", agent_color="white",reset(fen=<black to move>): no opponent move is made, the agent is asked to move for Black, and if it delivers mate (d8h4in the test position) the step returnsreward=-1.0, a loss.agent_color="black"with the same FEN: the opponent plays Black's move (c7c5), and the agent then moves for White.The opponent now moves first whenever
self._board.turn != self._agent_color. On the standard starting board this is the same as before, since White is to move.The README's
agent_color=Nonerow said "alternate each episode", but the code picks at random fromreset(seed=...)'s RNG. The row now says that, and a sentence explains who moves first with a custom FEN.Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
TestChessEnvironmentWithOpponent:test_agent_moves_for_its_own_color_after_reset: for both agent colors, on the starting board and on a black-to-move FEN, the side to move afterreset()is the agent's.test_agent_mate_from_a_black_to_move_fen_is_a_win: the agent playing Black mates from the black-to-move FEN and getsreward=1.0.chess_environment.pyfrommain, the two black-to-move cases and the mate test fail (3 tests); with this branch all pass.PYTHONPATH=src:envs python -m pytest tests/envs/test_chess_environment.py tests/envs/test_chess_rubric_migration.py: 47 passed (Linux, Python 3.12).bash .claude/hooks/lint.sh,usort/ruff formaton the changed files, andpython scripts/sync_env_docs.py --checkpass.chess_envand its tests.#1693 also touches
chess_environment.py(instep(), notreset()), so the two don't overlap.Claude Code Review
Alignment review by Opus 5.5, in the format of
.claude/skills/alignment-review/SKILL.md.Automated Checks
bash .claude/hooks/lint.shprint,breakpointor TODO lines.Open RFCs Context
No open RFC covers chess_env.
Tier 1: Fixes Required
None.
Tier 2: Alignment Discussion
Principle Conflicts
None identified. The
resetsignature is unchanged and rewards stay inside the environment.RFC Conflicts
None identified.
Summary
Note
Low Risk
Localized bug fix in chess env reset/turn handling with added regression tests; behavior on the standard starting position is unchanged.
Overview
Fixes
ChessEnvironment.reset()so the opponent plays first whenever the board’s side to move is not the agent’s color, not only whenagent_color="black"on the standard start position. Customreset(fen=...)positions where the agent’s opponent is to move no longer let the agent move the wrong color or assign win/loss rewards incorrectly.Docs now describe
agent_color=Noneas random per episode (reproducible withreset(seed=...)) and note when the opponent moves first with a configured opponent. New tests cover side-to-move after reset for both colors on the start and a black-to-move FEN, and that mating from that FEN as Black yieldsreward=1.0.Reviewed by Cursor Bugbot for commit 0edb14a. Bugbot is set up for automated code reviews on this repo. Configure here.