M2: The rising tide

The tide now runs every match, from the drop on, and water flows along the
terrain instead of standing everywhere under one level.

- Tide (src/sim/tide.gd): Tuning.TIDE_PHASES as a schedule of holds and
  rises. Level, forecast (each hold announces its level), stage, drowning
  rate, surge timing and the time limit are pure functions of the tick.
- SafeGround (src/sim/safe_ground.gd): safe ground from elevation on an 8 m
  grid, and per-island planned levels. A phase's level is lowered, when it
  must be, to just under the top of the largest piece of land still dry when
  the phase begins; every phase still rises at least TIDE_MIN_RISE_METRES and
  the last keeps its table level.
- Flood (src/sim/flood.gd): a 4 m grid aligned with building cells. Water
  reaches cells from the world's edge through ground under the sea and edges
  no breakwater stack seals. Cut-off ground stays dry until overtopped or
  breached, then fills at BREACH_FLOW_METRES_PER_SECOND. Incremental: only
  the edges where water stopped are re-tested, once a second.
- Players, drowning and structure wear use the local water. Breakwaters wear
  by head and fail past BREAKWATER_MAX_HEAD; a breach floods what's behind.
- Storm surges: each phase's `surge` damage hits pieces near the water when
  its rise begins.
- Sudden death after the last rise, then a time limit. Match breaks ties
  (most health, highest feet, earliest join) at the limit and when the last
  players fall together, so every match ends with a winner.

Tests: test_tide (18) covers the schedule and forecasts, planned levels,
overtopping, a sealed ring, breach and fill rate, spill-over, pressure wear
and head failure, dry pieces, surges, drowning under the real tide, sudden
death, the time limit and simultaneous eliminations. test_island's 100-seed
sweep now checks that every phase leaves safe ground reachable on foot from
the whole main landmass within the phase's time (closest margin 14 s).
A full rise with 24 bots measured p99 1.5 ms, max 1.9 ms per tick.

Closes #25

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 20:48:41 -05:00
co-authored by Claude Opus 5.5
parent c6f3c19004
commit 8a6fb93b50
18 changed files with 1194 additions and 21 deletions
+20
View File
@@ -91,6 +91,8 @@ func test_one_hundred_seeds_make_playable_islands() -> void:
var worst_stranded: float = 0.0
var land_range: Vector2 = Vector2(INF, -INF)
var peak_counts: Dictionary = {}
var safe_margin: float = INF
var lowered_phases: int = 0
for seed_value: int in range(1, SWEEP_SEEDS + 1):
var started: int = Time.get_ticks_msec()
var island: Island = Island.generate(seed_value)
@@ -116,6 +118,23 @@ func test_one_hundred_seeds_make_playable_islands() -> void:
assert_true(stranded <= MAX_STRANDED_FRACTION,
"%s: at %.0f m, %.3f of dry land is cut off from the main landmass" % [label, level, stranded])
# Safe ground (issue M2): every phase of the island's planned tide that leaves
# land leaves it within reach of the whole main landmass, on foot, in time.
var safe: SafeGroundSurvey = SafeGroundSurvey.new(island)
var checked: Array[Dictionary] = safe.check()
assert_true(checked.size() >= Tuning.TIDE_PHASES.size() - 2, "%s: only %d phases leave safe ground" % [label, checked.size()])
for result: Dictionary in checked:
var phase_label: String = "%s phase %d (%.1f m)" % [label, result["phase"], result["level"]]
assert_eq(result["unreached"], 0, "%s: main landmass cells with no way to safe ground" % phase_label)
assert_eq(result["swimmers"], 0, "%s: main landmass cells that must swim to safe ground" % phase_label)
assert_true(result["worst_seconds"] <= result["allowed_seconds"],
"%s: %.0f s to safe ground, %.0f s allowed" % [phase_label, result["worst_seconds"], result["allowed_seconds"]])
safe_margin = minf(safe_margin, result["allowed_seconds"] - result["worst_seconds"])
for index: int in safe.levels.size():
if not is_equal_approx(safe.levels[index], float(Tuning.TIDE_PHASES[index]["level"])):
lowered_phases += 1
assert_eq(safe.levels[safe.levels.size() - 1], float(Tuning.TIDE_PHASES[-1]["level"]), "%s: the last phase keeps its level" % label)
var peaks: Array[Vector3] = survey.peaks(PEAK_MIN_HEIGHT, PEAK_RADIUS, PEAK_DROP)
assert_true(peaks.size() >= 2, "%s: %d distinct high points" % [label, peaks.size()])
@@ -134,6 +153,7 @@ func test_one_hundred_seeds_make_playable_islands() -> void:
assert_true(marsh_islands >= SWEEP_SEEDS * 0.8, "only %d islands have marsh" % marsh_islands)
print(" island sweep: slowest %d ms, land %.2f to %.2f of the world, worst stranded %.4f," % [
slowest, land_range.x, land_range.y, worst_stranded])
print(" island sweep: safe ground reached with at least %.0f s to spare; %d phase levels lowered by planning" % [safe_margin, lowered_phases])
print(" island sweep: islands by distinct high points %s, %d of %d with marsh" % [
peak_counts, marsh_islands, SWEEP_SEEDS])