def get_random_room(): # --- Se elige en que lado del pasillo se va a insertar la habitación --- random_side = random.choice(list(dict_orientation_sides[orientation])) if dict_rooms_per_side[random_side] > max_rooms_per_side: print(f'side {random_side} has already the maximum of rooms') random_side = dict_opposite_side[random_side] print(f'side chosed = {random_side}') # --- Se escoge un punto aleatorio de ese lado --- random_point = random.choice(list(corridor_points[random_side])) print(f'point = {random_point}') # --. Se escogen un ancho y un alto para la habitacion teninedo en cuenta el lado del pasillo en el que estará la # habitacion si esta en la parte de abajo del pasillo la altura no puede ser positiva porque se comería el # pasillo--- signed_width = random.choice(dict_side_sign[random_side][0]) signed_height = random.choice(dict_side_sign[random_side][1]) random_width = signed_width * (random.uniform(2.5, 5)) random_height = signed_height * (random.uniform(2.5, 5)) print( f'Creating room with width = {random_width} and height = {random_height}' ) # --- Se crea un rectangulo con el ancho y alto seleccionado random_room = QRectF(random_point.x(), random_point.y(), random_width, random_height) # Se comprueba que la habitación no interseccione con ninguna otra o no contenga a alguan otra valid_room = True for prev_room in random_qrect_list: intersected = random_room.intersects(prev_room) room_contained_in_prev = prev_room.contains(random_room) prev_contained_in_room = random_room.contains(prev_room) if intersected or room_contained_in_prev or prev_contained_in_room: print('room intersects with existing room') valid_room = False break if valid_room: random_qrect_list.append(random_room) dict_rooms_per_side[random_side] += 1 return valid_room
def get_random_room(): # corridor_height, initial_corridor random_side = random.choice(['top', 'bottom']) if len(dict_rooms_per_side[random_side]) >= max_rooms_per_side: print(f'side {random_side} has already the maximum of rooms') random_side = dict_opposite_side[random_side] print(f'side chosed = {random_side}') corridor_locations = dict_corridors_per_side[random_side] new_corridor_width = initial_corridor.height() add_corridor = False # if corridor_location == len(dict_rooms_per_side[random_side]): if len(dict_rooms_per_side[random_side]) in corridor_locations: add_corridor = True if len(dict_rooms_per_side[random_side]) == 0: if add_corridor: if random_side == 'bottom': random_point = initial_corridor.topLeft() random_point = QPointF(random_point.x() + new_corridor_width, random_point.y()) else: random_point = initial_corridor.bottomLeft() random_point = QPointF(random_point.x() + new_corridor_width, random_point.y()) else: if random_side == 'bottom': random_point = initial_corridor.topLeft() else: random_point = initial_corridor.bottomLeft() # random_point = random.choice(list(dict_corridor_points[random_side])) else: if add_corridor: prev = dict_rooms_per_side[random_side][-1].topRight() random_point = QPointF(prev.x() + new_corridor_width, prev.y()) else: random_point = dict_rooms_per_side[random_side][-1].topRight() print(f'random point = {random_point}') # --. Se escogen un ancho y un alto para la habitacion teninedo en cuenta el lado del pasillo en el que estará la # habitacion si esta en la parte de abajo del pasillo la altura no puede ser positiva porque se comería el # pasillo--- signed_width = dict_side_sign[random_side][0] signed_height = dict_side_sign[random_side][1] random_width = signed_width * (random.uniform(3, 6)) random_height = signed_height * fixed_w_h_room print( f'Creating room with width = {random_width} and height = {random_height}' ) # --- Se crea un rectangulo con el ancho y alto seleccionado random_room = QRectF(random_point.x(), random_point.y(), random_width, random_height) # Se comprueba que la habitación no interseccione con ninguna otra o no contenga a alguan otra valid_room = True for prev_room in random_qrect_list: intersected = random_room.intersects(prev_room) room_contained_in_prev = prev_room.contains(random_room) prev_contained_in_room = random_room.contains(prev_room) if intersected or room_contained_in_prev or prev_contained_in_room: print('room intersects with existing room') valid_room = False break if valid_room: random_qrect_list.append(random_room) dict_rooms_per_side[random_side].append(random_room) return valid_room