コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: TicTacToe.cs プロジェクト: PaulMineau/AIMA.Net
	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);
		}
	}
コード例 #3
0
ファイル: Game.cs プロジェクト: PaulMineau/AIMA.Net
 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;
     }
 }