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
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:
@@ -535,7 +535,11 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
const auto world = nursery_config.world;
|
||||
const auto region = nursery_config.region;
|
||||
const auto frame = nursery_config.frame;
|
||||
const bool reproduction = profile == CellularLivesProfile::reproduction; // Rules 7.
|
||||
const bool foraging = profile == CellularLivesProfile::foraging; // Rules 8.
|
||||
// A rules-8 opening needs a deposit habitat, and only it may have one.
|
||||
if (foraging != (habitat->config().format == biology::cellular_habitat_deposit_format))
|
||||
return std::unexpected{CellularLivesError::habitat};
|
||||
const bool reproduction = profile == CellularLivesProfile::reproduction || foraging;
|
||||
const bool balance = profile == CellularLivesProfile::balance || reproduction; // Rules 6+.
|
||||
const bool presence = profile == CellularLivesProfile::presence || balance;
|
||||
const bool budding = profile == CellularLivesProfile::budding || presence;
|
||||
@@ -550,12 +554,13 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
: budding ? cellular_lives_bud_format
|
||||
: engulf ? cellular_lives_engulf_format
|
||||
: cellular_lives_format,
|
||||
reproduction ? cellular_lives_reproduction_rules
|
||||
: balance ? cellular_lives_balance_rules
|
||||
: presence ? cellular_lives_presence_rules
|
||||
: budding ? cellular_lives_bud_rules
|
||||
: engulf ? cellular_lives_engulf_rules
|
||||
: cellular_lives_rules);
|
||||
foraging ? cellular_lives_foraging_rules
|
||||
: reproduction ? cellular_lives_reproduction_rules
|
||||
: balance ? cellular_lives_balance_rules
|
||||
: presence ? cellular_lives_presence_rules
|
||||
: budding ? cellular_lives_bud_rules
|
||||
: engulf ? cellular_lives_engulf_rules
|
||||
: cellular_lives_rules);
|
||||
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
|
||||
}
|
||||
|
||||
@@ -984,7 +989,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
format_version == cellular_lives_presence_format &&
|
||||
(rules_version == cellular_lives_presence_rules ||
|
||||
rules_version == cellular_lives_balance_rules ||
|
||||
rules_version == cellular_lives_reproduction_rules);
|
||||
rules_version == cellular_lives_reproduction_rules ||
|
||||
rules_version == cellular_lives_foraging_rules);
|
||||
// Formats 5 and 6 carry the bud sequence and parent lives (rules 4 and 5).
|
||||
const bool bud_version = presence_version || (magic == cellular_lives_v5_magic &&
|
||||
format_version == cellular_lives_bud_format &&
|
||||
@@ -1169,6 +1175,10 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
return std::unexpected{CellularLivesError::checksum};
|
||||
return std::unexpected{CellularLivesError::habitat};
|
||||
}
|
||||
// Rules 8 run on a deposit habitat, and nothing else does (ADR-0136).
|
||||
if ((rules_version >= cellular_lives_foraging_rules) !=
|
||||
((*habitat)->config().format == biology::cellular_habitat_deposit_format))
|
||||
return std::unexpected{CellularLivesError::habitat};
|
||||
auto archive = biology::LineageArchive::decode(archive_payload);
|
||||
if (!archive) {
|
||||
if (archive.error() == biology::ArchiveCodecError::version)
|
||||
@@ -1248,6 +1258,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
return std::unexpected{CellularLivesError::version};
|
||||
// Rules 4 keep rules 3 (engulfment, detritus) and add budding (ADR-0125).
|
||||
const bool engulf_rules = state_->rules_version >= cellular_lives_engulf_rules;
|
||||
const bool contact_rules = state_->rules_version >= cellular_lives_foraging_rules;
|
||||
const bool bud_rules = state_->rules_version >= cellular_lives_bud_rules;
|
||||
const bool presence_rules = state_->rules_version >= cellular_lives_presence_rules;
|
||||
for (std::size_t i = 0; i < ordered.size(); ++i) {
|
||||
@@ -1319,8 +1330,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
*membrane,
|
||||
life.source});
|
||||
}
|
||||
auto proposal = biology::propose_cellular_region_step(state_->config.tick, state_->config.area,
|
||||
inputs, *state_->habitat, {engulf_rules});
|
||||
auto proposal =
|
||||
biology::propose_cellular_region_step(state_->config.tick, state_->config.area, inputs,
|
||||
*state_->habitat, {engulf_rules, contact_rules});
|
||||
if (!proposal)
|
||||
return std::unexpected{CellularLivesError::region_step};
|
||||
|
||||
@@ -1606,13 +1618,25 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
found->stock = update.stock;
|
||||
}
|
||||
// Rules 3 detritus at empty cells becomes new patches; create() revalidates the map.
|
||||
for (const auto& made : proposal->new_patches) {
|
||||
// Format 2 (ADR-0136): new bubbles take the next deposit ids, and a deposit emptied this
|
||||
// tick is gone.
|
||||
const bool deposits = habitat_config.format == biology::cellular_habitat_deposit_format;
|
||||
for (auto made : proposal->new_patches) {
|
||||
const auto at = std::ranges::lower_bound(habitat_config.patches, made.address, {},
|
||||
[](const auto& patch) { return patch.address; });
|
||||
if (at != habitat_config.patches.end() && at->address == made.address)
|
||||
return std::unexpected{CellularLivesError::habitat};
|
||||
if (deposits) {
|
||||
if (habitat_config.next_deposit == std::numeric_limits<std::uint32_t>::max())
|
||||
return std::unexpected{CellularLivesError::overflow};
|
||||
made.id = habitat_config.next_deposit++;
|
||||
}
|
||||
habitat_config.patches.insert(at, made);
|
||||
}
|
||||
if (deposits)
|
||||
std::erase_if(habitat_config.patches, [](const biology::CellularPatch& patch) {
|
||||
return patch.stock == accounting::Inventory{};
|
||||
});
|
||||
auto next_habitat = biology::CellularHabitat::create(std::move(habitat_config));
|
||||
if (!next_habitat)
|
||||
return std::unexpected{CellularLivesError::habitat};
|
||||
|
||||
@@ -124,19 +124,34 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
const auto centre_y = static_cast<std::int64_t>(life.position.y_um) + extent / 2;
|
||||
std::optional<biology::CellularPatchAddress> nearest;
|
||||
std::uint64_t nearest_distance{};
|
||||
// Rules 8 (ADR-0136): deposits are discs at their centres, any non-empty one is food,
|
||||
// and touching feeds; earlier rules seek energy patches and name them.
|
||||
const bool deposits = state.rules_version() >= cellular_lives_foraging_rules;
|
||||
const auto offset = deposits ? 0 : half_pitch;
|
||||
std::optional<biology::CellularPatchPerception> chosen;
|
||||
for (const auto& patch : *perceived) {
|
||||
if (patch.available.energy.value == 0)
|
||||
if (deposits ? patch.available == accounting::Inventory{}
|
||||
: patch.available.energy.value == 0)
|
||||
continue;
|
||||
const auto dx = std::int64_t{patch.address.x_um} + half_pitch - centre_x;
|
||||
const auto dy = std::int64_t{patch.address.y_um} + half_pitch - centre_y;
|
||||
const auto dx = std::int64_t{patch.address.x_um} + offset - centre_x;
|
||||
const auto dy = std::int64_t{patch.address.y_um} + offset - centre_y;
|
||||
const auto distance = static_cast<std::uint64_t>(dx * dx + dy * dy);
|
||||
// Perception is ordered by address, so the first of equal distances wins.
|
||||
if (!nearest || distance < nearest_distance) {
|
||||
nearest = patch.address;
|
||||
nearest_distance = distance;
|
||||
chosen = patch;
|
||||
}
|
||||
}
|
||||
if (nearest) {
|
||||
if (nearest && deposits && chosen) {
|
||||
biology::CellularPatch disc{};
|
||||
disc.address = chosen->address;
|
||||
disc.radius_um = chosen->radius_um;
|
||||
disc.kind = chosen->kind;
|
||||
if (!biology::cellular_patch_contact(life.position, extent, disc))
|
||||
intent.movement = wildlife_toward(std::int64_t{nearest->x_um} - centre_x,
|
||||
std::int64_t{nearest->y_um} - centre_y);
|
||||
} else if (nearest) {
|
||||
intent.intake_target = nearest;
|
||||
if (!overlaps(life.position.x_um, extent, nearest->x_um) ||
|
||||
!overlaps(life.position.y_um, extent, nearest->y_um))
|
||||
|
||||
@@ -153,7 +153,7 @@ struct RegionSessions::Impl {
|
||||
const network::SessionMessage& message) {
|
||||
for (const auto& c : connections) {
|
||||
if (c.state != State::established ||
|
||||
c.protocol_version != network::session_protocol_v10 || c.account_id != account)
|
||||
!network::cellular_v10_family(c.protocol_version) || c.account_id != account)
|
||||
continue;
|
||||
const auto bytes = network::encode_session(message, c.protocol_version);
|
||||
return !bytes.empty() && endpoint->send_message(c.id, bytes).has_value();
|
||||
@@ -447,7 +447,7 @@ struct RegionSessions::Impl {
|
||||
(c.protocol_version == network::session_protocol_v7 ||
|
||||
c.protocol_version == network::session_protocol_v8 ||
|
||||
c.protocol_version == network::session_protocol_v9 ||
|
||||
c.protocol_version == network::session_protocol_v10)))))
|
||||
network::cellular_v10_family(c.protocol_version))))))
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
|
||||
return replication.acknowledge(c.session, *ack);
|
||||
@@ -616,9 +616,9 @@ struct RegionSessions::Impl {
|
||||
((wire_version == network::session_protocol_v7 ||
|
||||
wire_version == network::session_protocol_v8 ||
|
||||
wire_version == network::session_protocol_v9 ||
|
||||
wire_version == network::session_protocol_v10) &&
|
||||
network::cellular_v10_family(wire_version)) &&
|
||||
!cellular_actions) ||
|
||||
wire_version > network::session_protocol_v10)
|
||||
wire_version > network::session_protocol_v11)
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
} else if (wire_version != c.protocol_version) {
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
@@ -644,14 +644,14 @@ struct RegionSessions::Impl {
|
||||
if (c.protocol_version != network::session_protocol_v7 &&
|
||||
c.protocol_version != network::session_protocol_v8 &&
|
||||
c.protocol_version != network::session_protocol_v9 &&
|
||||
c.protocol_version != network::session_protocol_v10)
|
||||
!network::cellular_v10_family(c.protocol_version))
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
if (const auto receipt = intents.admit(c.session, *m, admission()))
|
||||
answer(c, *receipt);
|
||||
return;
|
||||
}
|
||||
if (const auto* m = std::get_if<network::CellularMutationAction>(&*decoded)) {
|
||||
if (c.protocol_version != network::session_protocol_v10 ||
|
||||
if (!network::cellular_v10_family(c.protocol_version) ||
|
||||
!config.select_cellular_mutation)
|
||||
return close(c, SessionCloseReason::protocol, now);
|
||||
CellularMutationAnswer answer{
|
||||
@@ -934,10 +934,15 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account,
|
||||
if (c.state != Impl::State::established ||
|
||||
(c.protocol_version != network::session_protocol_v8 &&
|
||||
c.protocol_version != network::session_protocol_v9 &&
|
||||
c.protocol_version != network::session_protocol_v10) ||
|
||||
!network::cellular_v10_family(c.protocol_version)) ||
|
||||
c.account_id != account)
|
||||
continue;
|
||||
auto delivered = perception;
|
||||
// v11 sees deposits (ADR-0136), earlier versions square patches; never both.
|
||||
if (c.protocol_version == network::session_protocol_v11)
|
||||
delivered.patches.clear();
|
||||
else
|
||||
delivered.deposits.clear();
|
||||
if (c.protocol_version == network::session_protocol_v8)
|
||||
delivered.diagnostics.reset();
|
||||
if (c.protocol_version == network::session_protocol_v9 && delivered.diagnostics) {
|
||||
@@ -975,7 +980,7 @@ void RegionSessions::clear_cellular_perceptions(std::uint64_t tick) {
|
||||
if (c.state == Impl::State::established &&
|
||||
(c.protocol_version == network::session_protocol_v8 ||
|
||||
c.protocol_version == network::session_protocol_v9 ||
|
||||
c.protocol_version == network::session_protocol_v10))
|
||||
network::cellular_v10_family(c.protocol_version)))
|
||||
m.send(c, cleared);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user