## Creature Project ## CSC323: Group 1: Nora, Terian, Josh, and Jordan ## 4/7/10 ## species.py: Contains methods associated with the class Species. #NOTE, 4/14/10: Currently no enumerated type State. spec is a string. from rule import Rule class Species: """Name and rules associated with creatures of a particular species""" def __init__(self, spec): """Initializes a species object.""" #ensure spec is an element of the enumerated type State self.name = spec self.rules = [] def addRule(self, rule): """Adds a Rule object to the list of rules""" self.rules.append(rule) def next(self, world, location): """Returns list of instructions for next step based on rules, loc""" changes = [] for nextRule in self.rules: if nextRule.apply(world, location): changes.append(nextRule.nextMove) return changes #what will happen when multiple rules hold true, and conflict? #will some other class handle conflicts? def toString(self): """Returns a string object representing the species.""" def fromString(self, newspecies): """Resets itself from a string object representing the species.""" def __str__(self): """Returns a string representation""" return self.name