Skip to content

Commit

Permalink
Merge pull request #596 from HaonRekcef/fix-castlingmove
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce authored Mar 18, 2024
2 parents 5d8d02b + 94dca22 commit 7c7c9d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lib/src/model/common/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ abstract class Node {
bool prepend = false,
}) {
final pos = nodeAt(path).position;
final (newPos, newSan) = pos.makeSan(convertAltCastlingMove(move) ?? move);
final isKingMove =
move is NormalMove && pos.board.roleAt(move.from) == Role.king;
final convertedMove =
isKingMove ? convertAltCastlingMove(move) ?? move : move;
final (newPos, newSan) = pos.makeSan(convertedMove);
final newNode = Branch(
sanMove: SanMove(newSan, convertAltCastlingMove(move) ?? move),
sanMove: SanMove(newSan, convertedMove),
position: newPos,
);
return addNodeAt(path, newNode, prepend: prepend);
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -769,26 +769,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: cdd14e3836065a1f6302a236ec8b5f700695c803c57ae11a1c84df31e6bcf831
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.3"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "9b2ef90589911d665277464e0482b209d39882dffaaf4ef69a3561a3354b2ebc"
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: fd3cd66cb2bcd7b50dcd3b413af49d78051f809c8b3f6e047962765c15a0d23d
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.0.1"
linkify:
dependency: "direct main"
description:
Expand Down Expand Up @@ -833,10 +833,10 @@ packages:
dependency: "direct main"
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Lichess mobile app V2

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 0.7.4+000704 # see README.md for details about versioning
version: 0.7.5+000705 # see README.md for details about versioning

environment:
sdk: ">=3.3.0 <4.0.0"
Expand Down
10 changes: 10 additions & 0 deletions test/model/common/node_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ void main() {
);
});
});
test('only convert king moves in altCastlingMove', () {
const pgn =
'1. e4 e5 2. Bc4 Qh4 3. Nf3 Qxh2 4. Ke2 Qxh1 5. Qe1 Qh5 6. Qh1';
final root = Root.fromPgnGame(PgnGame.parsePgn(pgn));
final initialPng = root.makePgn();
final previousUciPath = root.mainlinePath.penultimate;
final move = Move.fromUci('e1g1');
root.addMoveAt(previousUciPath, move!);
expect(root.makePgn(), isNot(initialPng));
});
});
}

Expand Down

0 comments on commit 7c7c9d8

Please sign in to comment.