Fix Board.moveStack() returning chess960 castling notation in non-chess960 mode#913
Draft
Fix Board.moveStack() returning chess960 castling notation in non-chess960 mode#913
Conversation
…mode Co-authored-by: ianfab <12969303+ianfab@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] ffish.js Board.moveStack() method returns chess960 style UCI castling move in non-chess960 mode
Fix Board.moveStack() returning chess960 castling notation in non-chess960 mode
Sep 5, 2025
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.
The
Board.moveStack()method in ffish.js was incorrectly returning chess960-style UCI castling moves (e.g.,e8h8) instead of standard castling notation (e.g.,e8g8) when playing in non-chess960 mode. This occurred when the board position changed significantly after a castling move was played.Problem
Consider this sequence:
Root Cause
The
move_stack()method was callingUCI::move(pos, *it)to convert each storedMoveobject back to UCI format using the current position. When the position changed after castling, the UCI formatting logic detected that the standard castling move (e8g8) would be ambiguous with a normal king move in the new position, causing it to fall back to chess960 notation (e8h8).Solution
Store the original UCI strings when moves are played instead of converting
Moveobjects back to UCI format later:moveStackUCImember variable to preserve input UCI stringspush()andpush_san()to store original UCI strings alongsideMoveobjectsmove_stack()to return stored UCI strings instead of convertingMoveobjectspop()andset_fen()to maintain consistency between both stacksThis ensures
moveStack()always returns the exact UCI strings as they were originally input, eliminating the position-dependent conversion issue.Testing
Added a comprehensive test case that reproduces the exact issue and verifies the fix works correctly for both push/pop operations and position changes.
Fixes #911.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.