Pac-Man has been running from ghosts all his life, but things were not always so. Legend has it that many years ago, Pac-Man's grandfather Grandpac learned to hunt ghosts for sport. However, he was blinded by his power and could subsequently only track ghosts by their banging and clanging sounds.
In this project, you will design Pac-Man agents that use sensors to locate invisible ghosts.
The code for this project contains the following files, available as a zip archive.
||Agents for playing the Ghostbusters variant of Pac-Man.|
||Code for tracking ghosts over time using their sounds.|
||The main entry to Ghostbusters (replacing pacman.py)|
||New ghost agents for Ghostbusters|
||Computes maze distances|
||Inner workings and helper classes for Pac-Man|
||Agents to control ghosts|
||Graphics for Pac-Man|
||Support for Pac-Man graphics|
||Keyboard interfaces to control Pac-Man|
||Code for reading layout files and storing their contents|
What to submit: You will fill in portions of
inference.py during the assignment. You should submit these two files containing your code through BlackBoard.
Please do not change the other files in this distribution or submit any of our original files other
Evaluation: Your code will be autograded for technical correctness. Please do not change the names of any provided functions or classes within the code, or you will wreak havoc on the autograder. However, the correctness of your implementation -- not the autograder's judgements -- will be the final judge of your score. If necessary, we will review and grade assignments individually to ensure that you receive due credit for your work.
Your goal will be to program Pac-Man agents to hunt down scared but invisible ghosts. Pac-Man, ever resourceful, is equipped with sonar (ears) that provides noisy readings of the Manhattan distance to each ghost. The game ends when pacman has eaten all the ghosts.
To start, try playing a game yourself using the keyboard (preferably while listening to the pop classic Ghostbusters).
The blocks of color indicate where each ghost could possibly be, given the noisy distance readings provided to Pac-Man. The noisy distances at the bottom of the display are always non-negative, and always within 7 of the true distance. The probability of a distance reading decreases exponentially with its difference from the true distance.
Your primary task in this project is to implement inference to track the ghosts.
A crude form of inference is implemented for you by default: all squares in which a
ghost could possibly be are shaded by the color of the ghost. Option
shows where the ghost actually is.
python busters.py -s -k 1Naturally, we want a better estimate of the ghost's position. We will start by locating a single, stationary ghost using multiple noisy distance readings. The default
inference.pyto track ghosts.
Question 1 (50 points) Update the
observe method in
ExactInference class of
inference.py to correctly update the agent's
belief distribution over ghost positions. When complete, you should be able to accurately locate a
ghost by circling it.
python busters.py -s -k 1 -g StationaryGhost
Because the default
RandomGhost ghost agents move independently of one another,
you can track each one separately. The default
BustersKeyboardAgent is set up to
do this for you. Hence, you should be able to locate multiple stationary ghosts simultaneously.
Encircling the ghosts should give you precise distributions over the ghosts' locations.
python busters.py -s -g StationaryGhost
Note: Your busters agents have a separate inference module for each ghost they are tracking.
That's why if you print an observation inside the
observe function, you'll only see a
single number even though there may be multiple ghosts on the board.
initializeUniformly. After receiving a reading, the
observefunction is called, which must update the belief at every position.
observefunction) to get started.
util.Counterobjects (like dictionaries) in a field called
self.beliefs, which you should update.
GhostAgent. Your next task is to use the ghost's move distribution to update your agent's beliefs when time elapses.
Question 2 (50 points) Fill in the
elapseTime method in
ExactInference to correctly update the agent's belief distribution over the ghost's
position when the ghost moves. When complete, you should be able to accurately locate moving ghosts,
but some uncertainty will always remain about a ghost's position as it moves.
python busters.py -s -k 1
python busters.py -s -k 1 -g DirectionalGhost
gameState, appears in the comments of
DirectionalGhostis easier to track because it is more predictable. After running away from one for a while, your agent should have a good idea where it is.
Now that Pac-Man can track ghosts, try playing without peeking at the ghost locations. Beliefs about each ghost will be overlaid on the screen. The game should be challenging, but not impossible.
python busters.py -l bigHunt