def is_room(self, start_position, area_bounds): found_floor = False current_position = Vector(start_position.x, start_position.y + 1) # Check vertical for the room bounds while (current_position.y <= area_bounds.y_max and not found_floor): if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]): found_floor = True current_position.y -= 1 else: current_position.y += 1 room_bounds_y = current_position.y next_position = room_bounds_y + 1 if not found_floor or room_bounds_y == start_position.y: return False, next_position, None # Check horizontal for the room bounds found_floor = False current_position.x += 1 while (current_position.x <= area_bounds.x_max and not found_floor): if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]): found_floor = True current_position.x -= 1 else: current_position.x += 1 room_bounds_x = current_position.x if not found_floor or room_bounds_x == start_position.x: return False, next_position, None # Check vertical with the bounds found for y for y in range(start_position.y, room_bounds_y + 1): current_position.y = y if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]): return False, next_position, None # Check horizontal with the bounds found for y current_position.y = start_position.y for x in range(start_position.x, room_bounds_x + 1): current_position.x = x if not self.is_tile_of_type(current_position, TILE_TYPES["WALL"]): return False, next_position, None if abs(start_position.x - room_bounds_x) == 1 or \ abs(start_position.y - room_bounds_y) == 1: return False, next_position, None room_bounds = Bounds(start_position.x, start_position.y, room_bounds_x, room_bounds_y) return True, next_position, room_bounds
def evaluate_dungeon(self, data): self.convert(data) results = list() bounds = Bounds(0, 0, DUNGEON_DIMENSION, DUNGEON_DIMENSION) # Evaluate bounds of tilemap are walls bounds_are_walls_result = self.evaluate_bounds_are_of_type( bounds, TILE_TYPES["WALL"]) results.append(bounds_are_walls_result) print("bounds_are_walls_result: " + str(bounds_are_walls_result)) # Evaluate cells next to bounds of tilemap are corridors corridor_bounds = Bounds(bounds.x_min + 1, bounds.y_min + 1, bounds.x_max - 1, bounds.y_max - 1) next_to_bounds_are_corridors_result = self.evaluate_bounds_are_of_type( corridor_bounds, TILE_TYPES["CORRIDOR"]) results.append(next_to_bounds_are_corridors_result) print("next_to_bounds_are_corridors_result: " + str(next_to_bounds_are_corridors_result)) # Evaluate if there are any rooms in the dungeon room_bounds = Bounds(bounds.x_min + 2, bounds.y_min + 2, bounds.x_max - 2, bounds.y_max - 2) number_of_rooms_result = self.evaluate_rooms(room_bounds) results.append(number_of_rooms_result) print("number_of_rooms_result: " + str(number_of_rooms_result)) # Evaluate the cells in room areas room_area_result = self.evaluate_room_areas(self.rooms) results.append(room_area_result) print("room_area_result: " + str(room_area_result)) self.total_score(results)