Advertisement
proffreda

Python Prototypes for Ants versus Somebees

Mar 23rd, 2016
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.75 KB | None | 0 0
  1. #Prototypes for Ants versus Somebees
  2.  
  3. class Place(object):
  4.     """A Place holds insects and has an exit to another Place."""
  5.  
  6.     def __init__(self, name, exit=None):
  7.         """Create a Place with the given exit.
  8.        name -- A string; the name of this Place.
  9.        exit -- The Place reached by exiting this Place (may be None).
  10.        """
  11.  
  12.     def add_insect(self, insect):
  13.         """Add an Insect to this Place. There are game limits on whether insect
  14.        types can be added.
  15.        """
  16.  
  17.     def remove_insect(self, insect):
  18.         """Remove an Insect from this Place.
  19.        """
  20.      
  21. class Insect(object):
  22.     """An Insect, the base class of Ant and Bee, has armor and a Place.
  23.    """
  24.  
  25.     def __init__(self, armor, place=None):
  26.         """Create an Insect with an armor amount and a starting Place.
  27.        """
  28.        
  29.     def reduce_armor(self, amount):
  30.         """Reduce armor by amount, and remove the insect from its place if it
  31.        has no armor remaining.
  32.        """
  33.        
  34.     def action(self, colony):
  35.         """The action performed each turn.
  36.        Uses the AntColony (colony), used to access game state information.
  37.        """
  38.  
  39.   """ Test
  40.        >>> test_insect = Insect(5)
  41.        >>> test_insect.reduce_armor(2)
  42.        >>> test_insect.armor
  43.        3
  44.  """
  45.  
  46. class Bee(Insect):
  47.     """A Bee moves from place to place, following exits and stinging ants.
  48.    """
  49.  
  50.     def sting(self, ant):
  51.         """Attack an Ant, reducing the Ant's armor by 1.
  52.        """
  53.  
  54.     def move_to(self, place):
  55.         """Move from the Bee's current Place to a new Place.
  56.        """
  57.        
  58.     def blocked(self):
  59.         """Return True if this Bee cannot advance to the next Place.
  60.        """    
  61.  
  62.     def action(self, colony):
  63.         """A Bees action stings the Ant that blocks its exit if it is blocked
  64.        """
  65.  
  66. class Ant(Insect):
  67.     """An Ant occupies a place and does work for the colony.
  68.    """
  69.  
  70.     def __init__(self, armor=1):
  71.         """Create an Ant with an armor quantity."""
  72.        
  73.  
  74.  
  75. class HarvesterAnt(Ant):
  76.     """HarvesterAnt produces 1 additional food per turn for the colony.
  77.    """
  78.  
  79.     def action(self, colony):
  80.         """Produce 1 additional food for the colony.
  81.        """
  82.  
  83. class ThrowerAnt(Ant):
  84.     """ThrowerAnt throws a leaf each turn at the nearest Bee in its range.
  85.    """
  86.  
  87.     def nearest_bee(self, hive):
  88.         """Return the nearest Bee in a Place that is not the Hive, connected to
  89.        the ThrowerAnt's Place by following entrances.
  90.        """
  91.  
  92.     def throw_at(self, target):
  93.         """Throw a leaf at the target Bee, reducing its armor.
  94.        """
  95.        
  96.     def action(self, colony):
  97.         """Throw a leaf at the nearest Bee in range."""
  98.         self.throw_at(self.nearest_bee(colony.hive))
  99.  
  100.  
  101. class Wasp(Bee):
  102.     """Class of Bee that has higher damage.
  103.    """
  104.  
  105. class Boss(Wasp, Hornet):
  106.     """The leader of the bees. Combines the high damage of the Wasp along with
  107.    status effect immunity of Hornets. Damage to the boss is capped.
  108.    """
  109.    
  110. class Hive(Place):
  111.     """The Place from which the Bees launch their assault.
  112.  
  113.    assault_plan -- An AssaultPlan; when & where bees enter the colony.
  114.    """
  115.     def __init__(self, assault_plan):
  116.  
  117.        
  118. class AntColony(object):
  119.     """An ant collective that manages global game state and simulates time.
  120.  
  121.    Attributes:
  122.    time -- elapsed time
  123.    food -- the colony's available food total
  124.    queen -- the place where the queen resides
  125.    places -- A list of all places in the colony (including a Hive)
  126.    bee_entrances -- A list of places that bees can enter
  127.    """
  128.  
  129.     def __init__(self, strategy, hive, ant_types, create_places, dimensions, food=2):
  130.         """Create an AntColony for simulating a game.
  131.  
  132.        Arguments:
  133.        strategy -- a function to deploy ants to places
  134.        hive -- a Hive full of bees
  135.        ant_types -- a list of ant constructors
  136.        create_places -- a function that creates the set of places
  137.        dimensions -- a pair containing the dimensions of the game layout
  138.        """
  139.        
  140.     def configure(self, hive, create_places):
  141.         """Configure the places in the colony.
  142.        """
  143.        
  144.     def simulate(self):
  145.         """Simulate an attack on the ant colony (i.e., play the game).
  146.        """
  147.  
  148. class AssaultPlan(dict):
  149.     """The Bees' plan of attack for the Colony.  Attacks come in timed waves.
  150.  
  151.    An AssaultPlan is a dictionary from times (int) to waves (list of Bees).
  152.  
  153.    >>> AssaultPlan().add_wave(4, 2)
  154.    {4: [Bee(3, None), Bee(3, None)]}
  155.    """
  156.  
  157.     def add_wave(self, bee_type, bee_armor, time, count):
  158.         """Add a wave at time with count Bees that have the specified armor."""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement