def buildGoal(self, e, pos, relation, restriction): ''' create a goal based on a pair of objects or lists of objects by adding relations to a new goal''' ori,dst,q = e if isinstance(ori, basestring): ori = [ori] if isinstance(dst, basestring): dst = [dst] g = Goal() if restriction and (restriction[0] not in ori + dst): g.addRestriction(restriction[0],restriction[1]) if q == 'any' and "".join(sorted(ori)) == "".join(sorted(dst)): dst.pop() for o in ori: if q == 'any': n_dst = copy.deepcopy(dst) nn_dst = copy.deepcopy(n_dst) for d in n_dst: if d == o or not Physics().checkPhysicalLaws(o, d, relation, False): nn_dst.remove(d) if len(nn_dst) > 0: g.addRelation(o,nn_dst,pos) else: for d in dst: if d == o or not Physics().checkPhysicalLaws(o, d, relation, False): return None g.addRelation(o,d,pos) if not len(g.relations): return None return g