Exemple #1
0
        private float EvaluatePosition(int depth, Dot player, float alpha, float beta)
        {
            if (depth == 0)
            {
                return(Estimator.Estimate(player));
            }

            Dot nextPlayer = player.NextPlayer();

            var moves = MoveGenerator.GenerateMovesForPlayer(player);

            foreach (var move in moves)
            {
                if (alpha < beta)
                {
                    Field.MakeMove(move);
                    float tmp = -EvaluatePosition(depth - 1, nextPlayer, -beta, -alpha);
                    Field.UnmakeMove();
                    if (tmp > alpha)
                    {
                        alpha = tmp;
                    }
                }
            }

            return(alpha);
        }
Exemple #2
0
        public int SearchBestMove(int depth, Dot player, float alpha, float beta)
        {
            int bestMove = 0;

            var moves      = MoveGenerator.GenerateMovesForPlayer(player);
            Dot nextPlayer = player.NextPlayer();

            foreach (var move in moves)
            {
                if (alpha < beta)
                {
                    Field.MakeMove(move);
                    float tmp = -EvaluatePosition(depth - 1, nextPlayer, -beta, -alpha);
                    Field.UnmakeMove();
                    if (tmp > alpha)
                    {
                        alpha    = tmp;
                        bestMove = move;
                    }
                }
            }

            return(bestMove);
        }