Geras1mleo / Chess

C# .NET 6.0 Chess Library
MIT License
49 stars 15 forks source link

Ambiguous move execution failure #21

Closed AlphaYui closed 3 months ago

AlphaYui commented 4 months ago

Describe the bug When a move executed in SAN is ambiguous with two pieces being on the same file, the move execution fails if the notation is over-specific. An example is the screenshot at the bottom: The move "knight on d2 to f3" is ambiguous because of the knight on d4. "N2f3" would be the shortest SAN but "Nd2f3" is also valid. Trying to make a move using the longer notation leads to the following exception:

San.cs:43 @ Chess.Move Chess.ChessBoard.ParseFromSan(string, bool): Chess.ChessSanTooAmbiguousException: Given SAN move: Nd2f3 is too ambiguous between moves: {wn - d2 - f3}, {wn - d4 - f3}

To Reproduce

string fen = "rnbqkb1r/1ppp1pp1/p3pn1p/8/3N4/3P4/PPPNPPPP/R1BQKB1R w KQkq - 0 5";
var board = ChessBoard.LoadFromFen(fen);
board.Move("Nd2f3");

Expected behaviour Ambiguous moves should be executed successfully even if the notation is more detailed than necessary.

Screenshots image

Additional context I believe I've already found the problem and will submit a PR soon.