Beispiel #1
0
    public override double evaluate(Model.State state)
    {
        bool oldMove = state.isP1Turn;

        state.isP1Turn = true;
        int P1Mobility = state.getLegalMoves().Count;

        state.isP1Turn = false;
        int P2Mobility = state.getLegalMoves().Count;

        state.isP1Turn = oldMove;
        return(normalize(P1Mobility - P2Mobility));
    }
Beispiel #2
0
    private SearchPair search(Model.State state, int depth, bool max)
    {
        List <Model.Action> legalActs = state.getLegalMoves();

        if (legalActs == null || legalActs.Count == 0)
        {
            if (!state.isTerminal)
            {
                Debug.Log("Problem with Model.State: No legal moves but game not over!");
            }
            else
            {
                return(new SearchPair(null, (double)state.winStatus));
            }
        }
        SearchPair bestPair = null;
        SearchPair thisPair = null;
        double     bestEval;

        if (max)
        {
            bestEval = -1.0;
        }
        else
        {
            bestEval = 1.0;
        }
        foreach (Model.Action act in legalActs)
        {
            if (depth <= 1)
            {
                thisPair = new SearchPair(act, this.eval.evaluate(new Model.State(state, act)));
            }
            else
            {
                thisPair = search(new Model.State(state, act), depth - 1, !max);
            }
            if ((max && thisPair.eval >= bestEval) || (!max && thisPair.eval <= bestEval))
            {
                bestEval = thisPair.eval;
                bestPair = new SearchPair(act, bestEval);
            }
        }
        return(bestPair);
    }
Beispiel #3
0
    public override Model.Action getAction(Model.State state)
    {
        List <Model.Action> actions = state.getLegalMoves();

        return(actions[rnd.Next(actions.Count)]);
    }