AnyPillsModeSelector extends MsPacManModeSelector { public int mode() { return gs.getNumActivePills() > 0 || gs.getNumActivePowerPills() > 0 ? PILLS_PRESENT : NO_PILLS_PRESENT; } AnyPillsModeSelector(); 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 pills in the * first index and the score for if there are no pills in the second * index */ int[] associatedFitnessScores(); static final int PILLS_PRESENT; static final int NO_PILLS_PRESENT; }
@Test public void testMode() { GameFacade g = new GameFacade(new Game(0)); EnumMap<GHOST,MOVE> gm = new EnumMap<GHOST,MOVE>(GHOST.class); gm.put(GHOST.SUE, MOVE.NEUTRAL); g.newG.advanceGame(MOVE.LEFT, gm); select.giveGame(g); assertEquals(AnyPillsModeSelector.PILLS_PRESENT, select.mode()); for(int i = 0; i < 100; i++) g.newG.advanceGame(MOVE.LEFT, gm); while(!g.anyIsEdible()) g.newG.advanceGame(MOVE.DOWN, gm); select.giveGame(g); assertEquals(AnyPillsModeSelector.PILLS_PRESENT, select.mode()); g.newG.playWithoutPills(); select.giveGame(g); assertEquals(AnyPillsModeSelector.PILLS_PRESENT, select.mode()); g.newG.playWithoutPowerPills(); select.giveGame(g); assertEquals(AnyPillsModeSelector.NO_PILLS_PRESENT, select.mode()); }