Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/src/model/common/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,14 @@ abstract class Node {
bool prepend = false,
}) {
final pos = nodeAt(path).position;
final isKingMove =
move is NormalMove && pos.board.roleAt(move.from) == Role.king;

final potentialAltCastlingMove = move is NormalMove &&
pos.board.roleAt(move.from) == Role.king &&
pos.board.roleAt(move.to) != Role.rook;

final convertedMove =
isKingMove ? convertAltCastlingMove(move) ?? move : move;
potentialAltCastlingMove ? convertAltCastlingMove(move) ?? move : move;

final (newPos, newSan) = pos.makeSan(convertedMove);
final newNode = Branch(
sanMove: SanMove(newSan, convertedMove),
Expand Down
13 changes: 13 additions & 0 deletions test/model/common/node_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ void main() {
root.addMoveAt(previousUciPath, move!);
expect(root.makePgn(), isNot(initialPng));
});
test(
'do not convert castling move if rook is on the alternative castling square',
() {
const pgn =
'[FEN "rnbqkbnr/pppppppp/8/8/8/2NBQ3/PPPPPPPP/2R1KBNR w KQkq - 0 1"]';
final root = Root.fromPgnGame(PgnGame.parsePgn(pgn));
final initialPng = root.makePgn();
final previousUciPath = root.mainlinePath.penultimate;
final move = Move.parse('e1c1');
root.addMoveAt(previousUciPath, move!);
expect(root.makePgn(), isNot(initialPng));
expect(root.mainline.last.sanMove.move, move);
});
});
}

Expand Down