Beispiel #1
0
    double AlphaBeta(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 >= Max_Node)
        {
            nodeCount++;
            return Evaluator.Evaluate(descriptor) - depth; // the quicker, the better
        }

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

        foreach (AI_Action tryAction in actions)
        {
            descriptor.DoAction(tryAction);
            var tmp = -AlphaBeta(descriptor, depth - 1, -beta, -alpha);
            tryAction.UnDo(descriptor);

            if (tmp >= beta)
                return beta;
            if (tmp > alpha)
            {
                alpha = tmp;
                if (depth == Max_Depth)
                    action = tryAction;
            }
        }
        return alpha;
    }
Beispiel #2
0
    double AlphaBeta(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 >= Max_Node)
        {
            nodeCount++;
            return(Evaluator.Evaluate(descriptor) - depth); // the quicker, the better
        }

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

        Disturb(actions);

        foreach (PlayerAction tryAction in actions)
        {
            descriptor.DoAction(tryAction);
            var tmp = -AlphaBeta(descriptor, depth - 1, -beta, -alpha);
            tryAction.UnDo(descriptor);

            if (tmp >= beta)
            {
                return(beta);
            }
            if (tmp > alpha)
            {
                alpha = tmp;
                if (depth == Max_Depth)
                {
                    action = tryAction;
                }
            }
        }
        return(alpha);
    }
Beispiel #3
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);
    }