@Override public MOVE getMove(Game game, long timeDue) { int current = game.getPacmanCurrentNodeIndex(); // Strategy 1: if any non-edible ghost is too close (less than MIN_DISTANCE), run away for (GHOST ghost : GHOST.values()) if (game.getGhostEdibleTime(ghost) == 0 && game.getGhostLairTime(ghost) == 0) if (game.getShortestPathDistance(current, game.getGhostCurrentNodeIndex(ghost)) < MIN_DISTANCE) return game.getNextMoveAwayFromTarget( game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(ghost), DM.PATH); // Strategy 2: find the nearest edible ghost and go after them int minDistance = Integer.MAX_VALUE; GHOST minGhost = null; for (GHOST ghost : GHOST.values()) if (game.getGhostEdibleTime(ghost) > 0) { int distance = game.getShortestPathDistance(current, game.getGhostCurrentNodeIndex(ghost)); if (distance < minDistance) { minDistance = distance; minGhost = ghost; } } if (minGhost != null) // we found an edible ghost return game.getNextMoveTowardsTarget( game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(minGhost), DM.PATH); // Strategy 3: go after the pills and power pills int[] pills = game.getPillIndices(); int[] powerPills = game.getPowerPillIndices(); ArrayList<Integer> targets = new ArrayList<Integer>(); for (int i = 0; i < pills.length; i++) // check which pills are available if (game.isPillStillAvailable(i)) targets.add(pills[i]); for (int i = 0; i < powerPills.length; i++) // check with power pills are available if (game.isPowerPillStillAvailable(i)) targets.add(powerPills[i]); int[] targetsArray = new int[targets.size()]; // convert from ArrayList to array for (int i = 0; i < targetsArray.length; i++) targetsArray[i] = targets.get(i); // return the next direction once the closest target has been identified return game.getNextMoveTowardsTarget( current, game.getClosestNodeIndexFromNodeIndex(current, targetsArray, DM.PATH), DM.PATH); }
/** * Gets the retreat actions. * * @param game the game * @param ghost the ghost * @return the retreat actions */ private MOVE getRetreatActions(Game game, GHOST ghost) { int currentIndex = game.getGhostCurrentNodeIndex(ghost); int pacManIndex = game.getPacmanCurrentNodeIndex(); if (game.getGhostEdibleTime(ghost) == 0 && game.getShortestPathDistance(currentIndex, pacManIndex) < PACMAN_DISTANCE) return game.getApproximateNextMoveTowardsTarget( currentIndex, pacManIndex, game.getGhostLastMoveMade(ghost), DM.PATH); else return game.getApproximateNextMoveTowardsTarget( currentIndex, game.getPowerPillIndices()[cornerAllocation.get(ghost)], game.getGhostLastMoveMade(ghost), DM.PATH); }