## Creature Project ## CSC323: Group 1: Nora, Terian, Josh, and Jordan ## 4/7/10 ## QuantityPredicate.py: Checks that neighbors match in species and quantity. ###Borrowed code from Group 0 from Predicate import * '''the rules for a QuantityPredicate are the desiredSpecies and desiredNum.''' class QuantityPredicate(TestPredicate): """holds takes as parameters the localworld and the location of the creature being tested""" """checks whether the neighbors surrounding the creature at location match self.desiredSpecies, and that they number no more or less than self.desiredNum""" def holds(self, world, location): neighborcount = 0 x = location[0] y = location[1] for i in (x-1,x,x+1): for j in (y-1,y,y+1): if not (x==i and y==j): if (self.desiredSpecies == None) | (world.getCreature(i, j).getSpecies() == self.desiredSpecies): neighborcount++ if not neighborcount == self.desiredNum: return False return True def __str__(self): #to do: pull out self.desiredNum and self.desiredSpecies, and use these to define the string