예제 #1
0
파일: MyTronBot.cs 프로젝트: nloko/tron
    private static float AlphaBeta(GameState gs, int depth, float alpha, float beta, bool isMax)
    {
        if (depth == 0 || gs.IsEndGame()) {
        float val = EvaluateMove(gs);
        return isMax ? val : -val;
        }

        Point p = null;
        if (isMax) {
        p = new Point(gs.MyX(), gs.MyY());
        } else {
        p = new Point(gs.OpponentX(), gs.OpponentY());
        }

        GameState newState = null;
        foreach (Point child in gs.PossibleMoves(p.X, p.Y, true)) {
        if (isMax) {
             newState = gs.ApplyMoveToMeAndCreate(child.GetDirectionFromPoint(p.X, p.Y));
        } else {
             newState = gs.ApplyMoveToOpponentAndCreate(child.GetDirectionFromPoint(p.X, p.Y));
        }

        alpha = Math.Max (alpha, -AlphaBeta(newState, depth-1, -beta, -alpha, !isMax));
        if (beta <= alpha) {
            break;
        }
        }

        return alpha;
    }