Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Prototypes for Ants versus Somebees
- class Place(object):
- """A Place holds insects and has an exit to another Place."""
- def __init__(self, name, exit=None):
- """Create a Place with the given exit.
- name -- A string; the name of this Place.
- exit -- The Place reached by exiting this Place (may be None).
- """
- def add_insect(self, insect):
- """Add an Insect to this Place. There are game limits on whether insect
- types can be added.
- """
- def remove_insect(self, insect):
- """Remove an Insect from this Place.
- """
- class Insect(object):
- """An Insect, the base class of Ant and Bee, has armor and a Place.
- """
- def __init__(self, armor, place=None):
- """Create an Insect with an armor amount and a starting Place.
- """
- def reduce_armor(self, amount):
- """Reduce armor by amount, and remove the insect from its place if it
- has no armor remaining.
- """
- def action(self, colony):
- """The action performed each turn.
- Uses the AntColony (colony), used to access game state information.
- """
- """ Test
- >>> test_insect = Insect(5)
- >>> test_insect.reduce_armor(2)
- >>> test_insect.armor
- 3
- """
- class Bee(Insect):
- """A Bee moves from place to place, following exits and stinging ants.
- """
- def sting(self, ant):
- """Attack an Ant, reducing the Ant's armor by 1.
- """
- def move_to(self, place):
- """Move from the Bee's current Place to a new Place.
- """
- def blocked(self):
- """Return True if this Bee cannot advance to the next Place.
- """
- def action(self, colony):
- """A Bees action stings the Ant that blocks its exit if it is blocked
- """
- class Ant(Insect):
- """An Ant occupies a place and does work for the colony.
- """
- def __init__(self, armor=1):
- """Create an Ant with an armor quantity."""
- class HarvesterAnt(Ant):
- """HarvesterAnt produces 1 additional food per turn for the colony.
- """
- def action(self, colony):
- """Produce 1 additional food for the colony.
- """
- class ThrowerAnt(Ant):
- """ThrowerAnt throws a leaf each turn at the nearest Bee in its range.
- """
- def nearest_bee(self, hive):
- """Return the nearest Bee in a Place that is not the Hive, connected to
- the ThrowerAnt's Place by following entrances.
- """
- def throw_at(self, target):
- """Throw a leaf at the target Bee, reducing its armor.
- """
- def action(self, colony):
- """Throw a leaf at the nearest Bee in range."""
- self.throw_at(self.nearest_bee(colony.hive))
- class Wasp(Bee):
- """Class of Bee that has higher damage.
- """
- class Boss(Wasp, Hornet):
- """The leader of the bees. Combines the high damage of the Wasp along with
- status effect immunity of Hornets. Damage to the boss is capped.
- """
- class Hive(Place):
- """The Place from which the Bees launch their assault.
- assault_plan -- An AssaultPlan; when & where bees enter the colony.
- """
- def __init__(self, assault_plan):
- class AntColony(object):
- """An ant collective that manages global game state and simulates time.
- Attributes:
- time -- elapsed time
- food -- the colony's available food total
- queen -- the place where the queen resides
- places -- A list of all places in the colony (including a Hive)
- bee_entrances -- A list of places that bees can enter
- """
- def __init__(self, strategy, hive, ant_types, create_places, dimensions, food=2):
- """Create an AntColony for simulating a game.
- Arguments:
- strategy -- a function to deploy ants to places
- hive -- a Hive full of bees
- ant_types -- a list of ant constructors
- create_places -- a function that creates the set of places
- dimensions -- a pair containing the dimensions of the game layout
- """
- def configure(self, hive, create_places):
- """Configure the places in the colony.
- """
- def simulate(self):
- """Simulate an attack on the ant colony (i.e., play the game).
- """
- class AssaultPlan(dict):
- """The Bees' plan of attack for the Colony. Attacks come in timed waves.
- An AssaultPlan is a dictionary from times (int) to waves (list of Bees).
- >>> AssaultPlan().add_wave(4, 2)
- {4: [Bee(3, None), Bee(3, None)]}
- """
- def add_wave(self, bee_type, bee_armor, time, count):
- """Add a wave at time with count Bees that have the specified armor."""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement