ludic/packages/ludic.zones/tests/zones_test.ludic
Orkuncakilkaya 509b5ef111 ludic.zones: a player's radius never past no fog's 900 m
A 1 km fog gave a 1040 m zone, more of the world than no fog's 900 m (2405 MB and 1029 nav tiles against
2294 MB and 753 in the fog profile). zones_radius is min(max(fog + 40, 150), 900); the test holds 1 km
and 860 m at 900.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:42:43 +03:00

54 lines
2.3 KiB
Text

# zones_test.ludic - discs merged into clusters (near players one, far ones two, a player leaving
# splits the chain), inside or not, how far to the nearest edge, and the radius a fog gives
import "ludic.zones"
import "ludic.base"
program ZonesTest {
numbers float
test "two near players are one cluster, two far apart are two" (zones_st: mut ZonesState) {
zones_reset(zones_st)
zones_set(zones_st, 0, 0.0, 0.0, 200.0)
zones_set(zones_st, 1, 300.0, 0.0, 150.0)
zones_merge(zones_st)
expect_eq(zones_clusters(zones_st), 1)
expect_eq(zones_cluster_of(zones_st, 0), zones_cluster_of(zones_st, 1))
expect_eq(zones_cluster_n(zones_st, 0), 2)
expect(zones_cluster_r(zones_st, 0) >= 325.0)
zones_set(zones_st, 1, 1000.0, 0.0, 150.0)
zones_merge(zones_st)
expect_eq(zones_clusters(zones_st), 2)
expect(zones_cluster_of(zones_st, 0) != zones_cluster_of(zones_st, 1))
}
test "a player leaving the middle of a chain splits it" (zones_st: mut ZonesState) {
zones_reset(zones_st)
zones_set(zones_st, 0, 0.0, 0.0, 200.0)
zones_set(zones_st, 3, 350.0, 0.0, 200.0)
zones_set(zones_st, 5, 700.0, 0.0, 200.0)
zones_merge(zones_st)
expect_eq(zones_clusters(zones_st), 1)
zones_clear(zones_st, 3)
zones_merge(zones_st)
expect_eq(zones_clusters(zones_st), 2)
expect(zones_cluster_of(zones_st, 0) != zones_cluster_of(zones_st, 5))
}
test "inside, the distance to the nearest edge, and nothing set is everywhere" (zones_st: mut ZonesState) {
zones_reset(zones_st)
expect(zones_contains(zones_st, 5000.0, 5000.0))
expect(zones_nearest(zones_st, 5000.0, 5000.0) == 0.0)
zones_set(zones_st, 2, 100.0, 100.0, 150.0)
expect(zones_contains(zones_st, 200.0, 100.0))
expect(not zones_contains(zones_st, 300.0, 100.0))
expect(zones_nearest(zones_st, 200.0, 100.0) == 0.0)
expect(Math.abs(zones_nearest(zones_st, 350.0, 100.0) - 100.0) < 0.001)
}
test "a player's radius: past the fog, never under the least nor over no fog's" (zones_st: mut ZonesState) {
expect(zones_radius(0.0) == ZONES_NO_FOG)
expect(zones_radius(30.0) == ZONES_LEAST)
expect(zones_radius(500.0) == 540.0)
expect(zones_radius(1000.0) == ZONES_NO_FOG) # a kilometre's fog keeps no more than none
expect(zones_radius(860.0) == ZONES_NO_FOG)
}
}