nvzqz / Sage

A cross-platform chess library for Swift
Apache License 2.0
375 stars 43 forks source link

Castling rights not updated after rook capture #8

Closed robmaceachern closed 7 years ago

robmaceachern commented 8 years ago

The castling rights don't seem to be updated when a rook is captured. Here's a quick test I put together:

func testCastlingRightsAfterRookCapture() {
    let startFen = "rnbqkbnr/pppppp1p/8/8/1P4p1/8/PBPPPPPP/RN1QKBNR w KQkq - 0 1"
    let startPosition = Game.Position(fen: startFen)!
    let game = try! Game(position: startPosition)
    let move = Move(start: .b2, end: .h8)
    try! game.execute(move: move)
    XCTAssertFalse(game.castlingRights.contains(.blackKingside))
}

It looks like _execute(uncheckedMove:promotion:) is only updating castling rights when moving rooks or kings right now.

Interestingly, I was able to generate a fen that included invalid castling rights but I couldn't initialize a Position using that same fen (a PositionError.missingRook was thrown). It might be good to include position validation during fen generation too.

Thanks for the fantastic library. Very impressive work!

captainsano commented 7 years ago

@nvzqz: I've added a PR for fixing this. Please take a look, https://github.com/nvzqz/Sage/pull/13