CompleteTaskModeSelector extends MsPacManModeSelector { public int mode() { if (gs.anyIsEdible()) { return EAT_GHOSTS; } if (gs.getActivePowerPillsIndices().length == 0) { return EAT_PILLS; } int current = gs.getPacmanCurrentNodeIndex(); int[] threatLocations = gs.getThreatGhostLocations(); if (threatLocations.length == 0) { return EAT_PILLS; } int nearestGhost = gs.getClosestNodeIndexFromNodeIndex(current, threatLocations); double distance = gs.getPathDistance(current, nearestGhost); return distance < closeGhostDistance ? LURE : EAT_PILLS; } CompleteTaskModeSelector(); int mode(); int numModes(); @Override /** * gets the associated fitness scores with this mode selector based on human * defined close ghost distance * * @return an int array holding the score for if the ghosts are edible in * the first index, the score for if there are no edible ghosts and * a ghost is near in the second index, and the score for if there * are no edible ghosts and the ghosts are not near in the third * index */ int[] associatedFitnessScores(); static final int EAT_GHOSTS; static final int LURE; static final int EAT_PILLS; final int closeGhostDistance; }
@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(CompleteTaskModeSelector.EAT_PILLS, select.mode()); for(int i = 0; i < 350; i++) g.newG.advanceGame(MOVE.LEFT, gm); select.giveGame(g); assertEquals(CompleteTaskModeSelector.LURE, select.mode()); while(!g.anyIsEdible()) g.newG.advanceGame(MOVE.DOWN, gm); select.giveGame(g); assertEquals(CompleteTaskModeSelector.EAT_GHOSTS, select.mode()); }