AnyGhostEdibleModeSelector extends MsPacManModeSelector { @Override public int[] associatedFitnessScores() { int[] result = new int[numModes()]; result[NO_EDIBLE_GHOSTS] = awardProperPowerPillEating ? PROPER_POWER_PILL_GHOST_COMBO : GAME_SCORE; result[SOME_EDIBLE_GHOST] = punishImproperPowerPillEating ? IMPROPER_POWER_PILL_GHOST_COMBO : (levelObjective ? GHOST_AND_LEVEL_COMBO : GHOST_SCORE); return result; } AnyGhostEdibleModeSelector(); int mode(); int numModes(); @Override /** * gets the associated fitness scores with this mode selector based on human * selected parameters * * @return an int array holding the score for no edible ghosts in the first * index and the score for some edible ghosts in the second index */ int[] associatedFitnessScores(); static final int NO_EDIBLE_GHOSTS; static final int SOME_EDIBLE_GHOST; final boolean awardProperPowerPillEating; final boolean punishImproperPowerPillEating; final boolean levelObjective; }
@Test public void testAssociatedFitnessScores() { Parameters.parameters.setBoolean("awardProperPowerPillEating", true); Parameters.parameters.setBoolean("punishImproperPowerPillEating",true); Parameters.parameters.setBoolean("levelObjective", true); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{12,13}); Parameters.parameters.setBoolean("levelObjective", false); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{12 , 13}); Parameters.parameters.setBoolean("punishImproperPowerPillEating",false); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{12 , 3}); Parameters.parameters.setBoolean("levelObjective", true); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{12 , 21}); Parameters.parameters.setBoolean("awardProperPowerPillEating", false); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{1 , 21}); Parameters.parameters.setBoolean("levelObjective", false); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{1 , 3}); Parameters.parameters.setBoolean("punishImproperPowerPillEating",true); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{1 , 13}); Parameters.parameters.setBoolean("levelObjective", true); select = new AnyGhostEdibleModeSelector(); assertArrayEquals(select.associatedFitnessScores(), new int[]{1 , 13}); }