put() public method

public put ( String key, Object value ) : void
key String
value Object
return void
Esempio n. 1
0
	public GameState getMove(GameState state, int x, int y) {
		GameState retVal = null;
		XYLocation loc = new XYLocation(x, y);
		List moves = getMoves(state);
		List newMoves = (List) moves.clone();
		if (moves.contains(loc)) {
			int index = newMoves.indexOf(loc);
			newMoves.remove(index);

			retVal = new GameState();

			retVal.put("moves", newMoves);
			TicTacToeBoard newBoard = getBoard(state).cloneBoard();
			if (getPlayerToMove(state) == "X") {
				newBoard.markX(x, y);
				retVal.put("player", "O");

			} else {
				newBoard.markO(x, y);
				retVal.put("player", "X");

			}
			retVal.put("board", newBoard);
			retVal.put("utility", new int(computeUtility(newBoard,
					getPlayerToMove(getState()))));
			retVal.put("level", new int(getLevel(state) + 1));
			// presentState = retVal;
		}
		return retVal;
	}
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        public int minValue(GameState state)
        {
            int v = int.MAX_VALUE;

            if (terminalTest(state))
            {
                return(computeUtility(state));
            }
            else
            {
                List <GameState> successorList = getSuccessorStates(state);
                for (int i = 0; i < successorList.Count; i++)
                {
                    GameState successor = successorList.get(i);
                    int       maximumValueOfSuccessors = maxValue(successor);
                    if (maximumValueOfSuccessors < v)
                    {
                        v = maximumValueOfSuccessors;
                        state.put("next", successor);
                    }
                }
                return(v);
            }
        }
Esempio n. 4
0
        public int maxValue(GameState state)
        {
            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 = successorList.get(i);
                    int minimumValueOfSuccessor = minValue(successor);
                    if (minimumValueOfSuccessor > v)
                    {
                        v = minimumValueOfSuccessor;
                        state.put("next", successor);
                    }
                }
                return v;
            }

        }
Esempio n. 5
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;
     }
 }