Add bounded cellular resource perception
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (network) (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 1m8s
Foundation / checks (checks) (push) Canceled after 1m13s
Foundation / checks (ecs) (push) Canceled after 1m4s

This commit is contained in:
dingo
2026-10-10 21:16:54 -04:00
parent 1787718383
commit 44732967e7
7 changed files with 135 additions and 1 deletions
+28
View File
@@ -123,6 +123,34 @@ std::optional<std::size_t> CellularHabitat::find(CellularPatchAddress address) c
return static_cast<std::size_t>(found - config_.patches.begin());
}
std::expected<std::vector<CellularPatchPerception>, CellularHabitatError>
CellularHabitat::perceive(CellularPosition position, std::uint32_t extent_um) const {
if (extent_um == 0 || extent_um > config_.width_um || extent_um > config_.height_um ||
position.x_um > config_.width_um - extent_um ||
position.y_um > config_.height_um - extent_um)
return std::unexpected{CellularHabitatError::outside_area};
std::vector<CellularPatchPerception> visible;
for (const auto& patch : config_.patches) {
const auto axis_gap = [](std::uint64_t body_start, std::uint32_t body_extent,
std::uint32_t patch_start) {
const auto body_end = body_start + body_extent;
const auto patch_end = std::uint64_t{patch_start} + cellular_patch_pitch_um;
if (body_end < patch_start)
return std::uint64_t{patch_start} - body_end;
if (patch_end < body_start)
return body_start - patch_end;
return std::uint64_t{};
};
const auto dx = axis_gap(position.x_um, extent_um, patch.address.x_um);
const auto dy = axis_gap(position.y_um, extent_um, patch.address.y_um);
const auto radius = std::uint64_t{cellular_trial_perception_radius_um};
if (dx * dx + dy * dy <= radius * radius)
visible.push_back({patch.address, patch.stock});
}
return visible;
}
std::expected<CellularPatchUptakeProposal, CellularHabitatError>
CellularHabitat::propose_uptake(CellularPatchAddress address, accounting::Inventory reserve,
const MetabolicBudget& budget) const noexcept {