Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
 public GameState(GameState gs)
     : this(gs.map, gs.Width(), gs.Height(), new Point(gs.MyX(), gs.MyY()), new Point(gs.OpponentX(), gs.OpponentY()))
 {
     this.map = (bool[,])gs.map.Clone();
 }
Ejemplo n.º 3
0
 public Territory(GameState gs)
 {
     this.gs = gs;
     this.me = new Point(gs.MyX(), gs.MyY());
     this.you = new Point(gs.OpponentX(), gs.OpponentY());
 }