diff --git a/src/Aiursoft.ChessServer/Aiursoft.ChessServer.csproj b/src/Aiursoft.ChessServer/Aiursoft.ChessServer.csproj index 13e067f..25e1735 100644 --- a/src/Aiursoft.ChessServer/Aiursoft.ChessServer.csproj +++ b/src/Aiursoft.ChessServer/Aiursoft.ChessServer.csproj @@ -15,6 +15,6 @@ - + \ No newline at end of file diff --git a/src/Aiursoft.ChessServer/Services/ChessEngine.cs b/src/Aiursoft.ChessServer/Services/ChessEngine.cs index b3fee8e..f560b12 100644 --- a/src/Aiursoft.ChessServer/Services/ChessEngine.cs +++ b/src/Aiursoft.ChessServer/Services/ChessEngine.cs @@ -1,5 +1,4 @@ using System.Threading.Channels; -using Chess; using Lynx; using Lynx.Model; @@ -21,13 +20,14 @@ public class ChessEngine public string GetBestMove(string fen) { - var board = ChessBoard.LoadFromFen(fen); - _engine.AdjustPosition($"position fen {fen}"); - var moves = _engine.IDDFS(1, 10); - var bestMove = moves.Moves - .Select(t => t.ToEPDString()) - .FirstOrDefault(t => board.IsValidMove(t)); - return bestMove ?? moves.BestMove.ToEPDString(); + var positionClone = new Position(_engine.Game.CurrentPosition); + + var result = _engine.IDDFS(1, 10); + _engine.Game.ResetCurrentPositionToBeforeSearchState(); + + return result + .BestMove + .ToEPDString(positionClone); } } \ No newline at end of file