protected override VariationLine DoGetMove(GetMoveRequest request)
        {
            while (true)
            {
                request.CancellationToken.ThrowIfCancellationRequested();

                lock (_syncLock)
                {
                    var move = _move;
                    if (move != null)
                    {
                        _move = null;
                        return(move | VariationLine.Zero);
                    }

                    if (!_isAwaitingMove)
                    {
                        _isAwaitingMove = true;
                        RaiseMoveRequestedAsync();
                    }
                }

                Thread.Sleep(10);
            }
        }
        private static void ExecuteTestForFenAndDepth(
            string fen,
            int maxPlyDepth,
            [CanBeNull] GameMove expectedBestMove)
        {
            var currentMethodName = MethodBase.GetCurrentMethod().GetQualifiedName();

            Console.WriteLine(
                @"[{0}] Executing the test for '{1}' with max ply depth {2}...",
                currentMethodName,
                fen,
                maxPlyDepth);

            var gameBoard = new GameBoard(fen);

            var playerParameters = new EnginePlayerParameters
            {
                MaxPlyDepth           = maxPlyDepth,
                UseOpeningBook        = false,
                MaxTimePerMove        = null,
                UseMultipleProcessors = false,
                UseTranspositionTable = false
            };

            var player = new EnginePlayer(FakeLogger.Instance, FakeOpeningBookProvider.Instance, gameBoard.ActiveSide, playerParameters);

            var stopwatch       = Stopwatch.StartNew();
            var gameControlStub = new GameControl();
            var request         = new GetMoveRequest(gameBoard, CancellationToken.None, gameControlStub);
            var task            = player.CreateGetMoveTask(request);

            task.Start();
            var principalVariationInfo = task.Result;

            stopwatch.Stop();

            Console.WriteLine(
                @"[{0} @ {1}] ({2}) Time {3}, PV {{{4}}}, max ply depth {5}.",
                currentMethodName,
                DateTimeOffset.Now.ToFixedString(),
                ChessHelper.PlatformVersion,
                stopwatch.Elapsed,
                principalVariationInfo,
                player.MaxPlyDepth);

            Console.WriteLine();

            Assert.That(principalVariationInfo, Is.Not.Null);

            if (expectedBestMove != null)
            {
                Assert.That(principalVariationInfo.FirstMove, Is.EqualTo(expectedBestMove));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the move.
        /// </summary>
        /// <param name="request">The move request.</param>
        /// <returns>The <see cref="Task"/> containing the API response with <see cref="Move"/>.</returns>
        public virtual Task <ApiResponse <Move> > GetAsync(GetMoveRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var requestContext = PrepareRequestContext(path: $"{Path}/{request.Id}")
                                 .WithQuery(request.Query.Build());

            return(CallAsync <Move>(requestContext));
        }