## Creature Project ## CSC323 ## 4/17/10 ## Instruction.py: Initializes and packs instructions for Species. import Direction class Instruction: """An instruction is basically just an object that tells the cell adjacent in the (given) direction to change to the (given) species.""" def __init__(self, direction, species, coordinates=(0,0)): """The optional coordinates parameter is for the pack method.""" self.direction = direction self.species = species self.coords = coordinates def pack(self, coordinates): """Packs an instruction object with the coordinates given. A packed instruction is just an instruction for the cell it is meant to change (current cell modified by direction of action). A packed instruction's direction should never be used, although I changed it to C (current cell) for purposes of logic.""" self.coords = coordinates return Instruction(Direction.C, self.species,\ (self.coords[0]+self.direction.x, self.coords[1]+self.direction.y)) def __str__(self): """Returns the direction as a string.""" s = "Direction =" + str(self.direction) + "Species = " + \ str(self.species) + "Coords = (" + str(self.coords[0]) + ", " + \ str(self.coords[1]) + ")" return s def save_the_instruction(self): """Saves the instruction as savedRule""" savedRule = "I(D:" + str(self.direction) + " S:" +str(self.species) + \ " C:(" + str(self.coords[0]) + "," + str(self.coords[1]) + "))" return savedRule