chameleon.py: 8 points
|fighting behavior||starts with |
|color||starts as |
|movement behavior||if the chameleons have lost the majority of their fights so far, then use avoidance. Otherwise, move towards opponents|
Unlike other critters,
Chameleon’s think as a “species” when it comes to fighting and moving. However, each chooses their color independently.
Chameleon will use the strategy that beats (and thus is different from) the most common attack used on chameleons. This should imply to you that the species (i.e., class) as a whole should keep information about how often each strategy is used against any chameleon and play the counter-strategy to the most-used one.
How might you keep track of such information? Well, the
Critter superclass has a
recover() method that is called by the game but is not implemented yet. At the end of each and every battle, the game calls
recover() for each critter and passes a boolean called
won that indicates whether the critter won the battle and a constant called
opp_attack indicating the opponent’s fighting strategy (
constants.SCRATCH). You should implement the
recover() method in your critter to gain access to and use these parameters. Keep in mind that you should not change the input parameters for
recover() because they are controlled by the game.
Remember to periodically commit and push your changes.
Chameleon’s movement strategy is based on the species’ overall success rate. If the species is not doing well (i.e., the species has lost at least half the total number of battles), a chameleon will try to avoid other critters. On the other hand, if the species is doing well, then a chameleon will become aggressive and move towards other critters.
To determine where to move, you should make use of the
neighbor_threat() method. Given two parameters, the current chameleon’s
self_info and a constant
neighbor_threat() returns the total number of other critters in that given direction. For instance, if there are critters to the southwest and southeast of the current
neighbor_threat(self_info, constants.SOUTH) will return 2. Although
neighbor_threat() includes other critters on the diagonals, a reminder that critters themselves can only move in cardinal directions. Finally, you get to decide how to handle the movement decision in the case of a tie.
neighbor_threat() has been implemented for you in the
Critter superclass. There is no need to re-implement this method yourself. Instead, use the
neighbor_threat() method that has been inherited by
Chameleons should start out as
constants.GREEN. However, one of the ways
Chameleons differentiate themsleves from other
Chameleons is by emulating the appearance of its most recent (losing) opponent by display the opponent’s color. A reminder this is information you can get from the fight methods’
opp_info parameter. So, if one
Chameleon beats an
Elephant, it will become
constants.GRAY on the next turn, but no other
Chameleons will change their color as a result of this fight.
Please commit and push your changes before moving on.