Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alternative castling #596

Merged
merged 4 commits into from
Mar 18, 2024
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
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