import java.util.HashMap; public class PacmanMCTS implements Pacman { private double C; private int maxTimeMilli; private int maxDepth; public PacmanMCTS(int maxTimeMilli, int maxDepth, double C){ this.C = C; this.maxTimeMilli = maxTimeMilli; this.maxDepth = maxDepth; } @Override public Position chooseAction(PacmanState state) { long startTime = System.currentTimeMillis(); MCTSNode currentNode = new MCTSNode(state); int counter = 0; while(System.currentTimeMillis() - startTime < maxTimeMilli){ counter += 1; MCTSNode leaf = currentNode.selectLeaf(C); leaf.generateSons(); for (MCTSNode node: leaf.getSons()){ this.stateToNode.put(node.getState(), node); } leaf.selectSon(C).runSimulation(maxDepth); } System.out.println("Number of nodes explored: " + counter); return currentNode.selectSonFinal().getState().findPacman(); } }