38 lines
1.3 KiB
GDScript3
38 lines
1.3 KiB
GDScript3
|
|
extends SceneTree
|
||
|
|
|
||
|
|
# Headless gameplay test: run with
|
||
|
|
# godot --headless -s res://tests/test_biome_generation.gd
|
||
|
|
# Verifies WorldGen's biome-per-chunk function is deterministic (querying
|
||
|
|
# the same chunk twice gives the same biome) and that the seeded noise
|
||
|
|
# field actually produces both biome types within a reasonably large
|
||
|
|
# sampled area - a regression guard against a threshold tuned so one biome
|
||
|
|
# never appears at all.
|
||
|
|
|
||
|
|
func _initialize() -> void:
|
||
|
|
var deterministic_ok: bool = true
|
||
|
|
for i in range(20):
|
||
|
|
var chunk: Vector2i = Vector2i(i * 3 - 10, i * 2 - 5)
|
||
|
|
var a: int = WorldGen.biome_at_chunk(chunk)
|
||
|
|
var b: int = WorldGen.biome_at_chunk(chunk)
|
||
|
|
if a != b:
|
||
|
|
deterministic_ok = false
|
||
|
|
print("FAIL: chunk %s gave %d then %d" % [chunk, a, b])
|
||
|
|
|
||
|
|
var space_count: int = 0
|
||
|
|
var asteroid_count: int = 0
|
||
|
|
for x in range(-25, 25):
|
||
|
|
for y in range(-25, 25):
|
||
|
|
var biome: int = WorldGen.biome_at_chunk(Vector2i(x, y))
|
||
|
|
if biome == WorldGen.Biome.SPACE:
|
||
|
|
space_count += 1
|
||
|
|
elif biome == WorldGen.Biome.ASTEROID_FIELD:
|
||
|
|
asteroid_count += 1
|
||
|
|
|
||
|
|
print("deterministic_ok=%s space_count=%d asteroid_count=%d" % [deterministic_ok, space_count, asteroid_count])
|
||
|
|
|
||
|
|
if deterministic_ok and space_count > 0 and asteroid_count > 0:
|
||
|
|
print("TEST_BIOME_GENERATION: PASS")
|
||
|
|
quit(0)
|
||
|
|
else:
|
||
|
|
print("TEST_BIOME_GENERATION: FAIL")
|
||
|
|
quit(1)
|