from Predicate import * class AndPredicate(LogicPredicate): '''performs an n-way boolean AND on the list of predicates''' def holds(self, board, coordinates): for predicate in self.predicateList: if not predicate.holds(board, coordinates): 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, board, coordinates): for predicate in self.predicateList: if predicate.holds(board, coordinates): 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, board, coordinates): return not self.Predicate.holds(board, coordinates) def __str__(self): return ''.join(["(NOT ", self.Predicate.__str__(), ")"])