lichess-org / dartchess

Dart chess library for native platforms
https://pub.dev/packages/dartchess
GNU General Public License v3.0
33 stars 17 forks source link

Bug in Castling? #33

Closed topse closed 1 month ago

topse commented 6 months ago

Hi,

Library Version: dartchess: ^0.6.1

I am using the following test-code to query the allowed moves of the king:

    String fen =
        "rnbqk2r/ppppbppp/4p1N1/4P3/8/B7/PPPPBPPP/RN1QK2R w KQkq - 0 1";
    final chess = Chess.fromSetup(Setup.parseFen(fen));

    SquareSet set = chess.legalMovesOf(Squares.e1);
    for (var element in set.squares) {
      developer.log(element.toString());
    }
    Iterable<Square> squares = set.squares;
    expect(squares.length, 2);
    expect(squares.first, Squares.f1);
    expect(squares.last, Squares.g1);

Expected: King has two fields, f1 and g1 (in case of castling). Problem: legalMovesOf gives back the fields f1 and h1, which seems to be odd?

When executing a move, it is possible to execute the move chess.play(NormalMove(from: Squares.e1, to: Squares.g1));, which again seems to be odd, as g1 is not recognized as a legal move.

Best Regards, Tobias

veloce commented 1 month ago

Hi,

Sorry for the late reply. This library purposely defines a single castling move format as the king to rook move. I agree this is not very clear and should be documented.

We're using this helper to get the alternative castling moves: https://github.com/lichess-org/flutter-chessground/blob/main/lib/src/utils.dart#L9

veloce commented 1 month ago

Added some doc comment to the legalMoves getter. Hope it is clearer how to use it now.