Randoloot/tests/levels/system_generation_test.gd
2026-10-10 21:21:58 +02:00

50 lines
2.2 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Node
const GENERATOR := preload("res://scripts/levels/system_generator.gd")
const BALANCE := preload("res://scripts/levels/level_balance.gd")
func _ready() -> void:
for point in BALANCE.COUNT_POINTS:
assert(BALANCE.enemy_count(int(point.x)) == int(point.y))
var previous_count := 0
for level in range(1, 1001):
var count := BALANCE.enemy_count(level)
assert(count >= previous_count and count <= 40)
assert(BALANCE.enemy_tiers(level).size() == count)
previous_count = count
var observed_counts: Dictionary = {}
for level in [1, 10, 50, 100, 250, 500, 1000]:
for seed_value in range(1, 61):
var data := GENERATOR.generate(level, seed_value)
assert(data == GENERATOR.generate(level, seed_value))
assert(data["star_position"] == Vector2.ZERO)
assert(data["player_start"].distance_to(Vector2.ZERO) <= 300.0)
var planets: Array[Dictionary] = data["planets"]
assert(planets.size() >= 1 and planets.size() <= 5)
observed_counts[planets.size()] = true
var protected_count := 0
for planet in planets:
if planet["protected"]:
protected_count += 1
var position: Vector2 = planet["position"]
assert(position.length() > 900)
assert(absf(position.x) + float(planet["radius"]) < 2580)
assert(absf(position.y) + float(planet["radius"]) < 1780)
assert(protected_count == 1)
assert(planets[data["protected_index"]]["protected"])
var enemies: Array[Dictionary] = data["enemies"]
assert(enemies.size() == BALANCE.enemy_count(level))
for index in enemies.size():
var position: Vector2 = enemies[index]["position"]
assert(position.length() >= GENERATOR.SAFE_ZONE_RADIUS)
assert(position.distance_to(data["player_start"]) >= 940.0)
assert(absf(position.x) <= 2380 and absf(position.y) <= 1580)
for other_index in range(index + 1, enemies.size()):
assert(position.distance_to(enemies[other_index]["position"]) >= GENERATOR.ENEMY_MIN_SEPARATION)
if level <= 10:
assert(enemies[index]["tier"] == 0)
if enemies[index]["tier"] == 2:
assert(enemies[index + 1]["tier"] == 1 and enemies[index + 2]["tier"] == 1)
assert(observed_counts.size() == 5)
print("SYSTEM_GENERATION_TEST: PASS (420 layouts, deterministic retries, planets, safe spawn and level balance 1–1000)")