protected int maxValue(GameState state, AlphaBeta ab) { int v = int.MIN_VALUE; if (terminalTest(state)) { return(computeUtility(state)); } else { List <GameState> successorList = getSuccessorStates(state); for (int i = 0; i < successorList.Count; i++) { GameState successor = (GameState)successorList.get(i); int minimumValueOfSuccessor = minValue(successor, ab.copy()); if (minimumValueOfSuccessor > v) { v = minimumValueOfSuccessor; state.put("next", successor); } if (v >= ab.beta()) { // System.Console.WriteLine("pruning from max"); return(v); } ab.setAlpha(Util.max(ab.alpha(), v)); } return(v); } }
public override int getAlphaBetaValue(GameState state) { if (getPlayerToMove(state).equalsIgnoreCase("X")) { AlphaBeta initial = new AlphaBeta(int.MIN_VALUE, int.MAX_VALUE); int max = maxValue(state, initial); return max; } else { // invert? AlphaBeta initial = new AlphaBeta(int.MIN_VALUE, int.MAX_VALUE); return minValue(state, initial); } }
protected int maxValue(GameState state, AlphaBeta ab) { int v = int.MIN_VALUE; if (terminalTest(state)) { return computeUtility(state); } else { List<GameState> successorList = getSuccessorStates(state); for (int i = 0; i < successorList.Count; i++) { GameState successor = (GameState)successorList.get(i); int minimumValueOfSuccessor = minValue(successor, ab.copy()); if (minimumValueOfSuccessor > v) { v = minimumValueOfSuccessor; state.put("next", successor); } if (v >= ab.beta()) { // System.Console.WriteLine("pruning from max"); return v; } ab.setAlpha(Util.max(ab.alpha(), v)); } return v; } }