static void Main(string[] args) { Console.WriteLine("Chess.NET by Gediminas Masaitis"); IChessProtocol protocol = null; var interruptor = new ConsoleInterruptor(); while (true) { string line; if (interruptor.IsRunning) { line = interruptor.WaitStopAndGetResult(); } else { line = Console.ReadLine(); } if (protocol == null && line == "uci") { protocol = new UCIProtocol(interruptor); protocol.OnOutput += Console.WriteLine; protocol.OnExit += Environment.Exit; } protocol?.Input(line); } }
public void Play() { Move bestMove; List <(Position, Move)> nextPositionMoveTupleList = currentPosition.GeneratePositions(); while (result == null) { if (currentPosition.toMove == WHITE) { // Make the white player find a move and apply it to the position. bestMove = Engine.FindBestMove(whitePlayer.EvaluatePosition, currentPosition, nextPositionMoveTupleList, engineDepth, -2.0f, 2.0f).Item1; currentPosition = currentPosition.MakeMove(bestMove); if (currentPosition.fiftyMoveProximity >= 100) { result = DRAW; } else { nextPositionMoveTupleList = currentPosition.GeneratePositions(); if (nextPositionMoveTupleList.Count == 0) { // White just played a move which doesn't give black any pseudo-legal moves. isCheck = currentPosition.IsCheck(); result = isCheck ? WHITE_WIN : DRAW; } else if (nextPositionMoveTupleList.Last().Item1 == null) { // White just played an illegal move (which only happens when there are no legal moves). result = isCheck ? BLACK_WIN : DRAW; } isCheck = currentPosition.IsCheck(); } } else { // Make the black player find a move and apply it to the position. bestMove = Engine.FindBestMove(blackPlayer.EvaluatePosition, currentPosition, nextPositionMoveTupleList, engineDepth, -2.0f, 2.0f).Item1; currentPosition = currentPosition.MakeMove(bestMove); if (currentPosition.fiftyMoveProximity >= 100) { result = DRAW; } else { nextPositionMoveTupleList = currentPosition.GeneratePositions(); if (nextPositionMoveTupleList.Count == 0) { // Black just played a move which doesn't give white any pseudo-legal moves. isCheck = currentPosition.IsCheck(); result = isCheck ? BLACK_WIN : DRAW; } if (nextPositionMoveTupleList.Last().Item1 == null) { // Black just played an illegal move (which only happens when there are no legal moves). result = isCheck ? WHITE_WIN : DRAW; } isCheck = currentPosition.IsCheck(); } } if (storeGame) { moveHistory.Add(UCIProtocol.MoveToUCINotation(bestMove) + " "); } } }