public int playoutMove(State state) {

		int move = -2; // -2 is our fail state
		List<Integer> legalMoves = state.legalMoves();
		List<Integer> unplayed = new ArrayList<>();

		if (children.size() == 0) {
			return -2;
		}

		// check for unplayed values
		for (int legMove : legalMoves) {
			if (children.get(legMove) == null) {
				unplayed.add(legMove);
			}
		}
		// if there are unplayed values, choose from them randomly
		if (!unplayed.isEmpty()) {
			move = unplayed.get(StdRandom.uniform(unplayed.size()));
		} else { // otherwise find node with highest Ucb1 value
			double ucb = 0;
			for(int key : children.keySet()){
				double currentUCB = children.get(key).getUcb1TunedValue(this);
				if (currentUCB > ucb) {
					ucb = currentUCB;
					move = key;
				}
			}			
		}
		return move;
	}