feat: Add complete Chess960 (Fischer Random) support with UCI convention#134
Open
fafriat wants to merge 3 commits intobhlangonijr:masterfrom
Open
feat: Add complete Chess960 (Fischer Random) support with UCI convention#134fafriat wants to merge 3 commits intobhlangonijr:masterfrom
fafriat wants to merge 3 commits intobhlangonijr:masterfrom
Conversation
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
Adds full Chess960 castling support to chesslib, including move generation, validation, execution, undo, SAN/UCI parsing, and FEN round-trip. All 960 starting positions are handled correctly.
Closes #122
Changes
Detection
Board.loadFromFen()auto-detects Chess960 from Shredder-FEN (AHah) orKQkqwith king not on e-fileBoard.loadFromFen(fen, true)forces Chess960 mode (useful when PGN has[Variant "Chess960"])GameContext
loadChess960()configures king/rook moves, traversed squares, and "must be empty" bitboards dynamically from actual piece positionsMove execution
Board.doMove()handles Chess960 castling with manual piece placement (avoids capture issues when king/rook are adjacent)Board.isMoveLegal()excludes king/rook from occupancy checks for castling validationMoveBackup.restore()handles Chess960 castle undoMove generation
MoveGenerator.generateCastleMoves()excludes king/rook from occupancy checksUCI support
Board.toUci(Move)returns king→rook notation for Chess960 castling (e.g.g1h1), following the official UCI Chess960 conventionBoard.fromUci(String)parses king→rook UCI notation as castlingMoveList.loadFromText()usesboard.fromUci()for correct Chess960 UCI parsingSAN support
MoveList.encode()usescontext.isCastleMove()instead of file-delta for castle detection (handles king moves of 0-1 files in Chess960)FEN
Board.getFen()outputs Shredder-FEN castling rights for Chess960 positionsEdge cases handled
Tests
14 new tests covering detection, castling O-O/O-O-O, undo, SAN parsing, UCI conversion, loadFromText, FEN round-trip, standard chess unaffected, and castle rights loss.
All 125 existing tests pass unchanged.