feat(biology): liquid motion in the shared region tick
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m28s
Foundation / postgres-tools (push) Successful in 25s
Foundation / server-image (push) Successful in 4m3s
Foundation / image (push) Successful in 4m28s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m28s
Foundation / postgres-tools (push) Successful in 25s
Foundation / server-image (push) Successful in 4m3s
Foundation / image (push) Successful in 4m28s
Rules 12 lives carry a liquid input (motion state, handling, brake and the local flow sample) and step through propose_liquid_cellular_step: maintenance first, then one kinematic tick funded from what is left, so unfundable thrust coasts with the current. A format-3 habitat requires liquid input on every life and older habitats refuse it. Contact feeding sweeps each liquid cell's whole path so a fast cell cannot pass over food; frozen cells keep their motion; corpse bubbles in a format-3 habitat count one merged bubble and use the larger deposit limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -450,6 +450,28 @@ scatter_deposits(CellularHabitatConfig base, std::span<const CellularPatch> pool
|
||||
return base;
|
||||
}
|
||||
|
||||
bool cellular_path_contact(CellularPosition from, CellularPosition to, std::uint32_t extent_um,
|
||||
const CellularPatch& patch) noexcept {
|
||||
if (from == to)
|
||||
return cellular_patch_contact(to, extent_um, patch);
|
||||
const auto dx = static_cast<std::int64_t>(to.x_um) - static_cast<std::int64_t>(from.x_um);
|
||||
const auto dy = static_cast<std::int64_t>(to.y_um) - static_cast<std::int64_t>(from.y_um);
|
||||
const auto reach = std::max<std::int64_t>(
|
||||
1, std::min<std::int64_t>(patch.radius_um == 0 ? cellular_patch_pitch_um : patch.radius_um,
|
||||
extent_um) /
|
||||
2);
|
||||
const auto span = std::max(dx < 0 ? -dx : dx, dy < 0 ? -dy : dy);
|
||||
const auto steps = std::clamp<std::int64_t>((span + reach - 1) / reach, 1, 256);
|
||||
for (std::int64_t step = 0; step <= steps; ++step) {
|
||||
const CellularPosition at{
|
||||
static_cast<std::uint64_t>(static_cast<std::int64_t>(from.x_um) + dx * step / steps),
|
||||
static_cast<std::uint64_t>(static_cast<std::int64_t>(from.y_um) + dy * step / steps)};
|
||||
if (cellular_patch_contact(at, extent_um, patch))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cellular_patch_contact(CellularPosition position, std::uint32_t extent_um,
|
||||
const CellularPatch& patch) noexcept {
|
||||
if (patch.kind == CellularDepositKind::patch)
|
||||
|
||||
@@ -66,11 +66,17 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
if (lives.size() > max_cellular_tick_lives)
|
||||
return std::unexpected{CellularRegionStepError::too_many_lives};
|
||||
|
||||
const bool liquid = habitat.config().format == cellular_habitat_liquid_format;
|
||||
const auto deposit_limit = liquid ? max_cellular_liquid_deposits : max_cellular_patches;
|
||||
std::vector<const CellularLifeStepInput*> ordered;
|
||||
ordered.reserve(lives.size());
|
||||
for (const auto& life : lives) {
|
||||
if (life.life_id == 0)
|
||||
return std::unexpected{CellularRegionStepError::invalid_life_id};
|
||||
// Rules 12: liquid motion in a format-3 habitat, for every life, and nowhere else.
|
||||
if (life.liquid.has_value() != liquid ||
|
||||
(liquid && (life.intent.intake_target || !rules.contact_feeding)))
|
||||
return std::unexpected{CellularRegionStepError::invalid_intent};
|
||||
if (life.intent.frozen &&
|
||||
(life.intent.movement != CellularIntent{} || life.intent.intake_target ||
|
||||
life.intent.engulf || life.intent.bud))
|
||||
@@ -111,6 +117,8 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
frozen.position = life->position;
|
||||
frozen.reserve_after = life->reserve;
|
||||
frozen.heat_after = life->heat;
|
||||
if (life->liquid)
|
||||
frozen.motion = life->liquid->motion; // Anchored while frozen.
|
||||
candidate.lives.push_back({life->life_id, frozen});
|
||||
survivors.push_back(life);
|
||||
continue;
|
||||
@@ -121,8 +129,12 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
intent.intake_target.reset();
|
||||
intent.engulf = false;
|
||||
const auto step =
|
||||
propose_cellular_step(begin_tick, area, life->position, life->extent_um, intent,
|
||||
life->reserve, life->heat, life->budget, habitat);
|
||||
life->liquid
|
||||
? propose_liquid_cellular_step(begin_tick, area, life->position, life->extent_um,
|
||||
intent.movement, *life->liquid, life->reserve,
|
||||
life->heat, life->budget)
|
||||
: propose_cellular_step(begin_tick, area, life->position, life->extent_um, intent,
|
||||
life->reserve, life->heat, life->budget, habitat);
|
||||
if (!step && step.error() == CellularStepError::insufficient_maintenance) {
|
||||
CellularCorpseCandidate corpse{life->life_id, life->position, life->reserve};
|
||||
for (std::size_t channel = 0; channel < corpse.inventory.matter.size(); ++channel) {
|
||||
@@ -187,7 +199,11 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
std::optional<std::size_t> first;
|
||||
for (std::size_t index = 0; index < patch_stock.size(); ++index) {
|
||||
const auto& deposit = habitat.patches()[index];
|
||||
if (!cellular_patch_contact(result.position, life->extent_um, deposit))
|
||||
// Liquid motion sweeps its whole path, so a fast cell cannot skip food.
|
||||
if (life->liquid
|
||||
? !cellular_path_contact(life->position, result.position, life->extent_um,
|
||||
deposit)
|
||||
: !cellular_patch_contact(result.position, life->extent_um, deposit))
|
||||
continue;
|
||||
bool took = false;
|
||||
for (std::size_t channel = 0; channel < limit.size(); ++channel) {
|
||||
@@ -337,8 +353,7 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
continue;
|
||||
accounting::Inventory single{};
|
||||
channel_of(single, channel) = amount;
|
||||
if (habitat.patches().size() + candidate.new_patches.size() >=
|
||||
max_cellular_patches) {
|
||||
if (habitat.patches().size() + candidate.new_patches.size() >= deposit_limit) {
|
||||
overflow.push_back({deposit.life_id, deposit.source, deposit.position,
|
||||
single, deposit.extent_um});
|
||||
continue;
|
||||
@@ -356,9 +371,12 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
address.x_um = address.x_um + 1 < area.width_um ? address.x_um + 1 : 0;
|
||||
const auto at = std::ranges::lower_bound(candidate.new_patches, address, {},
|
||||
&CellularPatch::address);
|
||||
candidate.new_patches.insert(at, CellularPatch{address, deposit.source, single,
|
||||
0, cellular_mote_radius_um,
|
||||
CellularDepositKind::mote});
|
||||
CellularPatch bubble{
|
||||
address, deposit.source, single,
|
||||
0, cellular_mote_radius_um, CellularDepositKind::mote};
|
||||
if (liquid)
|
||||
bubble.merged = 1;
|
||||
candidate.new_patches.insert(at, bubble);
|
||||
}
|
||||
}
|
||||
deposits = std::move(overflow); // A full habitat: the nearest deposit takes it.
|
||||
@@ -377,7 +395,7 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
||||
return std::unexpected{CellularRegionStepError::overflow};
|
||||
continue;
|
||||
}
|
||||
if (habitat.patches().size() + candidate.new_patches.size() < max_cellular_patches) {
|
||||
if (habitat.patches().size() + candidate.new_patches.size() < deposit_limit) {
|
||||
candidate.new_patches.insert(made, {address, deposit.source, deposit.inventory});
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -96,4 +96,61 @@ propose_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosit
|
||||
candidate.intake = *intake;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
std::expected<CellularStepCandidate, CellularStepError>
|
||||
propose_liquid_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosition position,
|
||||
std::uint32_t extent_um, CellularIntent movement,
|
||||
const CellularLiquidInput& liquid, accounting::Inventory reserve,
|
||||
accounting::Inventory heat, const MetabolicBudget& budget) noexcept {
|
||||
if (begin_tick == std::numeric_limits<std::uint64_t>::max())
|
||||
return std::unexpected{CellularStepError::invalid_tick};
|
||||
if (budget.rate_microseconds != rate_period_microseconds)
|
||||
return std::unexpected{CellularStepError::unsupported_rate_period};
|
||||
const auto maintenance = accounting::per_tick(
|
||||
budget.maintenance.value, cellular_motion_tick_microseconds, accounting::Rounding::up);
|
||||
if (!maintenance)
|
||||
return std::unexpected{CellularStepError::overflow};
|
||||
if (reserve.energy.value < *maintenance)
|
||||
return std::unexpected{CellularStepError::insufficient_maintenance};
|
||||
if (!credit_heat(heat, *maintenance))
|
||||
return std::unexpected{CellularStepError::overflow};
|
||||
reserve.energy.value -= *maintenance;
|
||||
|
||||
const auto motion =
|
||||
step_cellular_kinematics(area, position, extent_um, liquid.motion, {movement, liquid.brake},
|
||||
liquid.handling, liquid.flow, reserve.energy);
|
||||
if (!motion)
|
||||
return std::unexpected{CellularStepError::motion};
|
||||
if (!credit_heat(heat, motion->cost.value))
|
||||
return std::unexpected{CellularStepError::overflow};
|
||||
reserve.energy.value -= motion->cost.value;
|
||||
|
||||
CellularStepCandidate candidate{};
|
||||
candidate.begin_tick = begin_tick;
|
||||
candidate.end_tick = begin_tick + 1;
|
||||
candidate.position = motion->position;
|
||||
candidate.reserve_after = reserve;
|
||||
candidate.heat_after = heat;
|
||||
candidate.maintenance_cost = {*maintenance};
|
||||
candidate.movement_cost = motion->cost;
|
||||
candidate.motion = motion->state;
|
||||
candidate.path_um = motion->path_um;
|
||||
switch (motion->thrust) {
|
||||
case CellularThrustStatus::idle:
|
||||
candidate.movement_status = CellularMovementStatus::not_requested;
|
||||
break;
|
||||
case CellularThrustStatus::unfunded:
|
||||
candidate.movement_status = CellularMovementStatus::insufficient_reserve;
|
||||
break;
|
||||
case CellularThrustStatus::applied:
|
||||
// Blocked only when an edge stopped it; a sub-micrometre start is still moving.
|
||||
candidate.movement_status = motion->position == position &&
|
||||
motion->state.velocity_x_q10 == 0 &&
|
||||
motion->state.velocity_y_q10 == 0
|
||||
? CellularMovementStatus::blocked
|
||||
: CellularMovementStatus::moved;
|
||||
break;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
} // namespace evo::biology
|
||||
|
||||
Reference in New Issue
Block a user