CMPT 120 Assignment 4 Hints

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 robotlib import * (instead of import robotlib) since you'll be using items from the module so often. You won't want to have to constantly type “robotlib.”.

To get you started working with the module, you have have a look at example robot program. The robot in this program doesn't do anything particularly useful (and might sometimes fall off the board or hit a block), but at least it does something.

Suggested Plan

The real assignment here is to come up with the best algorithm 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.

  1. Start by working on an algorithm for boards with no blocks. That way there's nothing to hit: just come up with an algorithm that takes you around the board enough that you can see and grab each coin. Make sure your algorithm never allows the robot to fall off the board.
  2. Try the problem with one block on the board. Try it assuming that the block is not on the outside of the board, so you can freely cruise around the outside board, looking for coins. Make sure you test with coins on the same row and column as the block. Make sure your algorithm never lets the robot run into the block.
  3. Now, try to modify your algorithm so it also works for any two or three blocks on the board. Again, you might want to assume that none of the blocks are on the edges of the board.
  4. There are many ways to attack the problem after this (and even before). Try some stuff: try to come up with a method that will let you avoid obstacles and still find your way around the board.
  5. Don't be discouraged if you can't “finish” this problem. It's hard and if more than a couple of students produce an algorithm that works in general, I'll be surprised. [I'd be surprised if the TAs got it without some pain.]

Notice that there's relatively little programming in the above list. Most of your time on this assignment can (and 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.

You can do something like this:

directions = [N, E, S, W]

for d in directions:     # check the sensor in direction d (or whatever you need done)
    

You can also consider creating functions that take a direction and give you back the value you really need. For example,

You can then have the robot spin in a circle like this:

d = N
while True:
    r.move(d)
    d = right(d)