feat(biology): evolve photosynthetic producers that capture light
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (deploy) (push) Successful in 5m15s
Foundation / checks (network) (push) Successful in 21m56s
Foundation / checks (client) (push) Successful in 22m54s
Foundation / checks (tsan) (push) Successful in 47m4s
Foundation / checks (postgres) (push) Successful in 1h15m49s
Foundation / checks (checks) (push) Failing after 1h30m4s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (deploy) (push) Successful in 5m15s
Foundation / checks (network) (push) Successful in 21m56s
Foundation / checks (client) (push) Successful in 22m54s
Foundation / checks (tsan) (push) Successful in 47m4s
Foundation / checks (postgres) (push) Successful in 1h15m49s
Foundation / checks (checks) (push) Failing after 1h30m4s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
ADR-0175 implements ADR-0136 step C with trial costs to be balanced after playtesting. Genome schema 5 adds a photosynthesis efficiency (empty in schemas 1-4, so earlier offers and draws are unchanged; mutation operators 29-32 are appended). Development version 5 builds the organelles as internal membrane (p/4 of structure, upkept twice) and slows movement by p/2 per thousand. Founder 4 and cellular rules 11 let lineages earn the capability as an offspring plan that children express. Owner format 9 declares the region's light. Inside each tick's detached candidate, active unfrozen producers capture cross-section x irradiance x efficiency (a quarter while moving), credited to the reserve and boundary inflow together and replayed from recorded intentions. Well-lit wildlife producers hold still. The joint owner keeps infall, water and radiation and nests a rules-11 owner unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,8 +85,9 @@ void audit(const CellularEnvironment& value) {
|
||||
expected.matter[channel].value +=
|
||||
ledger.incoming.matter[channel].value - ledger.outgoing.matter[channel].value;
|
||||
require(state.current_total() == expected, "joint owner broke open-boundary closure");
|
||||
require(ledger.incoming == value.imported() &&
|
||||
ledger.outgoing == Inventory{value.exported(), {}},
|
||||
auto environmental = value.imported();
|
||||
environmental.energy.value += state.captured_light().value; // A rules-11 owner's light.
|
||||
require(ledger.incoming == environmental && ledger.outgoing == Inventory{value.exported(), {}},
|
||||
"environment flows differ from the nested boundary ledger");
|
||||
for (std::size_t index = 0; index < value.sources().size(); ++index) {
|
||||
const auto& made = value.sources()[index];
|
||||
@@ -238,6 +239,151 @@ void raw_and_cohort() {
|
||||
<< raw->exported().value << " pJ at tick " << raw->tick() << '\n';
|
||||
}
|
||||
|
||||
// ADR-0175: a rules-11 region whose founder is born after the upgrade (founder 4).
|
||||
Owner producer_region(std::uint64_t irradiance) {
|
||||
auto state = opening(7, true, 1, false);
|
||||
checked(state->advance_tick({}), "producer genesis tick");
|
||||
state = checked(state->migration_upgrade_candidate(), "boundary upgrade");
|
||||
state = checked(state->maturation_upgrade_candidate(), "maturation upgrade");
|
||||
state = checked(state->inheritance_upgrade_candidate(), "inheritance upgrade");
|
||||
const CellularLight light{irradiance, 1, {irradiance == 0 ? 0 : 1ULL << 50}};
|
||||
require(!state->photosynthesis_upgrade_candidate({1, 0, {1}}) &&
|
||||
!state->photosynthesis_upgrade_candidate({1, 1, {0}}),
|
||||
"invalid light declared");
|
||||
state = checked(state->photosynthesis_upgrade_candidate(light), "photosynthesis upgrade");
|
||||
require(state->rules_version() == cellular_lives_photosynthesis_rules &&
|
||||
state->format_version() == cellular_lives_light_format && state->light() == light &&
|
||||
!state->photosynthesis_upgrade_candidate(light),
|
||||
"photosynthesis upgrade repeated, wrong versions or lost light");
|
||||
LifeAccount account{};
|
||||
account.back() = 1;
|
||||
state = checked(state->birth_candidate({account, 1}, {100, 100, 100, 100, {state->tick()}}),
|
||||
"founder 4 birth");
|
||||
const auto genome = state->archive().find(100);
|
||||
require(genome && genome->schema_version() == biology::genome_schema_v5 &&
|
||||
!genome->carries(biology::Capability::photosynthesis),
|
||||
"founder 4 is not schema 5 without photosynthesis");
|
||||
return state;
|
||||
}
|
||||
bool photosynthetic(const CellularLives& state, std::uint64_t genome) {
|
||||
const auto found = state.archive().find(genome);
|
||||
return found && found->carries(biology::Capability::photosynthesis);
|
||||
}
|
||||
void closed(const CellularLives& state) {
|
||||
const auto& ledger = state.boundary_ledger();
|
||||
auto expected = state.opening_total();
|
||||
expected.energy.value += ledger.incoming.energy.value - ledger.outgoing.energy.value;
|
||||
require(state.current_total() == expected && ledger.incoming.energy == state.captured_light(),
|
||||
"lit region broke closure or booked light outside the ledger");
|
||||
}
|
||||
struct Producers {
|
||||
std::unique_ptr<CellularPopulation> population;
|
||||
std::uint64_t plan{}, child{}, captured{}, lit_ticks{}, still{};
|
||||
};
|
||||
// The founder earns photosynthesis as its offspring plan (rules 10+), buds a child that
|
||||
// expresses it, and that child captures light inside the owner's own tick.
|
||||
Producers grow_producers(std::uint64_t irradiance) {
|
||||
Producers out;
|
||||
out.population = checked(
|
||||
CellularPopulation::create(producer_region(irradiance), {false, 900, 1'600}), "producers");
|
||||
auto& population = *out.population;
|
||||
for (unsigned tick = 0; tick < 80'000 && out.plan == 0; ++tick) {
|
||||
const auto& life = population.state().lives().front();
|
||||
if (!life.mutation.offer) {
|
||||
checked(population.advance_tick(controlled(population.state())), "feed");
|
||||
continue;
|
||||
}
|
||||
const auto& offer = *life.mutation.offer;
|
||||
const auto found = std::ranges::find_if(offer.candidates, [](const auto& candidate) {
|
||||
return candidate.target == biology::Capability::photosynthesis &&
|
||||
candidate.effect == biology::MutationEffect::acquire;
|
||||
});
|
||||
const auto successor = 2'000'000 + tick;
|
||||
// Decided before the tick: the tick replaces the state the offer lives in.
|
||||
const bool acquire = found != offer.candidates.end();
|
||||
const CellularMutationSelection selection{100, life.mutation.event_index,
|
||||
life.mutation.offer_tick, successor,
|
||||
acquire ? found->operator_id : std::uint16_t{0}};
|
||||
checked(population.advance_tick(controlled(population.state()), std::span{&selection, 1}),
|
||||
"selection tick");
|
||||
if (acquire)
|
||||
out.plan = successor;
|
||||
}
|
||||
require(
|
||||
out.plan != 0 && photosynthetic(population.state(), out.plan) &&
|
||||
!photosynthetic(population.state(), population.state().lives().front().identity.genome),
|
||||
"founder never planned photosynthesis or expressed it itself");
|
||||
for (unsigned tick = 0; tick < 40'000 && out.child == 0; ++tick) {
|
||||
checked(population.advance_tick(controlled(population.state(), true)), "bud");
|
||||
for (const auto& life : population.state().lives())
|
||||
if (life.parent_life == 100 && photosynthetic(population.state(), life.identity.genome))
|
||||
out.child = life.identity.life;
|
||||
}
|
||||
require(out.child != 0, "no child expressed the photosynthesis plan");
|
||||
for (unsigned tick = 0; tick < 400; ++tick) {
|
||||
const auto before = population.state().captured_light().value;
|
||||
const auto intents =
|
||||
checked(wildlife_intents(population.state(), population.state().tick() + 1), "intents");
|
||||
for (const auto& intent : intents) {
|
||||
const auto life = std::ranges::find(population.state().lives(), intent.life_id,
|
||||
[](const auto& l) { return l.identity.life; });
|
||||
if (photosynthetic(population.state(), life->identity.genome) &&
|
||||
intent.intent == biology::CellularStepIntent{})
|
||||
++out.still;
|
||||
}
|
||||
checked(population.advance_tick(controlled(population.state())), "lit tick");
|
||||
const auto gained = population.state().captured_light().value - before;
|
||||
out.captured += gained;
|
||||
out.lit_ticks += gained > 0 ? 1 : 0;
|
||||
closed(population.state());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
void producers() {
|
||||
auto trial = grow_producers(cellular_light_trial_irradiance);
|
||||
require(trial.captured > 0 && trial.lit_ticks > 0, "a photosynthetic child captured no light");
|
||||
const auto& state = trial.population->state();
|
||||
const auto bytes = state.snapshot();
|
||||
require(bytes.size() > 8 && bytes[7] == '9', "lit region not owner format 9");
|
||||
auto restored =
|
||||
checked(CellularPopulation::restore(trial.population->snapshot(), state.world(),
|
||||
state.region(), state.frame(), state.tick()),
|
||||
"lit restore");
|
||||
for (unsigned tick = 0; tick < 200; ++tick) {
|
||||
checked(trial.population->advance_tick(controlled(trial.population->state())), "a");
|
||||
checked(restored->advance_tick(controlled(restored->state())), "b");
|
||||
require(trial.population->snapshot() == restored->snapshot(),
|
||||
"lit region diverged after restore");
|
||||
}
|
||||
// A joint owner nests the lit owner: its own infall stays separate from the light.
|
||||
const auto& lit_state = trial.population->state();
|
||||
auto joint_config = config({}, 9);
|
||||
joint_config.geometry.box.width = {lit_state.area().width_um};
|
||||
joint_config.geometry.box.height = {lit_state.area().height_um};
|
||||
auto joint = checked(CellularEnvironment::create(std::move(restored), std::move(joint_config)),
|
||||
"lit joint");
|
||||
for (unsigned tick = 0; tick < 200; ++tick) {
|
||||
step(*joint);
|
||||
audit(*joint);
|
||||
}
|
||||
require(joint->state().captured_light().value > 0, "nested owner stopped capturing");
|
||||
// Without light nothing is captured, and a producer forages as before.
|
||||
auto dark = grow_producers(0);
|
||||
require(dark.captured == 0 && dark.population->state().captured_light().value == 0,
|
||||
"a dark region captured light");
|
||||
// Same history until the plan, then capture scales exactly with irradiance. (These
|
||||
// producers always touch food, so they hold still in any light; the light-driven
|
||||
// holding-still branch is not observable in this rich fixture.)
|
||||
auto bright = grow_producers(cellular_light_trial_irradiance * 20);
|
||||
require(bright.child == trial.child && bright.captured == 20 * trial.captured &&
|
||||
bright.still == trial.still && dark.still == trial.still,
|
||||
"capture did not scale with irradiance or light changed the controller");
|
||||
std::cout << "producers: plan " << trial.plan << ", child " << trial.child << ", captured "
|
||||
<< trial.captured << " pJ over " << trial.lit_ticks << " lit ticks (bright "
|
||||
<< bright.captured << ", still intents " << bright.still << " vs dark " << dark.still
|
||||
<< ")\n";
|
||||
}
|
||||
|
||||
// A full habitat refuses new deposits: bubbles are counted skipped, never deferred.
|
||||
void capacity() {
|
||||
auto value = environment(founders(),
|
||||
@@ -517,6 +663,7 @@ int main(int argc, char** argv) {
|
||||
atomic_and_restore();
|
||||
raw_and_cohort();
|
||||
capacity();
|
||||
producers();
|
||||
traces();
|
||||
refusals();
|
||||
auto value = restart_fixture();
|
||||
|
||||
Reference in New Issue
Block a user