We now have some great offensive troops to help vanquish the bees, but let's make sure we're also keeping our defensive efforts up. In this phase you will implement ants that have special defensive capabilities such as increased armor and the ability to protect other ants.
# BEGIN Problem 8# The WallAnt classclassWallAnt(Ant): name ='Wall' food_cost =4 implemented =Truedef__init__(self,armor=4): self.armor = armor# END Problem 8
classBodyguardAnt(Ant):"""BodyguardAnt provides protection to other Ants.""" name ='Bodyguard' food_cost =4 is_container =True# OVERRIDE CLASS ATTRIBUTES HERE# BEGIN Problem 9 implemented =True# Change to True to view in the GUI# END Problem 9def__init__(self,armor=2): Ant.__init__(self, armor) self.contained_ant =None# The Ant hidden in this bodyguarddefcan_contain(self,other):# BEGIN Problem 9"*** YOUR CODE HERE ***"returnnot other.is_container andnot self.contained_ant# END Problem 9defcontain_ant(self,ant):# BEGIN Problem 9"*** YOUR CODE HERE ***" self.contained_ant = ant# END Problem 9defaction(self,colony):# BEGIN Problem 9"*** YOUR CODE HERE ***"if self.contained_ant: self.contained_ant.action(colony)# END Problem 9
classTankAnt(BodyguardAnt):"""TankAnt provides both offensive and defensive capabilities.""" name ='Tank' damage =1 food_cost =6# OVERRIDE CLASS ATTRIBUTES HERE# BEGIN Problem 10 implemented =False# Change to True to view in the GUI# END Problem 10defaction(self,colony):# BEGIN Problem 10"*** YOUR CODE HERE ***" bees =list(colony.bees)for bee in bees: Insect.reduce_armor(bee, self.damage)if self.contained_ant: self.contained_ant.action(colony)# END Problem 10