except Exception as e: print(f"Error: {e}") travels_log.write(json.dumps(r) + ",") if "room_id" not in r: print(f"Error: {r}") else: player_current_room = graph.get_room(r["room_id"]) if not player_current_room: player_current_room = graph.add_room(r) traversal_path.append(direction) visited_rooms.add(player_current_room["room_id"]) graph.connect_rooms( current_room["room_id"], player_current_room["room_id"], direction) player_current_room["cooldown"] = r["cooldown"] time.sleep(player_current_room["cooldown"]) else: route = graph.explore_bfs(player_current_room["room_id"]) for direction in route: print(f"Direction: {direction}") try: r = requests.post(f"{base_url}/move/", headers=headers, data=json.dumps({"direction": direction, "next_room_id": str(player_current_room["exits"][direction])})).json() except Exception as e: print(f"Error: {e}") print(r)
# 30% of the time, don't continue straight if prev_dir in exits and random.random() > 0.7: exits.remove(prev_dir) direction = random.choice(exits) else: direction = exits[0] else: # If we backtracked from a dead end, take next avail clockwise turn direction = exits[0] backtracked = False player.travel(direction) traversal_path.append(direction) visited_rooms.add(player.current_room) graph.add_room(player.current_room.id, player.current_room.get_exits()) graph.connect_rooms(current_room.id, player.current_room.id, direction) else: route = graph.bfs(player.current_room.id) for direction in route: player.travel(direction) traversal_path.append(direction) backtracked = True if len(traversal_path) < shortest_traversal: print(f"NEW RECORD FOUND WITH SEED {seed}") shortest_traversal = len(traversal_path) # TRAVERSAL TEST visited_rooms = set() player.current_room = world.starting_room visited_rooms.add(player.current_room)