Part A: Adapting your Movement

In this lab, you will be designing autonomous “animals” (called critters) that will compete in a simulation. You’ll be programming how they move and fight with each other. Often, the behavior of your critters will be repetitive: they’ll move north and then east, or in circles, or attack according to some pattern. Sound familiar? In fact, your critters can use modified versions of your RepeatMove and ContinueMove classes from last week’s lab!

In this part of the Warmup, you’ll adapt RepeatMove and ContinueMove to work in the critter context. Follow the steps below.

  1. Copy over your RepeatMove and ContinueMove classes you made in lab 7 to the repeat.py and cmove.py files in your Lab 8 repository. If you are still working on Lab 7, please stop here and allow your Warmup partner to move ahead!
  2. You may have noticed that ContinueMove is a variation of RepeatMove. Let’s take this opportunity to practice inheritance syntax! In your Lab 8 repository, adapt ContinueMove to inherit from RepeatMove and update the constructor method accordingly. You’ll probably want to include a call to super() somewhere in there…
  3. Remember to describe your modifications to the ContinueMove class design in WARMUP.md.

Great! Now your previous move classes are all set for use with Critter. Next you’ll make one more move class.


Commit and push your changes before moving on.

Part B: Turning It Around

In Part A we practiced adapting an existing class from its own implementation into an inherited version. In this part of the Warmup, we’ll write an inherited class from scratch.

Our goal will be to program a subclass of RepeatMove which we will call OppositeRepeatMove. An OppositeRepeatMove will have the same methods and attributes as a RepeatMove and should inherit from it.

The only thing that will be different in OppositeRepeatMove is the constructor (__init__ method). An OppositeRepeatMove instance should move backwards through the list of values provided, starting at the last element and moving to the element before until the first element, and then looping back around. How can you modify the list of elements passed in to __init__ such that when you call next() from the RepeatMove class (which moves forward in self.moves) it goes in the opposite order? (Hint: think about reversing moves!).

  1. In the file opposite.py, implement the OppositeRepeatMove class. Remember all you should do is add code for __init__. Think about how you can use inheritance to gain access to the next() method from the RepeatMove class. Then, assuming that next() will move forward in self.moves, how can you set the value of self.moves accordingly.
  2. Add some code to the main() function to test your class. Feel free to reuse some of your test code from the RepeatMove class.
  3. Remember to describe your work with OppositeRepeatMove in WARMUP.md.


You are strongly encouraged to make use of RepeatMove, OppositeRepeatMove, and/or ContinueMove when completing the lab itself. It will make the solutions shorter to write. However, if you run into issues or bugs with your implementations—don’t worry! You can complete the lab without relying on these classes.


Commit and push your changes when you finish with the warmup.