feat(cellular): energy cycles back through the spent pool (ADR-0182 section 14)
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m42s
Foundation / checks (checks) (push) Successful in 6s
Foundation / checks (client) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 31s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / server-image (push) Successful in 4m45s
Foundation / checks (network) (push) Successful in 4s
Foundation / image (push) Successful in 5m31s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m42s
Foundation / checks (checks) (push) Successful in 6s
Foundation / checks (client) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 31s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / server-image (push) Successful in 4m45s
Foundation / checks (network) (push) Successful in 4s
Foundation / image (push) Successful in 5m31s
Energy cells used went to the region's heat store and never returned, so a region without photosynthesizers drained: region 16's wildlife ate its energy and starved, and its matter-only drip filled the deposit limit. Two optional rules-13 tuning keys, adoptable live: spent.heat_recycle_per_mille moves that share of the heat store to the spent pool at the end of every tick, before the drip (1,000 closes the loop and returns heat built up before), and spent.drip_absorb lets a drip at the deposit limit join the first existing bubble at or after its spot. Both use the reserved word after the offer interval, so rules without them keep their bytes, digests, checkpoints and replays. The DEV revamp file turns both on. The region view reports heat and the cycle; the portal counts heat in the region's energy and ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,9 @@ void renders_cells_and_deposits() {
|
||||
require(text.find(",\"bubbles\":" + list(bubbles) + "}") != std::string::npos,
|
||||
"bubble totals");
|
||||
require(text.find("\"drip\"") == std::string::npos, "a drip before rules 13");
|
||||
require(text.find("],\"heat\":" + std::to_string(state->heat().energy.value) +
|
||||
",\"cells_total\":") != std::string::npos,
|
||||
"heat");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +132,14 @@ void renders_the_drip() {
|
||||
.kill_bubble_per_thousand = 500},
|
||||
.drip_interval_ticks = 20,
|
||||
.drip_bubble_pj = 20'000'000,
|
||||
.drip_bubble_fg = 1'000'000};
|
||||
.drip_bubble_fg = 1'000'000,
|
||||
.heat_recycle_per_thousand = 1'000,
|
||||
.drip_absorb = true};
|
||||
state = checked(state->revamp_upgrade_candidate(rules), "revamp upgrade");
|
||||
const auto view = render_cellular_admin_view(*state, {});
|
||||
require(view.find("],\"drip\":[20,20000000,1000000],\"cells_total\":") != std::string::npos,
|
||||
"rules-13 drip");
|
||||
require(view.find(",\"drip\":[20,20000000,1000000,1000,1],\"cells_total\":") !=
|
||||
std::string::npos,
|
||||
"rules-13 drip and energy cycle");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1059,6 +1059,101 @@ void tuning_is_adopted_and_replayed() {
|
||||
require(!encode_cellular_batch(twice), "two adoptions shared a batch");
|
||||
}
|
||||
|
||||
// ADR-0182 section 14: adopted energy cycling returns the region's heat (what its cells used,
|
||||
// and what had built up before) to the spent pool before the drip. The fields sit in a reserved
|
||||
// word, so historical rules keep their bytes; adopted rules restore and replay.
|
||||
void heat_cycles_back() {
|
||||
auto live = revamp_region();
|
||||
for (int tick = 0; tick < 30; ++tick)
|
||||
checked(live->advance_tick(swim(*live, {1'000, 0})), "cells use energy");
|
||||
const auto heat = live->heat().energy.value;
|
||||
require(heat > 0, "the cells used no energy");
|
||||
const auto before = live->revamp_rules();
|
||||
auto cycling = before;
|
||||
cycling.heat_recycle_per_thousand = 1'000;
|
||||
cycling.drip_absorb = true;
|
||||
cycling.drip_interval_ticks = 0; // No drip: the whole recycled heat stays in the pool.
|
||||
const auto old_bytes = encode_cellular_revamp_rules(before);
|
||||
const auto new_bytes = encode_cellular_revamp_rules(cycling);
|
||||
require(cellular_revamp_valid(cycling) && old_bytes.size() == new_bytes.size() &&
|
||||
old_bytes != new_bytes,
|
||||
"the energy cycle is not a same-size distinct encoding");
|
||||
auto excessive = cycling;
|
||||
excessive.heat_recycle_per_thousand = 1'001;
|
||||
require(!cellular_revamp_valid(excessive), "more than all the heat was recycled");
|
||||
|
||||
std::array<std::uint8_t, 32> digest{};
|
||||
digest.fill(9);
|
||||
const std::vector commands{cellular_adopt_tuning_command(1, 7, digest)};
|
||||
std::vector<CellularAdminResult> results;
|
||||
auto after =
|
||||
checked(live->admin_candidate(commands, &results,
|
||||
[&](std::uint64_t, const std::array<std::uint8_t, 32>&) {
|
||||
return std::optional{cycling};
|
||||
}),
|
||||
"the energy cycle is adopted");
|
||||
require(results.size() == 1 && results.front().applied && after->revamp_rules() == cycling,
|
||||
"the energy cycle was not adopted");
|
||||
require(restore(*after)->revamp_rules() == cycling &&
|
||||
restore(*after)->snapshot() == after->snapshot(),
|
||||
"the energy cycle does not restore");
|
||||
|
||||
const auto spent = after->spent().energy.value;
|
||||
const auto twin = restore(*after);
|
||||
const auto intents = swim(*after, {1'000, 0});
|
||||
checked(after->advance_tick(intents), "a cycling tick");
|
||||
require(after->heat().energy.value == 0 && after->spent().energy.value > spent + heat,
|
||||
"the heat, old and new, did not reach the spent pool");
|
||||
checked(twin->advance_tick(intents), "the cycling tick again");
|
||||
require(twin->snapshot() == after->snapshot(), "the cycling tick is not deterministic");
|
||||
// Without the cycle the heat keeps building.
|
||||
checked(live->advance_tick(intents), "a historical tick");
|
||||
require(live->heat().energy.value > heat, "historical rules recycled heat");
|
||||
}
|
||||
|
||||
// A drip at the deposit limit waits, or with the absorbing drip joins an existing bubble.
|
||||
void full_drip_is_absorbed() {
|
||||
biology::CellularHabitatConfig full{};
|
||||
full.world = full.region = full.frame = 1;
|
||||
full.width_um = full.height_um = 1'000;
|
||||
full.format = biology::cellular_habitat_liquid_format;
|
||||
for (std::uint32_t i = 0; i < biology::max_cellular_liquid_deposits; ++i) {
|
||||
biology::CellularPatch bubble{
|
||||
{i % 128 * 7, i / 128 * 11}, 1, {}, i + 1, biology::cellular_mote_radius_um,
|
||||
biology::CellularDepositKind::mote};
|
||||
bubble.merged = 1;
|
||||
bubble.stock.matter[0].value = 10;
|
||||
full.patches.push_back(bubble);
|
||||
}
|
||||
std::ranges::sort(full.patches, {}, &biology::CellularPatch::address);
|
||||
full.next_deposit = biology::max_cellular_liquid_deposits + 1;
|
||||
auto rules = revamp();
|
||||
rules.drip_interval_ticks = 1;
|
||||
accounting::Inventory pool{};
|
||||
pool.energy.value = 30'000'000;
|
||||
pool.matter[0].value = 5;
|
||||
const auto energy = [](const biology::CellularHabitatConfig& c) {
|
||||
std::uint64_t total = 0;
|
||||
for (const auto& patch : c.patches)
|
||||
total += patch.stock.energy.value;
|
||||
return total;
|
||||
};
|
||||
|
||||
auto waiting = full;
|
||||
auto kept = pool;
|
||||
require(cellular_drip_spent(waiting, kept, rules, 1, 1, 1, 1) && kept == pool &&
|
||||
waiting == full,
|
||||
"a full habitat took a drip without absorbing");
|
||||
rules.drip_absorb = true;
|
||||
auto absorbing = full;
|
||||
auto left = pool;
|
||||
require(cellular_drip_spent(absorbing, left, rules, 1, 1, 1, 1), "the absorbing drip");
|
||||
require(absorbing.patches.size() == full.patches.size() &&
|
||||
left.energy.value == pool.energy.value - rules.drip_bubble_pj &&
|
||||
left.matter[0].value == 0 && energy(absorbing) == rules.drip_bubble_pj,
|
||||
"the drip did not join existing bubbles");
|
||||
}
|
||||
|
||||
// The safety revision preserves all five channels, follows both control choices,
|
||||
// separates eligible predator/prey siblings and replays their actual motion exactly.
|
||||
void safety_split(bool become) {
|
||||
@@ -1219,6 +1314,8 @@ void safe_bud_provision(bool become) {
|
||||
int main() try {
|
||||
admin_commands_apply_and_replay();
|
||||
tuning_is_adopted_and_replayed();
|
||||
heat_cycles_back();
|
||||
full_drip_is_absorbed();
|
||||
safety_split(false);
|
||||
safety_split(true);
|
||||
safe_bud_provision(false);
|
||||
|
||||
@@ -74,6 +74,9 @@ CellularRevampTuning trial(bool safety = true) {
|
||||
t.reproduction_safety_version = 0;
|
||||
t.body_growth_reserve_seconds = 0;
|
||||
t.reproduction_split_launch_um_per_s = 0;
|
||||
// The DEV revamp file cycles energy (ADR-0182 section 14).
|
||||
t.spent_heat_recycle_per_mille = 1'000;
|
||||
t.spent_drip_absorb = 1;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@@ -155,6 +158,20 @@ void refusals() {
|
||||
historical.erase(at, historical.find('\n', at) - at + 1);
|
||||
}
|
||||
CHECK(parse_cellular_revamp_tuning(historical)->reproduction_safety_version == 0);
|
||||
// The energy cycle keys (ADR-0182 section 14) are optional and bounded.
|
||||
auto uncycled = base;
|
||||
for (const auto* key : {"spent.heat_recycle_per_mille", "spent.drip_absorb"}) {
|
||||
const auto at = uncycled.find(key);
|
||||
uncycled.erase(at, uncycled.find('\n', at) - at + 1);
|
||||
}
|
||||
CHECK(parse_cellular_revamp_tuning(uncycled) == trial());
|
||||
const auto cycled = parse_cellular_revamp_tuning(
|
||||
with(with(base, "spent.heat_recycle_per_mille", "1_000"), "spent.drip_absorb", "1"));
|
||||
CHECK(cycled && cycled->spent_heat_recycle_per_mille == 1'000 &&
|
||||
cycled->spent_drip_absorb == 1);
|
||||
CHECK(error_of(with(base, "spent.heat_recycle_per_mille", "1001")) ==
|
||||
CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "spent.drip_absorb", "2")) == CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "playtest.starting_wildlife_cells", "256")) ==
|
||||
CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "playtest.starting_wildlife_cells", "-1")) ==
|
||||
|
||||
Reference in New Issue
Block a user