extends GutTest const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd") const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd") const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd") const ASCII_CATALOG_PATH := "res://data/ascii" const CARDINAL_DIRECTIONS := [Vector2i.LEFT, Vector2i.RIGHT, Vector2i.UP, Vector2i.DOWN] func test_one_hundred_seeds_have_safe_catalog_backed_reachable_population() -> void: var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH) assert_eq(Array(catalog.get_diagnostics()), []) for seed_index in range(100): var floor := FloorGeneratorType.generate("B4-safety-%03d" % seed_index, 1 + seed_index % 10, catalog) var reachable := _reachable_cells_treating_closed_doors_openable(floor.map, floor.entrance) var occupied: Dictionary[Vector2i, bool] = {} assert_false(_has_blocking_occupant_at(floor, floor.entrance), "seed %d keeps entrance clear" % seed_index) assert_false(_has_blocking_occupant_at(floor, floor.exit), "seed %d keeps exit clear" % seed_index) assert_true(reachable.has(floor.exit), "seed %d keeps exit reachable" % seed_index) for enemy in floor.enemies.values(): assert_ne(catalog.get_enemy(enemy.content_id), {}, "seed %d enemy is catalog backed" % seed_index) assert_lte(int(catalog.get_enemy(enemy.content_id).get("min_floor", 1)), floor.floor_number) _assert_valid_unique_reachable_cell(floor, enemy.cell, occupied, reachable, seed_index) for npc in floor.npcs.values(): assert_ne(catalog.get_npc(npc.content_id), {}, "seed %d NPC is catalog backed" % seed_index) _assert_valid_unique_reachable_cell(floor, npc.cell, occupied, reachable, seed_index) for cell in floor.chests: assert_ne(catalog.get_loot_table(StringName(floor.chests[cell]["loot_table_id"])), {}) _assert_valid_unique_reachable_cell(floor, cell, occupied, reachable, seed_index) for cell in floor.traps: assert_ne(catalog.get_trap(StringName(floor.traps[cell]["trap_id"])), {}) _assert_valid_unique_reachable_cell(floor, cell, occupied, reachable, seed_index) for event in floor.events: assert_ne(catalog.get_event(StringName(event["event_id"])), {}) var cell_data: Array = event["cell"] _assert_valid_unique_reachable_cell(floor, Vector2i(int(cell_data[0]), int(cell_data[1])), occupied, reachable, seed_index) func _assert_valid_unique_reachable_cell(floor: FloorState, cell: Vector2i, occupied: Dictionary[Vector2i, bool], reachable: Dictionary[Vector2i, bool], seed_index: int) -> void: assert_false(occupied.has(cell), "seed %d has no overlapping population" % seed_index) occupied[cell] = true assert_ne(cell, floor.entrance) assert_ne(cell, floor.exit) assert_true(reachable.has(cell), "seed %d population is reachable" % seed_index) assert_eq(floor.map.get_cell(cell), GridMapStateType.CellKind.FLOOR) func _has_blocking_occupant_at(floor: FloorState, cell: Vector2i) -> bool: for actor in floor.enemies.values() + floor.npcs.values(): if actor.cell == cell: return true return floor.chests.has(cell) or floor.traps.has(cell) func _reachable_cells_treating_closed_doors_openable(map: GridMapState, start: Vector2i) -> Dictionary[Vector2i, bool]: var reachable: Dictionary[Vector2i, bool] = {start: true} var frontier: Array[Vector2i] = [start] while not frontier.is_empty(): var current := frontier.pop_front() for direction in CARDINAL_DIRECTIONS: var next_cell: Vector2i = current + direction if (map.is_walkable(next_cell) or map.get_cell(next_cell) == GridMapStateType.CellKind.CLOSED_DOOR) and not reachable.has(next_cell): reachable[next_cell] = true frontier.append(next_cell) return reachable