In the first phase you will complete the implementation that will allow for basic gameplay with the two basic Ants: the HarvesterAnt and the ThrowerAnt.
Now that you've implemented basic gameplay with two types of Ants, let's add some flavor to the ways ants can attack bees. In this phase, you'll be implementing several different Ants with different offensive capabilities.
classHarvesterAnt(Ant):"""HarvesterAnt produces 1 additional food per turn for the colony.""" name ='Harvester' implemented =True food_cost =2defaction(self,colony):"""Produce 1 additional food for the COLONY. colony -- The AntColony, used to access game state information. """"*** YOUR CODE HERE ***" colony.food +=1
classPlace(object):"""A Place holds insects and has an exit to another Place."""def__init__(self,name,exit=None):"""Create a Place with the given NAME and EXIT. name -- A string; the name of this Place. exit -- The Place reached by exiting this Place (may be None). """ self.name = name self.exit =exit self.bees = [] # A list of Bees self.ant =None# An Ant self.entrance =None# A Place# Phase 1: Add an entrance to the exit# BEGIN Problem 2"*** YOUR CODE HERE ***"if self.exit: self.exit.entrance = self# END Problem 2
classThrowerAnt:... ... ... defnearest_bee(self,hive):"""Return the nearest Bee in a Place that is not the HIVE, connected to the ThrowerAnt's Place by following entrances. This method returns None if there is no such Bee (or none in range). """# BEGIN Problem 3 and 4 curr_place = self.first_place_in_range(self.min_range) distance =0 bee_place =Nonewhile curr_place and curr_place != hive and distance <= self.max_range:if curr_place.bees: bee_place = curr_placebreak curr_place = curr_place.entrance distance +=1if bee_place:returnrandom_or_none(bee_place.bees)else:return bee_place# END Problem 3 and 4
classFireAnt(Ant):"""FireAnt cooks any Bee in its Place when it expires.""" name ='Fire' food_cost =5 damage =3# OVERRIDE CLASS ATTRIBUTES HERE# BEGIN Problem 5 implemented =True# Change to True to view in the GUI# END Problem 5defreduce_armor(self,amount):"""Reduce armor by AMOUNT, and remove the FireAnt from its place if it has no armor remaining. If the FireAnt dies, damage each of the bees in the current place. """# BEGIN Problem 5"*** YOUR CODE HERE ***" self.armor -= amount bees =list(self.place.bees)#ant dies, remove from place and damage all bees in its placeif self.armor <=0: self.place.remove_insect(self)for bee in bees: Insect.reduce_armor(bee, self.damage)# END Problem 5
classHungryAnt(Ant):"""HungryAnt will take three turns to digest a Bee in its place. While digesting, the HungryAnt can't eat another Bee. """ name ='Hungry' food_cost =4 time_to_digest =3 implemented =True# Change to True to view in the GUIdef__init__(self,armor=1): self.armor = armor self.digesting =0defeat_bee(self,bee): Insect.reduce_armor(bee, bee.armor) self.digesting = self.time_to_digestdefaction(self,colony):# BEGIN Problem 6if self.digesting >0: self.digesting -=1returnNone random_bee =random_or_none(self.place.bees)if random_bee: self.eat_bee(random_bee)
classNinjaAnt(Ant):"""NinjaAnt does not block the path and damages all bees in its place.""" name ='Ninja' food_cost =5 damage =1 blocks_path =False implemented =True# Change to True to view in the GUIdefaction(self,colony): bees =list(colony.bees)for bee in bees: Insect.reduce_armor(bee, self.damage)