Cellular rules 8: pools and bubbles fed by contact (ADR-0136 step A)
Foundation / checks (checks) (push) Successful in 47m40s
Foundation / checks (client) (push) Successful in 17m27s
Foundation / checks (deploy) (push) Successful in 4m17s
Foundation / checks (ecs) (push) Successful in 4m31s
Foundation / checks (network) (push) Successful in 22m1s
Foundation / checks (tsan) (push) Successful in 13m10s
Foundation / checks (postgres) (push) Successful in 20m54s
Foundation / image (push) Successful in 4m15s
Foundation / postgres-tools (push) Successful in 5m32s
Foundation / server-image (push) Successful in 7m15s

Square patches invited camping and left the space between them empty. Rules 8 run on a
format-2 habitat of deposits:
- pools and single-nutrient bubbles at free micrometre centres, each with a stable id
  and a contact radius; the cellular-v7 opening scatters bubbles reproducibly from the
  genesis commit (three in ten in loose clumps) and lists pools with --pool;
- every cell drains what it touches, up to its intake rate per tick, with no target; a
  pool gives at most a quarter of that rate; an emptied deposit disappears;
- a dead cell's detritus breaks into one bubble per non-empty channel;
- wildlife swims to the nearest non-empty deposit and feeds by touch.

Bundle v9 (habitat 2) and schema v43 admit it. Session v11 carries the owner's 512
nearest deposits (id, centre, radius, shape, a drained flag and 16-bit amount codes)
instead of patches; every other cellular message is v10's. The client asks for v11,
draws bubbles (nutrient-coloured, pulsing while drained, popping when gone) and pools as
puddles, slows near food and sends no feed target; the HUD summarises food in range.
Earlier rules, regions and v10 clients are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-17 00:38:21 -04:00
co-authored by Claude Opus 5.5
parent 1d9af1d28e
commit be69cae652
35 changed files with 1311 additions and 112 deletions
+58
View File
@@ -23,6 +23,7 @@
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace evo::server_app {
@@ -259,7 +260,59 @@ class CellularBridge {
}
view.diagnostics = diagnostics;
view.patches.reserve(perceived->size());
// ADR-0136 (rules 8): pools and bubbles go out as v11 deposits, the nearest 512 to
// the cell, by ascending id; `drained` marks a stock that fell since last tick.
std::vector<std::pair<std::uint64_t, network::CellularPerceivedDeposit>> near;
const auto centre_x = static_cast<std::int64_t>(life.position.x_um);
const auto centre_y = static_cast<std::int64_t>(life.position.y_um);
for (const auto& patch : *perceived) {
if (patch.kind == biology::CellularDepositKind::patch)
continue;
network::CellularPerceivedDeposit deposit;
deposit.id = patch.id;
deposit.x_um = patch.address.x_um;
deposit.y_um = patch.address.y_um;
deposit.radius_um =
static_cast<std::uint16_t>(std::min<std::uint32_t>(patch.radius_um, 65'535));
deposit.shape = patch.kind == biology::CellularDepositKind::pool
? network::CellularDepositShape::pool
: network::CellularDepositShape::bubble;
deposit.amount_codes[0] =
network::deposit_amount_code(patch.available.energy.value);
for (std::size_t c = 0; c < patch.available.matter.size(); ++c)
deposit.amount_codes.at(c + 1) =
network::deposit_amount_code(patch.available.matter[c].value);
const auto before = deposit_stock_.find(patch.id);
deposit.drained = before != deposit_stock_.end() &&
(patch.available.energy.value < before->second.energy.value ||
std::ranges::any_of(
std::array{0, 1, 2, 3},
[&](int c) {
const auto i = static_cast<std::size_t>(c);
return patch.available.matter.at(i).value <
before->second.matter.at(i).value;
}));
seen_stock_[patch.id] = patch.available;
const auto dx = std::int64_t{patch.address.x_um} - centre_x;
const auto dy = std::int64_t{patch.address.y_um} - centre_y;
near.emplace_back(static_cast<std::uint64_t>(dx * dx + dy * dy), deposit);
}
if (near.size() > network::max_cellular_perceived_deposits) {
std::ranges::nth_element(
near,
near.begin() +
static_cast<std::ptrdiff_t>(network::max_cellular_perceived_deposits),
[](const auto& a, const auto& b) {
return std::pair{a.first, a.second.id} < std::pair{b.first, b.second.id};
});
near.resize(network::max_cellular_perceived_deposits);
}
for (const auto& [distance, deposit] : near)
view.deposits.push_back(deposit);
std::ranges::sort(view.deposits, {}, &network::CellularPerceivedDeposit::id);
for (const auto& patch : *perceived) {
if (patch.kind != biology::CellularDepositKind::patch)
continue;
network::CellularPerceivedPatch visible;
visible.x_um = patch.address.x_um;
visible.y_um = patch.address.y_um;
@@ -276,6 +329,9 @@ class CellularBridge {
&server::CellularOwnedLife::account) == state.lives().end();
});
announce_endings(state);
// What each deposit held when last seen, for next tick's `drained` flags.
deposit_stock_ = std::move(seen_stock_);
seen_stock_.clear();
replicated_tick_ = tick;
}
// ADR-0129: an owned life seen at the last replication and now a corpse is announced to
@@ -404,6 +460,8 @@ class CellularBridge {
};
std::vector<SentOffer> offers_; // Last offer view sent to each owner.
std::map<std::uint64_t, std::optional<accounting::Inventory>> bud_costs_; // By genome.
// ADR-0136: deposit stocks seen at the last replicated tick, and this tick's.
std::map<std::uint32_t, accounting::Inventory> deposit_stock_, seen_stock_;
std::vector<std::pair<server::LifeAccount, std::uint64_t>> owned_; // At last replication.
bool shutdown_{};
};