M11-PT-001: wildlife steering stays within the intent length limit
Foundation / checks (checks) (push) Successful in 45m24s
Foundation / checks (deploy) (push) Successful in 4m8s
Foundation / checks (ecs) (push) Successful in 2m18s
Foundation / checks (network) (push) Successful in 19m39s
Foundation / checks (postgres) (push) Successful in 44m48s
Foundation / checks (tsan) (push) Successful in 11m26s
Foundation / checks (client) (push) Successful in 17m4s
Foundation / postgres-tools (push) Successful in 21s
Foundation / server-image (push) Successful in 3m10s
Foundation / image (push) Successful in 3m18s

DEV region 6 stopped at tick 7144 (stall log: append error=13 lives=10, region_step).
The wildlife controller steered toward food by scaling the larger component to 1000, so
a diagonal heading such as {1000, 800} was longer than a cellular intent may be; the
owner refused it, failing the tick, and the deterministic controller asked again every
tick. Earlier tests only had buds already touching food, so none moved.

wildlife_toward scales each component by the exact length, truncates toward zero and
pulls in any rounding excess. A regression test reproduces the refusal and accepts the
steered intent; another checks length, direction and speed over a grid of offsets.
No history changes: the refused ticks were never committed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-16 15:05:28 -04:00
co-authored by Claude Opus 5.5
parent ac1b518ddd
commit 69b13d7325
5 changed files with 78 additions and 12 deletions
+22 -11
View File
@@ -4,6 +4,7 @@
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <optional>
@@ -19,21 +20,30 @@ std::uint64_t mix(std::uint64_t life, std::uint64_t phase) noexcept {
return value;
}
// Full speed toward (dx, dy), keeping the larger component at the limit.
biology::CellularIntent toward(std::int64_t dx, std::int64_t dy) noexcept {
const auto larger = std::max(std::llabs(dx), std::llabs(dy));
if (larger == 0)
return {};
return {static_cast<std::int16_t>(dx * wildlife_full_speed / larger),
static_cast<std::int16_t>(dy * wildlife_full_speed / larger)};
}
bool overlaps(std::uint64_t start, std::uint32_t extent, std::uint32_t patch) noexcept {
return start < std::uint64_t{patch} + biology::cellular_patch_pitch_um &&
start + extent > patch;
}
} // namespace
// M11-PT-001: scaling the larger component to the limit made a diagonal intent longer
// than the limit; the owner refused it and every later tick of the region stalled. Each
// component is scaled by the exact length and truncated toward zero, then pulled in if
// rounding still leaves the intent a hair long.
biology::CellularIntent wildlife_toward(std::int64_t dx, std::int64_t dy) noexcept {
if (dx == 0 && dy == 0)
return {};
const double length = std::hypot(static_cast<double>(dx), static_cast<double>(dy));
auto x = static_cast<std::int64_t>(static_cast<double>(dx) * wildlife_full_speed / length);
auto y = static_cast<std::int64_t>(static_cast<double>(dy) * wildlife_full_speed / length);
constexpr std::int64_t limit = wildlife_full_speed;
while (x * x + y * y > limit * limit) {
auto& larger = std::llabs(x) >= std::llabs(y) ? x : y;
larger += larger > 0 ? -1 : 1;
}
return {static_cast<std::int16_t>(x), static_cast<std::int16_t>(y)};
}
std::expected<std::vector<CellularLifeIntent>, CellularLivesError>
wildlife_intents(const CellularLives& state, std::uint64_t tick) {
constexpr std::array<biology::CellularIntent, 8> wander{{{1'000, 0},
@@ -86,8 +96,9 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
intent.intake_target = nearest;
if (!overlaps(life.position.x_um, extent, nearest->x_um) ||
!overlaps(life.position.y_um, extent, nearest->y_um))
intent.movement = toward(std::int64_t{nearest->x_um} + half_pitch - centre_x,
std::int64_t{nearest->y_um} + half_pitch - centre_y);
intent.movement =
wildlife_toward(std::int64_t{nearest->x_um} + half_pitch - centre_x,
std::int64_t{nearest->y_um} + half_pitch - centre_y);
} else {
intent.movement =
wander[mix(life.identity.life, tick / wildlife_wander_interval_ticks) %