コード例 #1
0
  /* (non-Javadoc)
   * @see pacman.controllers.Controller#getMove(pacman.game.Game, long)
   */
  public EnumMap<GHOST, MOVE> getMove(Game game, long timeDue) {
    int pacmanIndex = game.getPacmanCurrentNodeIndex();

    for (GHOST ghost : GHOST.values()) {
      if (game.doesGhostRequireAction(ghost)) {
        int currentIndex = game.getGhostCurrentNodeIndex(ghost);

        // if ghosts are all in close proximity and not near Ms Pac-Man, disperse
        if (isCrowded(game) && !closeToMsPacMan(game, currentIndex))
          myMoves.put(ghost, getRetreatActions(game, ghost)); // go towards the power pill locations
        // if edible or Ms Pac-Man is close to power pill, move away from Ms Pac-Man
        else if (game.getGhostEdibleTime(ghost) > 0 || closeToPower(game))
          myMoves.put(
              ghost,
              game.getApproximateNextMoveAwayFromTarget(
                  currentIndex,
                  pacmanIndex,
                  game.getGhostLastMoveMade(ghost),
                  DM.PATH)); // move away from ms pacman
        // else go towards Ms Pac-Man
        else
          myMoves.put(
              ghost,
              game.getApproximateNextMoveTowardsTarget(
                  currentIndex,
                  pacmanIndex,
                  game.getGhostLastMoveMade(ghost),
                  DM.PATH)); // go towards ms pacman
      }
    }

    return myMoves;
  }
コード例 #2
0
  /**
   * 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);
  }
コード例 #3
0
  /* (non-Javadoc)
   * @see pacman.controllers.Controller#getMove(pacman.game.Game, long)
   */
  public EnumMap<GHOST, MOVE> getMove(Game game, long timeDue) {
    myMoves.clear();

    int targetNode = game.getPacmanCurrentNodeIndex();

    if (game.doesGhostRequireAction(GHOST.BLINKY))
      myMoves.put(
          GHOST.BLINKY,
          game.getApproximateNextMoveTowardsTarget(
              game.getGhostCurrentNodeIndex(GHOST.BLINKY),
              targetNode,
              game.getGhostLastMoveMade(GHOST.BLINKY),
              DM.PATH));

    if (game.doesGhostRequireAction(GHOST.INKY))
      myMoves.put(
          GHOST.INKY,
          game.getApproximateNextMoveTowardsTarget(
              game.getGhostCurrentNodeIndex(GHOST.INKY),
              targetNode,
              game.getGhostLastMoveMade(GHOST.INKY),
              DM.MANHATTAN));

    if (game.doesGhostRequireAction(GHOST.PINKY))
      myMoves.put(
          GHOST.PINKY,
          game.getApproximateNextMoveTowardsTarget(
              game.getGhostCurrentNodeIndex(GHOST.PINKY),
              targetNode,
              game.getGhostLastMoveMade(GHOST.PINKY),
              DM.EUCLID));

    if (game.doesGhostRequireAction(GHOST.SUE))
      myMoves.put(GHOST.SUE, moves[rnd.nextInt(moves.length)]);

    return myMoves;
  }