Exemple #1
0
def run_maze():
    visited = set()
    graph = Graph()
    travel_path = []
    dfs_rooms = graph.dfs(player.current_room)
    rooms = [room for room in dfs_rooms]
    while (len(visited) < len(room_graph) - 1):
        current_room = rooms[0]
        next_room = rooms[1]
        shortest_path = graph.bfs(current_room, next_room)

        while len(shortest_path) > 1:
            current_room_neighbors = dfs_rooms[shortest_path[0]]
            next_room = shortest_path[1]
            if next_room in current_room_neighbors:
                travel_path.append(current_room_neighbors[next_room])
            shortest_path.remove(shortest_path[0])
        rooms.remove(current_room)
        visited.add(current_room)

    return travel_path

# print(world.rooms[0].n_to.id)

dft_path = gg.dft(0)
test_path = dft_path
new_list = []

# print(dft_path)
for index, current_room in enumerate(test_path):
    room_lookup = world.rooms[current_room]
    if index + 1 < len(test_path):
        if test_path[index + 1] in get_neighbors(room_lookup):
            new_list.append(current_room)
        else:
            missing_rooms = gg.bfs(current_room, test_path[index + 1])[:-1]
            # print(gg.bfs(current_room,test_path[index + 1])[1:-1])
            print(index, missing_rooms)
            # temp_index = index
            for missing_room in missing_rooms:
                new_list.append(missing_room)
            #     # print(index,temp_index,missing_rooms[index2])
            #     # test_path.insert(temp_index,missing_rooms[index2])
            # # #     # print(test_path)
            #     temp_index += 1

new_list.append(test_path[-1])

# print(new_list)

for index, room in enumerate(new_list):