/** * Monte-Carlo simulation for playout. * * @param node Node to start at * @param timeout Time limit * @return Scores for all players */ private int[] playout(Node node, long timeout) { if (node instanceof TerminalNode) { return ((TerminalNode) node).goal; } MachineState state = ((NonTerminalNode) node).state; while (System.currentTimeMillis() < timeout) { if (theMachine.isTerminal(state)) { List<Integer> s; try { s = theMachine.getGoals(state); } catch (GoalDefinitionException e) { System.err.println("Could not compute goal values."); return null; } int[] scores = new int[s.size()]; for (int i = 0; i < scores.length; i++) { scores[i] = s.get(i); } return scores; } try { state = theMachine.getNextState(state, theMachine.getRandomJointMove(state)); } catch (TransitionDefinitionException e) { System.err.println("Could not perform state update."); return null; } catch (MoveDefinitionException e) { System.err.println("Could not compute legal moves."); return null; } } return null; }