from zerolife import * class Species (): def __init__(self, name): self.name = name self.color = None self.rules = [] def addRule(self, rule, index=None): '''Places a rule in the list in a user selected place. This is given as an index.''' if index: self.rules.insert(rule, index) else: self.rules.append(rule) def removeRule(self, rule): '''Removes a rule from the list.''' try: self.rules.remove(rule) except Exception as e: pass def next(self, board, coordinates): '''Examines each rule in sequence and returns the instruction for the first one that evaluates to true. If no rule evaluates to true, a stay instruction is returned.''' for r in rules: if r.holds(board, coordinates): return r.getInstructions(coordinates) '''Calls Instruction constructor to make a new instruction object with the parameters that result in stay.''' return [Instruction.Instruction(direction.C, self, coordinates)]