Ejemplo n.º 1
0
        public Option <Move.Move> FindBestMove(Position.Position currentPosition)
        {
            evaluator.OnNewSearch(currentPosition);

            Option <Move.Move> bestMove = Option.None <Move.Move>();
            int bestMoveEvaluation      = MinEvaluationValue;

            foreach (var move in MoveGenerator.GenerateLegalMoves(currentPosition))
            {
                currentPosition.PlayMove(move);

                var evaluation = -CalculateEvaluationRecursively(
                    currentPosition,
                    currentDepth: 1)
                                 .ValueOr(-MinEvaluationValue);

                if (!bestMove.HasValue || evaluation >= bestMoveEvaluation)
                {
                    bestMove           = Option.Some(move);
                    bestMoveEvaluation = evaluation;
                }

                currentPosition.UndoMove();
            }

            return(bestMove);
        }
Ejemplo n.º 2
0
        public Task <Option <Move.Move> > FindBestMove(Position.Position position)
        {
            var legalMoves = MoveGenerator.GenerateLegalMoves(position);

            if (legalMoves.Count == 0)
            {
                return(Task.FromResult(Option.None <Move.Move>()));
            }
            else if (legalMoves.Count == 1)
            {
                return(Task.FromResult(Option.Some(legalMoves[0])));
            }

            var searchManager = new SearchManager(new Evaluator(), 2);

            return(Task.Run(() => searchManager.FindBestMove(position)));
        }