DM828, Assignment 2: Ghostbusters

GHOSTBUSTERS

I can hear you, ghost.
Running won't save you from my
Particle filter!

Introduction

Pac-Man spends his life running from ghosts, but things were not always so. Legend has it that many years ago, Pac-Man's great grandfather Grandpac learned to hunt ghosts for sport. However, he was blinded by his power and could only track ghosts by their banging and clanging.

In this project, you will design Pac-Man agents that use sensors to locate and eat invisible ghosts. You'll advance from locating single, stationary ghosts to hunting packs of multiple moving ghosts with ruthless efficiency.

The code for this project contains the following files, available as a zip archive.

Files you will edit
bustersAgents.py Agents for playing the Ghostbusters variant of Pac-Man.
inference.py Code for tracking ghosts over time using their sounds.
Files you will not edit
busters.py The main entry to Ghostbusters (replacing pacman.py)
bustersGhostAgents.py New ghost agents for Ghostbusters
distanceCalculator.py Computes maze distances
game.py Inner workings and helper classes for Pac-Man
ghostAgents.py Agents to control ghosts
graphicsDisplay.py Graphics for Pac-Man
graphicsUtils.py Support for Pac-Man graphics
keyboardAgents.py Keyboard interfaces to control Pac-Man
layout.py Code for reading layout files and storing their contents
util.py Utility functions

What to submit: You will fill in portions of bustersAgents.py and inference.py during the assignment. You should submit this files with your code and comments. In addition submit a file in any format different from .py and with name README for your graphical answers (handwritten graphs are fine). This file must contain the graphical model underlying your answer to the four questions. Please do not change the other files in this distribution or submit any of our original files other than inference.py and bustersAgents.py. For submission use the procedure within Blackboard.

Deadline:

23.59 of Monday, December 5, 2011

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 the autograder. However, the correctness of your implementation -- not the autograder's output -- will be the final judge of your score.

The grade serves only as a form of feedback and it will not be used for the final grade that depends only by the written exam. For this assignment: if you make an honest effort at some of the questions you will pass, otherwise fail. The accomplishment of the first 2 questions is a sufficient condition to pass the assignment. The remaining questions are optional.

Getting Help: You are not alone! If you find yourself stuck on something, ask your colleagues or contact the teacher for help. He doesn't know when or how to help unless you ask. But in any case do not ask for code, ask only verbal help. You must implement the required procedures yourself. One more piece of advice: if you don't know what a variable does or what kind of values it takes, print it out.


Ghostbusters and BNs

In this version of Ghostbusters, the goal is 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.

 python busters.py

The blocks of color indicate where the 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 -s shows where the ghost actually is.

  python busters.py -s -k 1

Naturally, 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 BustersKeyboardAgent in bustersAgents.py uses the ExactInference module in inference.py to track ghosts.

Question 1 (3 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.

Hints:

Ghosts don't hold still forever. Fortunately, your agent has access to the action distribution for any GhostAgent. Your next task is to use the ghost's move distribution to update your agent's beliefs when time elapses.

Question 2 (4 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

Hints:

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

Now, pacman is ready to hunt down ghosts on his own. You will implement a simple greedy hunting strategy, where Pac-Man assumes that each ghost is in its most likely position according to its beliefs, then moves toward the closest ghost.

Question 3 (4 points) Implement the chooseAction method in GreedyBustersAgent in bustersAgents.py. Your agent should first find the most likely position of each remaining (uncaptured) ghost, then choose an action that minimizes the distance to the closest ghost. If correctly implemented, your agent should win smallHunt with a score greater than 700 at least 8 out of 10 times.

  python busters.py -p GreedyBustersAgent -l smallHunt
Hints:

Approximate Inference

Approximate inference is very trendy among ghost hunters this season. Next, you will implement a particle filtering algorithm for tracking a single ghost.

Question 4 (5 points) Implement all necessary methods for the ParticleFilter class in inference.py. When complete, you should be able to track ghosts nearly as effectively as with exact inference. This means that your agent should win oneHunt with a score greater than 100 at least 8 out of 10 times.

  python busters.py -k 1 -s -a inference=ParticleFilter
Hints:

That's it for this assignment. But if you really did not get enough yet, you may look at the part commented out from the source of this .html page.