Download Tagger.py from the class web page:
It contains code very similar to Wanderer.py from Homework 2.
You might find that it makes more sense now :)
The object of this homework is to make the turtles play tag.
When the program starts, it will choose one of the turtles to
be `it'. This turtle will chase the others, and when it catches
one, it tags the other turtle. The other turtle becomes `it,'
and the game proceeds.
Some additional rules are:
- Turtles have to stay in bounds. You can use an algorithm
like what you used on Homework 2.
- After a turtle is tagged, it has to sulk for a while before
it can start chasing the other turtles.
- It should be possible, eventually, for the slow turtle to
tag the faster turtles.
Here are some suggestions for methods you might want to have in
the Tagger class:
- Compute the distance to another turtle.
- Turn toward another turtle. HINT: see the documentation
- Find the closest other turtle. Note: the World object
has an attribute named animals that is a list of all the
Turtles currently in the world.
- Tag another turtle.
- Change color (maybe the turtle who is `it' should be red and
a sulking turtle should be blue).
WARNING: Turtles already have an attribute named tag, so
you should not create a method named tag.