def test_search(self): graph = [(1, 2), (2, 1), (2, 3), (3, 2), (3, 4), (4, 3), (3, 5), (5, 3), (5, 6), (6, 5), (6, 7), (7, 6)] def cmpltr(goal): def _helper(roomid): return roomid == goal return _helper self.assertSequenceEqual(search(graph, 1, cmpltr(3)), [1, 2, 3])
def find_directions(rooms, start, objects): found = [] def completed(rooms, targets, found, room_id): obj = get_object(rooms, room_id) if obj in targets and obj not in found: found.append(obj) return len(found) == len(targets) start_id = get_id_by_name(rooms, start) graph = list(build_graph(rooms)) path = search(graph, start_id, lambda room_id: completed(rooms, objects, found, room_id)) return path_to_directions(rooms, path)
def find_directions(rooms, start, objects): found = [] def completed(rooms, targets, found, room_id): obj = get_object(rooms, room_id) if obj in targets and obj not in found: found.append(obj) return len(found) == len(targets) start_id = get_id_by_name(rooms, start) graph = list(build_graph(rooms)) path = search( graph, start_id, lambda room_id: completed(rooms, objects, found, room_id) ) return path_to_directions(rooms, path)