AnyGhostThreatModeSelector extends MsPacManModeSelector { public int mode() { return gs.getThreatGhostLocations().length > 0 ? SOME_GHOST_THREATENING : ALL_GHOSTS_EDIBLE; }  int mode(); int numModes(); @Override /** * gets the associated fitness scores with this mode selector * * @return an int array holding the score for if there are some threatening * ghosts in the first index and the score for if there are no * threatening ghosts in the second index */ int[] associatedFitnessScores(); static final int ALL_GHOSTS_EDIBLE; static final int SOME_GHOST_THREATENING; }
@Test public void testMode() { GameFacade g = new GameFacade(new Game(0)); EnumMap<GHOST,MOVE> gm = new EnumMap<GHOST,MOVE>(GHOST.class); gm.put(GHOST.BLINKY, MOVE.NEUTRAL); gm.put(GHOST.INKY, MOVE.NEUTRAL); gm.put(GHOST.PINKY, MOVE.NEUTRAL); gm.put(GHOST.SUE, MOVE.NEUTRAL); g.newG.advanceGame(MOVE.LEFT, gm); select.giveGame(g); assertEquals(AnyGhostThreatModeSelector.ALL_GHOSTS_EDIBLE, select.mode()); while(g.anyActiveGhostInLair()) { g.newG.advanceGame(MOVE.LEFT, gm); } select.giveGame(g); assertEquals(AnyGhostThreatModeSelector.SOME_GHOST_THREATENING, select.mode()); while(!g.anyIsEdible()){ g.newG.advanceGame(MOVE.DOWN, gm); } assertEquals(AnyGhostThreatModeSelector.ALL_GHOSTS_EDIBLE, select.mode()); }