fix: guarantee minimum generated room count
This commit is contained in:
@@ -4,12 +4,15 @@ const ContentCatalogType = preload("res://scripts/domain/content/content_catalog
|
||||
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
|
||||
|
||||
const CARDINAL_DIRECTIONS := [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN]
|
||||
const ROOM_PADDING := 2
|
||||
|
||||
func test_one_hundred_seeds_keep_every_room_center_entrance_and_exit_reachable() -> void:
|
||||
var catalog := ContentCatalogType.new()
|
||||
|
||||
for seed_index in range(100):
|
||||
var floor := FloorGeneratorType.generate("B2-connectivity-%03d" % seed_index, 1, catalog)
|
||||
assert_gte(floor.rooms.size(), 8, "seed %d creates at least eight padded rooms" % seed_index)
|
||||
_assert_padded_rooms(floor.rooms, seed_index)
|
||||
var reachable := _reachable_cells(floor.map, floor.entrance)
|
||||
var required_cells: Array[Vector2i] = [floor.entrance, floor.exit]
|
||||
for room in floor.rooms:
|
||||
@@ -18,6 +21,14 @@ func test_one_hundred_seeds_keep_every_room_center_entrance_and_exit_reachable()
|
||||
for cell in required_cells:
|
||||
assert_true(reachable.has(cell), "seed %d reaches %s" % [seed_index, cell])
|
||||
|
||||
func _assert_padded_rooms(rooms: Array[RoomState], seed_index: int) -> void:
|
||||
for first_index in range(rooms.size()):
|
||||
for second_index in range(first_index + 1, rooms.size()):
|
||||
assert_false(
|
||||
rooms[first_index].bounds.grow(ROOM_PADDING).intersects(rooms[second_index].bounds.grow(ROOM_PADDING)),
|
||||
"seed %d keeps %s and %s padded" % [seed_index, rooms[first_index].id, rooms[second_index].id]
|
||||
)
|
||||
|
||||
func _reachable_cells(map: GridMapState, start: Vector2i) -> Dictionary[Vector2i, bool]:
|
||||
var reachable: Dictionary[Vector2i, bool] = {}
|
||||
var frontier: Array[Vector2i] = [start]
|
||||
|
||||
Reference in New Issue
Block a user