def test_propose_link(self): """ Proposing a value doesn't officially make an assignment. If the Swede keeps a bird then no one else can. If the Swede doesn't live in that house then neither can the bird. """ # Proposing a value with no assignments made won't change state new_state = deepcopy(einstein.START_STATE) new_state = einstein.propose_link('nationality', 'swedish', 'pet', 'bird', new_state) self.assertEqual(new_state, einstein.START_STATE) # The norweigen cannot own a bird, because the swede does. new_state = einstein.assign_value('1', 'nationality', 'norweigen', new_state) new_state = einstein.propose_link('nationality', 'swedish', 'pet', 'bird', new_state) self.assertNotIn('bird', new_state['1']['pet']) # If house 3 owns a horse then the swede cannot live there, because he owns a bird. new_state = einstein.assign_value('3', 'pet', 'horse', new_state) new_state = einstein.propose_link('nationality', 'swedish', 'pet', 'bird', new_state) self.assertNotIn('swedish', new_state['3']['nationality'])
def the_person_who_is(predicate, with_this, new_predicate, assign_this, state): """ If the person matches a predicate then assing another predicate. eg. The brit lives in a red house. If you find a brit assign the house red. Else if you find a red house assign the brit. Else propose the following If a house has no british posibilities remove red. If a house has no red possibilities remove british. :param str predicate: The predicate we are looking for. :param str with_this: Value to search with. :param str predicate: The predicate we will asign. :param str assign_this: Value to assign. :param dict state: The current state of the universe. """ house_is_this = einstein.get_position(with_this, state) house_assigned_this = einstein.get_position(assign_this, state) if house_is_this and house_assigned_this: return state elif house_is_this: return einstein.assign_value(house_is_this, new_predicate , assign_this, state) elif house_assigned_this: return einstein.assign_value(house_assigned_this, predicate, with_this, state) else: return einstein.propose_link(predicate, with_this, new_predicate, assign_this, state)
def the_person_who_is(predicate, with_this, new_predicate, assign_this, state): """ If the person matches a predicate then assing another predicate. eg. The brit lives in a red house. If you find a brit assign the house red. Else if you find a red house assign the brit. Else propose the following If a house has no british posibilities remove red. If a house has no red possibilities remove british. :param str predicate: The predicate we are looking for. :param str with_this: Value to search with. :param str predicate: The predicate we will asign. :param str assign_this: Value to assign. :param dict state: The current state of the universe. """ house_is_this = einstein.get_position(with_this, state) house_assigned_this = einstein.get_position(assign_this, state) if house_is_this and house_assigned_this: return state elif house_is_this: return einstein.assign_value(house_is_this, new_predicate, assign_this, state) elif house_assigned_this: return einstein.assign_value(house_assigned_this, predicate, with_this, state) else: return einstein.propose_link(predicate, with_this, new_predicate, assign_this, state)