print(f"Wearing: {item}") wearing_boots = True time.sleep(i["cooldown"]) elif not wearing_jacket and "jacket" in item: i = requests.post(f"{base_url}/take/", headers=headers, data=json.dumps({"name": item})).json() print(f"Took: {item}") time.sleep(i["cooldown"]) i = requests.post(f"{base_url}/wear/", headers=headers, data=json.dumps({"name": item})).json() print(f"Wearing: {item}") wearing_jacket = True time.sleep(i["cooldown"]) # Get a list of unvisited exits from the current location exits = graph.get_connected_rooms( player_current_room["room_id"], visited=False) # If there are exits if exits: # Store current room for connecting to the next room current_room = player_current_room # If we didn't backtrack, bias toward making turns rather than going straight if not backtracked: # If there's more than one exit, remove the direction player came from # In order to force a turn if len(exits) > 1 and len(traversal_path) > 0: prev_dir = traversal_path[-1] # 30% of the time, don't continue straight if prev_dir in exits and random.random() > 0.7: exits.remove(prev_dir)
traversal_path = [] # Keep track of visited rooms so we know when we've visited them all visited_rooms = set() visited_rooms.add(player.current_room) # Initialize a graph to track rooms and connections between them graph = Graph() graph.add_room(player.current_room.id, player.current_room.get_exits()) backtracked = False # Track whether player has returned from a dead end # Loop until all rooms have been visited while len(visited_rooms) != len(room_graph): # Get a list of unvisited exits from the current location exits = graph.get_connected_rooms(player.current_room.id, visited=False) # If there are exits if exits: # Store current room for connecting to the next room current_room = player.current_room # If we didn't backtrack, bias toward making turns rather than going straight if not backtracked: # If there's more than one exit, remove the direction player came from # In order to force a turn if len(exits) > 1 and len(traversal_path) > 0: prev_dir = traversal_path[-1] # 30% of the time, don't continue straight if prev_dir in exits and random.random() > 0.7: exits.remove(prev_dir)