Problem 2 (200pts): Build Tunnel
In this problem, you'll complete Place.__init__
by adding code that tracks entrances.
Right now, a Place
keeps track only of its exit.
We would like a Place
to keep track of its entrance as well.
A Place
needs to track only one entrance
.
Tracking entrances will be useful when an Ant
needs to see what Bee
s are in front of it in the tunnel.
However, simply passing an entrance to a Place
constructor will be problematic;
we would need to have both the exit and the entrance before creating a Place
!
(It's a chicken or the egg problem.)
To get around this problem, we will keep track of entrances in the following way instead.
Place.__init__
should specify that:
- A newly created
Place
always starts with itsentrance
asNone
. - If the
Place
has anexit
, then theexit
'sentrance
is set to thatPlace
.
Hint 1: Remember that when the
__init__
method is called, the first parameter,self
, is bound to the newly created object.Hint 2: Try drawing out two
Place
s next to each other if things get confusing. In the GUI, a place'sentrance
is to its right while theexit
is to its left.Hint 3: Remember that Places are not stored in a list, so you can't index into anything to access them. This means that you can't do something like
colony[index + 1]
to access an adjacent Place. How can you move from one place to another?
Before writing any code, unlock the tests to verify your understanding of the question:
$ python ok -q 02 -u
Once you are done unlocking, begin implementing your solution. You can check your correctness with:
$ python ok -q 02