## Creature Project ## CSC323: Group 1: Nora, Terian, Josh, and Jordan ## 4/7/10 ## LogicPredicate.py: Checks and/or/not. ###Borrowed code from Group 0 from Predicate import * class AndPredicate(LogicPredicate): '''performs an n-way boolean AND on the list of predicates''' def holds(self, world, location): for predicate in self.predicateList if not predicate.holds(world, location): return False return True def __str__(self): return ''.join("(AND ",' '.join((pl.__str__() for pl in \ self.predicateList)), ")") class OrPredicate(LogicPredicate): '''performs an n-way boolean OR on the list of predicates''' def holds(self, world, location): for predicate in self.PredicateList if predicate.holds(world, location): return True return False def __str__(self): return ''.join("(OR",' '.join((pl.__str__() for pl in \ self.predicateList)), " )") class NotPredicate(LogicPredicate): '''inverts the result of its child predicate''' def __init__(self, pred): self.Predicate = pred def holds(self, world, location): return not self.Predicate.holds(world, location) def __str__(self): return ''.join("(NOT ", self.Predicate.__str__(), " )")