Beispiel #1
0
        private void ProcessBestMove(string line, bool tryToPlay)
        {
            try
            {
                Move bestMove = NotationUtils.ParseMoveString(Board, line.Split(';')[0]);

                TargetPiece    = bestMove.PieceName;
                TargetPosition = bestMove.Position;
                TargetMove     = bestMove;
            }
            catch (Exception)
            {
                TargetPiece = PieceName.INVALID;
            }

            if (tryToPlay && CurrentTurnIsEngineAI && CurrentGameSettings.GameMode == GameMode.Play && null != TargetMove)
            {
                if (TargetMove.IsPass)
                {
                    SendCommandInternal("pass");
                }
                else
                {
                    SendCommandInternal("play {0}", NotationUtils.ToBoardSpaceMoveString(Board, TargetMove));
                }
            }
        }
Beispiel #2
0
        private void BestMove(int maxDepth)
        {
            if (null == _gameBoard)
            {
                throw new NoBoardException();
            }

            if (_gameBoard.GameIsOver)
            {
                throw new GameIsOverException();
            }

            StopPonder();

            CancellationToken token = OnStartAsyncCommand();

            Task <Move> task = _gameAI.GetBestMoveAsync(_gameBoard.Clone(), maxDepth, Config.MaxHelperThreads, token);

            task.Wait();

            if (null == task.Result)
            {
                throw new Exception("Null move returned!");
            }

            ConsoleOut(NotationUtils.ToBoardSpaceMoveString(_gameBoard, task.Result));

            OnEndAsyncCommand();
        }
Beispiel #3
0
        private void BestMove(TimeSpan maxTime)
        {
            if (null == _gameBoard)
            {
                throw new NoBoardException();
            }

            if (_gameBoard.GameIsOver)
            {
                throw new GameIsOverException();
            }

            StopPonder();

            CancellationToken token = OnStartAsyncCommand();

            if (maxTime < TimeSpan.MaxValue)
            {
                _asyncCommandCTS.CancelAfter(maxTime);
            }

            Task <Move> task = _gameAI.GetBestMoveAsync(_gameBoard, maxTime, Config.MaxHelperThreads, token);

            task.Wait();

            if (null == task.Result)
            {
                throw new Exception("Null move returned!");
            }

            ConsoleOut(NotationUtils.ToBoardSpaceMoveString(_gameBoard, task.Result));

            OnEndAsyncCommand();
        }
Beispiel #4
0
 private void OnBestMoveFound(object sender, BestMoveFoundEventArgs args)
 {
     if (null != _gameBoard && !_isPondering && Config.ReportIntermediateBestMoves)
     {
         ConsoleOut("{0};{1};{2:0.00}", NotationUtils.ToBoardSpaceMoveString(_gameBoard, args.Move), args.Depth, args.Score);
     }
 }
Beispiel #5
0
        public void PlayTargetMove()
        {
            if (CurrentGameSettings.GameMode != GameMode.Play)
            {
                throw new Exception("Please switch the current game to play mode first.");
            }

            if (null == TargetMove)
            {
                throw new Exception("Please select a valid piece and destination first.");
            }

            if (TargetMove.IsPass)
            {
                Pass();
            }
            else
            {
                SendCommand("play {0}", NotationUtils.ToBoardSpaceMoveString(Board, TargetMove));
            }
        }