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; }
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(); }
public Territory(GameState gs) { this.gs = gs; this.me = new Point(gs.MyX(), gs.MyY()); this.you = new Point(gs.OpponentX(), gs.OpponentY()); }