This site applies only to CMPT 120 D1 (Burnaby) in Summer 2011. See the other instructors' pages for other sections.
The Module
You will probably want to import it with from cmptman import *
(instead of import cmptman
) since you'll be using items from the module so often. You won't want to have to constantly type “cmptman.
”.
To get you started working with the module, you have have a look at example CMPTman program. The ghosts in this program don't do anything particularly useful (and might sometimes fall off the board or hit a block), but at least they do something.
Suggested Plan
The real assignment here is to come up with the best algorithm(s) you can for this problem. The program itself is just an implementation of your algorithm, so there's no real “plan” that can be given for your program. There are a few things you can do to start working on an algorithm.
- Start by working on an algorithm for boards with no blocks in the way. That way there's nothing to hit: just come up with an algorithm that moves the ghost in the general direction of CMPTman. Make sure your algorithm never allows the ghosts to fall off the board.
- Try your ghosts on a board with a few blocks in the way. Modify your code so they don't run into the blocks (but perhaps get stuck behind them).
- Once you have that working, try the game with some more of the example boards. Ask yourself: what is it that the ghosts could do to make the game more challenging? Some ideas:
- You can use different algorithms (very different or slight modifications) for the different ghosts.
- The ghosts don't necessarily have to head only towards CMPTman. Maybe some of them hang around the dots waiting for CMPTman, or are scared of the other ghosts, or …
- It would be nice if the ghosts could find their way out of corners and around obstacles.
- Perhaps the ghosts (or some of the ghosts) should try to guess where CMPTman is going and head there, not for where it is right now.
- One restriction: it's totally boring to have a ghost just sit on a dot so CMPTman can never finish. Think of something better.
- Don't be discouraged if your ghosts are a little clumsy, or if the game is easy on boards that are slanted towards CMPTman (lots of corners to get stuck in, few ghosts, few dots). Making the ghosts “smart” is quite difficult.
Notice that there's relatively little programming in the above list. Most of your time on this assignment can (and maybe should) be away from the computer.
Directions
The four compass directions you get from the module aren't necessarily easy to work with, depending what you're doing.
How you handle this problem will depend the nature of your algorithm(s). One
suggestion is to write a towards
function. That is, a function
that can be given the position of CMPTman, and a ghost. It should return
one of N
, E
, S
, W
: a
direction that will get the ghost closer to CMPTman.