Due Saturday, 2012-02-18, 11:59pm
In this homework, you will practice using while loops and working with sequences.
You will submit one file, called <lastname>_hw4.py.
Remember to include your name and the assignment number in a comment at the top of the file
and to use lots of comments in your code, including docstrings for all functions that you define.
For this assignment, our diskoid lives in a world with pentoids (predators) and plasmoids (food), as well as other diskoids.
It has six feelers arranged around its body every 60 degrees, starting from its heading (the "mouth" in the figure).
When it activates its feelers, they return a list of 6 integers, each representing what it feels at one position: 1 represents a pentoid, 2 another diskoid, 3 a plasmoid, and 0 nothing.
The integers are ordered in a counterclockwise direction, starting with the heading.
For example, the list returned by the feelers of the diskoid in the center of the first figure would be
[0, 1, 1, 2, 3, 3]
and for the diskoid in the center of the second figure would be
[0, 0, 3, 0, 3, 3].
In response to what its feelers sense, the diskoid does the following:
count_things, which takes a list that would be returned by the diskoid's sensors and returns a list recording how many pentoids, diskoids, and plasmoids are felt (in that order).
For example, for the situations shown in the two figures, the function would do the following:
>>> count_things([0, 1, 1, 2, 3, 3]) [2, 1, 2] >>> count_things([0, 0, 3, 0, 3, 3]) [0, 0, 3]
eat, which takes a list that would be returned by the diskoid's sensors, prints out the turns that the diskoid executes in order to eat the plasmoids, and removes
the eaten plasmoids from the list. The function returns nothing.
For example, for the situation shown in the second figure, the function would do the following:
>>> felt_things = [0, 0, 3, 0, 3, 3] >>> eat(felt_things) Turned 120 degrees to eat Turned 120 degrees to eat >>> felt_things [0, 0, 0, 0, 0, 3]
respond, which takes a list that would be returned by the diskoid's sensors, prints out what the diskoid does, and returns the original list, possibly changed (if one or more plasmoids were eaten).
The definition of respond should make use of both count_things and eat.
Here is what respond would do in the situations in the two figures and a third situation like the first but with only one pentoid:
>>> respond([0, 1, 1, 2, 3, 3]) Camouflaged [0, 1, 1, 2, 3, 3] >>> respond([0, 0, 3, 0, 3, 3]) Turned 120 degrees to eat Turned 120 degrees to eat [0, 0, 0, 0, 0, 3] >>> respond([0, 1, 0, 2, 3, 3]) Primped [0, 1, 0, 2, 3, 3]