Question: For my intro to Java class, I need to create a PacMan AI. We have been given all of the methods we need, so I

For my intro to Java class, I need to create a PacMan AI. We have been given all of the methods we need, so I just need to piece them together. My strategy in mind is to get pacman close to the power pills and wait until a ghost (or "defender" in the code) is very close to PacMan, then he eats the pill and eats the ghosts. If you have a better strategy please feel free to share it with me. However, I am having trouble writing this PacMan AI and I will post the provided methods below along with their parameters and descriptions of what they do. I do not need to use all of the methods, just one or two from each class. I suspect this will just be a couple of if-else statements since I got a glimpse of some finished programs and they were not very long. Thank you in advance!

Game Interface- A class implementing the Game interface represents a game state.

Get a list List getPillList() of all available pills in the current level.

List getPowerPillList() Get a list of all available power pills in the current level.

boolean checkPill(Node location) Returns true if the location in question holds an available pill.

boolean checkPowerPill(Node location) Returns true if the location in question holds an available power pill.

Attacker getAttacker() Returns a copy of the attackers actor object.

Defender getDefender(int whichDefender) Returns a copy of the defenders actor object specified (by number).

List getDefenders() Retrieves a list of a copy of each defenders actor object.

Game copy() Return a deep copy of this game state object.

Maze getCurMaze() Returns a copy of the current maze information

class Direction { public static final int UP, RIGHT, DOWN, LEFT, EMPTY } Class containing constants for directions.

Node Interface- A class implementing the Node interface represents a location in the terrain. It has coordinates and neighbors.

int getX() Returns the x-coordinate of this location.

int getY() Returns the y-coordinate of this location.

boolean isPill() Returns true if this location has or had a pill.

boolean isPowerPill() Returns true if this location has or had a power pill.

boolean isJunction() Returns true if this location is a fork (has 3 or more neighbors).

int getNumNeighbors() Returns the number of neighbors this location has.

Node getNeighbor(int direction) Returns the node neighboring this location in the direction specified.

List getNeighbors() Returns the nodes neighboring this location as a List.

int getPathDistance(Node destination) Returns the distance of the shortest path between this location and the destination.

Maze Interface- A Maze object, representing the terrain, has the following methods:

Node getInitialAttackerPosition() Returns the starting location of the attacker.

Node getInitialDefendersPosition() Returns the starting location of the defenders.

List getPillNodes() Returns a list of the Node objects where pills are.

List getPowerPillNodes() Returns a list of the Node objects where power pills are.

List getJunctionNodes() Returns a list of the Node objects that are forks (have 3 or more neighbors).

Actor Interface- The Actor interface defines methods that are common to all characters (attackers and defenders alike).

Node getLocation() Returns the current location of the actor.

int getDirection() Returns the direction that the actor is currently facing.

List getPathTo(Node destination) Returns a list of nodes defining a path between the current location and the destination.

int getNextDir(Node target, boolean approach) Returns the next direction the actor should move it to approach (if approach is true) or flee (if false) the target.

Node getTarget(List targets, boolean nearest) Given a list of targets, find the closest (if nearest is true) or furthest (if false) from the actor.

int getReverse() Return the direction that is the reverse of where the agent is currently facing.

Attacker Interface- An Attacker object, representing the attackers actor, provides the following methods:

List getPossibleDirs(boolean canReverse) Returns a list of potential directions that the agent could move in. If canReverse is true, this can include the direction opposite the one the agent is currently facing.

List getPossibleLocations(boolean canReverse) Returns a list of potential locations that the agent could move to from its current location. If canReverse is true, this can include the location in the direction opposite the one the agent is currently facing.

Defender Interface- A Defender object, representing a defenders actor, provides the following methods:

boolean isVulnerable() Returns true if the defender is in a vulnerable state.

boolean requiresAction() Returns true if the actor currently requires an action to properly continue functioning (due to junction, etc.)

int getVulnerableTime() Returns the amount of time left that the actor will be vulnerable.

int getLairTime() Returns the amount of time remaining that the actor will spend in the lair.

List getPossibleDirs() Returns a list of potential directions that the agent could move in, excluding the direction opposite the one the actor is currently facing.

List getPossibleLocations() Returns a list of potential locations that the agent could move to from its current location, excluding the location in the direction opposite the one the agent is currently facing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!