DangerousAreaModeSelector extends MsPacManModeSelector { public int mode() { int maze = gs.getMazeIndex(); if (scentMaps.containsKey(maze)) { HashMap<Integer, Integer> mazeDeaths = scentMaps.get(maze); int current = gs.getPacmanCurrentNodeIndex(); if (mazeDeaths.containsKey(current)) { double count = mazeDeaths.get(current); int n = 1; int[] neighbors = gs.neighbors(current); for (int i = 0; i < neighbors.length; i++) { if (neighbors[i] != -1) { if (mazeDeaths.containsKey(neighbors[i])) { count += mazeDeaths.get(neighbors[i]); } n++; } } if (count / n > mazeAverages[maze]) { return DANGEROUS; } } } return SAFE; } DangerousAreaModeSelector(); static void updateScentMaps(); int mode(); int numModes(); @Override /** * gets the associated fitness scores with this mode selector based on the * danger of this area * * @return an int array holding the score for if the area is dangerous in * the first index and the score for if the area is safe in the * second index */ int[] associatedFitnessScores(); static HashMap<Integer, HashMap<Integer, Integer>> scentMaps; static double[] mazeAverages; static final int DANGEROUS; static final int SAFE; }
@Test public void testMode() { GameFacade g = new GameFacade(new Game(0)); GameView gv = new GameView(g.newG).showGame(); EnumMap<GHOST,MOVE> gm = new EnumMap<GHOST,MOVE>(GHOST.class); gm.put(GHOST.SUE, MOVE.NEUTRAL); g.newG.advanceGame(MOVE.LEFT, gm); gv.repaint(); MiscUtil.waitForReadStringAndEnterKeyPress(); select.giveGame(g); }