/// <summary> /// Processes a specified position command, /// with the side effect of resetting the curPositionAndMoves. /// </summary> /// <param name="command"></param> private void ProcessPosition(string command) { command = StringUtils.WhitespaceRemoved(command); string commandLower = command.ToLower(); string posString; if (commandLower.StartsWith("position fen ")) { posString = command.Substring(13); } else if (commandLower.StartsWith("position startpos")) { posString = command.Substring(9); } else { throw new Exception($"Illegal position command, expected to start with position fen or position startpos"); } PositionWithHistory newPositionAndMoves = PositionWithHistory.FromFENAndMovesUCI(posString); curPositionIsContinuationOfPrior = newPositionAndMoves.IsIdenticalToPriorToLastMove(curPositionAndMoves); if (!curPositionIsContinuationOfPrior && CeresEngine != null) { CeresEngine.ResetGame(); } // Switch to the new position and moves curPositionAndMoves = newPositionAndMoves; }
/// <summary> /// Processes a specified position command, /// with the side effect of resetting the curPositionAndMoves. /// </summary> /// <param name="command"></param> private void ProcessPosition(string command) { string[] parts = command.Split(" "); string fen; int nextIndex; string startFEN; switch (parts[1]) { case "fen": fen = command.Substring(command.IndexOf("fen") + 4); nextIndex = 2; while (parts.Length > nextIndex && parts[nextIndex] != "moves") { fen = fen + " " + parts[nextIndex++]; } startFEN = fen; break; case "startpos": startFEN = Position.StartPosition.FEN; nextIndex = 2; break; default: throw new Exception("invalid " + command); } string movesSubstring = ""; if (parts.Length > nextIndex && parts[nextIndex] == "moves") { for (int i = nextIndex + 1; i < parts.Length; i++) { movesSubstring += parts[i] + " "; } } PositionWithHistory newPositionAndMoves = PositionWithHistory.FromFENAndMovesUCI(startFEN, movesSubstring); curPositionIsContinuationOfPrior = newPositionAndMoves.IsIdenticalToPriorToLastMove(curPositionAndMoves); if (!curPositionIsContinuationOfPrior && CeresEngine != null) { CeresEngine.ResetGame(); } // Switch to the new position and moves curPositionAndMoves = newPositionAndMoves; }