Exemplo n.º 1
0
    double AlphaBeta_Slow(GameDescriptor descriptor, int depth, double alpha, double beta)
    {
        Ruler.GameResult result = Ruler.CheckGame(descriptor);
        if (result != Ruler.GameResult.NotYet)
            return Evaluator.EvaluateResult(result, descriptor.Turn) - depth;
        if (depth == 0)
        {
            nodeCount++;
            return Evaluator.Evaluate(descriptor) - depth;
        }

        List<AI_Action> actions = descriptor.QueryAllActions_Slow();
        Disturb(actions);

        foreach (AI_Action tryAction in actions)
        {
            GameDescriptor clone = descriptor.Clone() as GameDescriptor;
            clone.DoAction(tryAction);
            var tmp = -AlphaBeta_Slow(clone, depth - 1, -beta, -alpha);

            if (tmp >= beta)
                return beta;
            if (tmp > alpha)
            {
                alpha = tmp;
                if (depth == Max_Depth)
                    action = tryAction;
            }
        }
        return alpha;
    }
Exemplo n.º 2
0
    double AlphaBeta_Slow(GameDescriptor descriptor, int depth, double alpha, double beta)
    {
        Ruler.GameResult result = Ruler.CheckGame(descriptor);
        if (result != Ruler.GameResult.NotYet)
        {
            return(Evaluator.EvaluateResult(result, descriptor.Turn) - depth);
        }
        if (depth == 0)
        {
            nodeCount++;
            return(Evaluator.Evaluate(descriptor) - depth);
        }

        List <PlayerAction> actions = descriptor.QueryAllActions_Slow();

        Disturb(actions);

        foreach (PlayerAction tryAction in actions)
        {
            GameDescriptor clone = descriptor.Clone() as GameDescriptor;
            clone.DoAction(tryAction);
            var tmp = -AlphaBeta_Slow(clone, depth - 1, -beta, -alpha);

            if (tmp >= beta)
            {
                return(beta);
            }
            if (tmp > alpha)
            {
                alpha = tmp;
                if (depth == Max_Depth)
                {
                    action = tryAction;
                }
            }
        }
        return(alpha);
    }