Add reproduction safety trial and resizable cellular panels
This commit is contained in:
@@ -375,8 +375,16 @@ const CellularOwnedLife& life_of(const CellularLives& state, std::uint64_t id) {
|
||||
require(found != state.lives().end(), "life missing");
|
||||
return *found;
|
||||
}
|
||||
Owner offering_region(std::uint64_t cost_pj) {
|
||||
Owner offering_region(std::uint64_t cost_pj, bool safety = false) {
|
||||
auto rules = revamp();
|
||||
if (safety) {
|
||||
rules.safety_version = 1;
|
||||
rules.growth_reserve_seconds = 60;
|
||||
rules.split_launch_um_per_s = 800;
|
||||
rules.step.split_evenly = true;
|
||||
rules.split_share_per_thousand = 800;
|
||||
rules.split_min_growth = 500;
|
||||
}
|
||||
rules.offer_interval_ticks = 40;
|
||||
for (auto& m : rules.mutations) {
|
||||
m.cost.energy.value = cost_pj;
|
||||
@@ -576,15 +584,23 @@ void thrust_moves_affinity() {
|
||||
// Rules 13 (reproduction plan sections 6-7): Adhesion turns the cell into a two-member organism
|
||||
// that holds its whole body and reserve; the organism expresses later mutations as a whole,
|
||||
// buds add internal members, and at the threshold it emerges as a recorded export.
|
||||
Owner adhesion_region(std::uint64_t carbon_fee = 0) {
|
||||
Owner adhesion_region(std::uint64_t carbon_fee = 0, bool safety = false,
|
||||
std::uint32_t growth_rate = 0) {
|
||||
auto rules = revamp();
|
||||
if (safety) {
|
||||
rules.safety_version = 1;
|
||||
rules.growth_reserve_seconds = 60;
|
||||
rules.split_launch_um_per_s = 800;
|
||||
rules.step.split_evenly = true;
|
||||
rules.step.collection_percent = 1'000;
|
||||
}
|
||||
rules.bud_fee.matter[0].value = carbon_fee;
|
||||
rules.bud_fee_scale_percent = carbon_fee == 0 ? 0 : 100;
|
||||
rules.offer_interval_ticks = 40;
|
||||
rules.bounds.buds_for_adhesion = 0;
|
||||
rules.emerge_members = 3;
|
||||
rules.emerge_mass_fg = 0;
|
||||
rules.growth_per_tick_centi_mille = 0; // Collected matter stays in the reserve for buds.
|
||||
rules.growth_per_tick_centi_mille = growth_rate; // Zero keeps collected matter for buds.
|
||||
for (auto& m : rules.mutations)
|
||||
m.enabled = false;
|
||||
// Adhesion and five movement mutations: three options capped at 70% each need five.
|
||||
@@ -593,6 +609,29 @@ Owner adhesion_region(std::uint64_t carbon_fee = 0) {
|
||||
for (std::size_t i = 0; i < 5; ++i)
|
||||
rules.mutations.at(i).enabled = true;
|
||||
auto fresh = opening(7, true, 4, false); // A 6 mm region, rich motes at four sites.
|
||||
if (safety) {
|
||||
// Put finite food within reach of any seeded founder position. The test
|
||||
// isolates funding/allocation, rather than depending on the forager's search.
|
||||
auto habitat_config = fresh->habitat().config();
|
||||
for (auto& patch : habitat_config.patches)
|
||||
if (patch.kind == biology::CellularDepositKind::pool)
|
||||
patch.radius_um = biology::max_cellular_deposit_radius_um;
|
||||
auto habitat = checked(biology::CellularHabitat::create(std::move(habitat_config)),
|
||||
"safety funding habitat");
|
||||
auto nursery =
|
||||
checked(PrimitiveLives::create(
|
||||
{fresh->world(),
|
||||
fresh->region(),
|
||||
fresh->frame(),
|
||||
17,
|
||||
fresh->nursery(),
|
||||
{{1'000, 1'000}, {1'000, 4'000}, {4'000, 1'000}, {4'000, 4'000}}}),
|
||||
"safety funding nursery");
|
||||
fresh = checked(CellularLives::create(*nursery, std::move(habitat),
|
||||
{{6'000, 6'000}, 0, 293'150},
|
||||
CellularLivesProfile::foraging),
|
||||
"safety funding opening");
|
||||
}
|
||||
checked(fresh->advance_tick({}), "genesis tick");
|
||||
fresh = checked(fresh->migration_upgrade_candidate(), "boundary upgrade");
|
||||
fresh = checked(fresh->maturation_upgrade_candidate(), "maturation upgrade");
|
||||
@@ -834,9 +873,169 @@ void trace_replays() {
|
||||
!decoded.ticks.at(6).lives.front().intent.emerge,
|
||||
"Emerge did not survive the trace");
|
||||
}
|
||||
|
||||
// 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) {
|
||||
auto state = offering_region(0, true);
|
||||
for (int tick = 0; tick < 40; ++tick)
|
||||
checked(state->advance_tick(swim(*state, {1'000, 0})), "earn safety offer");
|
||||
auto base = restore(*state);
|
||||
require(base->revamp_rules() == state->revamp_rules(), "safety settings lost on restore");
|
||||
auto invalid = state->revamp_rules();
|
||||
invalid.safety_version = 2;
|
||||
require(!cellular_revamp_valid(invalid), "an unknown safety revision was admitted");
|
||||
invalid.safety_version = 0;
|
||||
require(!cellular_revamp_valid(invalid), "historical rules accepted hidden safety amounts");
|
||||
auto unsplit = restore(*state);
|
||||
const auto intents = swim(*state, {});
|
||||
checked(unsplit->advance_tick(intents), "unsplit comparison");
|
||||
const auto pre = life_of(*unsplit, 101);
|
||||
auto choice = choose(*state, 101, life_of(*state, 101).revamp.offer.ids.at(0), 9'000);
|
||||
choice.front().become = become;
|
||||
const auto execution =
|
||||
checked(state->advance_tick_with_mutations(intents, choice), "safe split");
|
||||
require(execution.mutations.front().result == CellularMutationResult::split_applied,
|
||||
"safety split refused");
|
||||
const auto identity = cellular_bud_identity(state->region(), 1);
|
||||
const auto parent = life_of(*state, 101);
|
||||
const auto child = life_of(*state, identity);
|
||||
const auto expressed = state->archive().find(pre.identity.genome);
|
||||
const auto successor = state->archive().find(9'000);
|
||||
const auto expected =
|
||||
checked(biology::split_cell(*expressed, *successor, pre.growth, pre.body, pre.reserve,
|
||||
293'150, become ? 800 : 200, 500, state->revamp_rules().body),
|
||||
"expected safety shares");
|
||||
require(
|
||||
parent.body == expected.parent_body && child.body == expected.child_body &&
|
||||
parent.reserve == expected.parent_reserve && child.reserve == expected.child_reserve,
|
||||
"the controlled cell did not receive its 80 percent without growth spending the buffer");
|
||||
require(become ? child.account == account(2) : parent.account == account(2),
|
||||
"safety control went to the wrong cell");
|
||||
const auto parent_budget =
|
||||
checked(biology::metabolic_budget(*expressed, parent.growth, {293'150, {}}, 1000,
|
||||
state->revamp_rules().body),
|
||||
"parent budget");
|
||||
const auto child_budget =
|
||||
checked(biology::metabolic_budget(*successor, child.growth, {293'150, {}}, 1000,
|
||||
state->revamp_rules().body),
|
||||
"child budget");
|
||||
require(!biology::cellular_footprints_contact(parent.position, parent_budget.phenotype.extent,
|
||||
child.position, child_budget.phenotype.extent),
|
||||
"split siblings remained in engulf contact");
|
||||
const auto dx = static_cast<std::int64_t>(child.position.x_um) -
|
||||
static_cast<std::int64_t>(parent.position.x_um);
|
||||
const auto dy = static_cast<std::int64_t>(child.position.y_um) -
|
||||
static_cast<std::int64_t>(parent.position.y_um);
|
||||
require(dx * (std::int64_t{child.motion.velocity_x_q10} - parent.motion.velocity_x_q10) +
|
||||
dy *
|
||||
(std::int64_t{child.motion.velocity_y_q10} - parent.motion.velocity_y_q10) >
|
||||
0,
|
||||
"the newborn was not launched away");
|
||||
auto hunters = swim(*state, {});
|
||||
for (auto& input : hunters)
|
||||
input.intent.engulf = true;
|
||||
checked(state->advance_tick(hunters), "sibling engulf attempt");
|
||||
require(state->lives().size() == base->lives().size() + 1,
|
||||
"a sibling was immediately reclaimed");
|
||||
closed(*state);
|
||||
CellularBatch batch;
|
||||
batch.format_version = cellular_batch_inheritance_format;
|
||||
batch.header = {state->world(), state->region(), state->frame(), {}, {},
|
||||
base->tick(), state->tick()};
|
||||
batch.header.predecessor.fill(1);
|
||||
batch.header.predecessor_digest.fill(2);
|
||||
batch.ticks.push_back({intents, {}, choice});
|
||||
batch.ticks.push_back({hunters, {}, {}});
|
||||
const auto decoded =
|
||||
checked(decode_cellular_batch(checked(encode_cellular_batch(batch), "encode")), "decode");
|
||||
const auto replayed = checked(replay_cellular_batch(*base, decoded), "safety replay");
|
||||
require(replayed->snapshot() == state->snapshot() &&
|
||||
restore(*state)->snapshot() == state->snapshot(),
|
||||
"safety restore/replay diverged");
|
||||
}
|
||||
|
||||
void safe_bud_provision(bool become) {
|
||||
auto state = adhesion_region(100'000, true, 625);
|
||||
for (int tick = 0; tick < 4'000; ++tick) {
|
||||
const auto cost = state->budding_cost(101);
|
||||
if (!cost)
|
||||
throw std::runtime_error("safety fixture has no bud requirement");
|
||||
const auto& reserve = life_of(*state, 101).reserve;
|
||||
bool funded = reserve.energy.value >= cost->energy.value + cost->energy.value / 10;
|
||||
for (std::size_t c = 0; funded && c < reserve.matter.size(); ++c)
|
||||
funded = reserve.matter[c].value >= cost->matter[c].value + cost->matter[c].value / 10;
|
||||
if (funded)
|
||||
break;
|
||||
checked(state->advance_tick(swim(*state, {}, 0x0F)), "fund safe bud");
|
||||
}
|
||||
auto baseline = restore(*state);
|
||||
auto inputs = swim(*state, {});
|
||||
auto request = std::ranges::find(inputs, 101, &CellularLifeIntent::life_id);
|
||||
request->intent.bud = true;
|
||||
request->intent.become = become;
|
||||
auto idle = swim(*baseline, {});
|
||||
checked(baseline->advance_tick(idle), "pre-bud comparison");
|
||||
const auto pre = life_of(*baseline, 101);
|
||||
const auto genome = baseline->archive().find(pre.identity.genome);
|
||||
const auto expected =
|
||||
checked(biology::fund_offspring(*genome, *genome, pre.growth, pre.reserve, 293'150),
|
||||
"ordinary bud funding");
|
||||
const auto result = checked(state->advance_tick_with_mutations(inputs, {}), "safe bud");
|
||||
require(result.buds.size() == 1 && result.buds.front().result == CellularBudResult::budded,
|
||||
"safe bud not funded");
|
||||
const auto& parent = life_of(*state, 101);
|
||||
const auto& child = life_of(*state, result.buds.front().bud_life);
|
||||
require(parent.body == pre.body && child.body == expected.body,
|
||||
"safe budding consumed parent tissue");
|
||||
auto parent_reserve = expected.parent_reserve;
|
||||
auto child_reserve = expected.reserve;
|
||||
if (become) {
|
||||
parent_reserve.matter[0].value -= 100'000;
|
||||
child_reserve.matter[0].value += 100'000;
|
||||
}
|
||||
require(parent.reserve == parent_reserve && child.reserve == child_reserve &&
|
||||
(become ? child.account == account(2) : parent.account == account(2)),
|
||||
"bud provision did not follow control or was reclaimed instead");
|
||||
require(state->habitat().patches().size() == baseline->habitat().patches().size(),
|
||||
"the returned provision also became environmental bubbles");
|
||||
closed(*state);
|
||||
require(restore(*state)->snapshot() == state->snapshot(), "safe bud restore diverged");
|
||||
std::uint32_t growth_steps = 0;
|
||||
const auto child_id = child.identity.life;
|
||||
for (int tick = 0; tick < 800; ++tick) {
|
||||
checked(state->advance_tick(swim(*state, {})), "funded safe growth");
|
||||
const auto& growing = life_of(*state, child_id);
|
||||
const auto report = std::ranges::find(state->last_tick_feedback(), child_id,
|
||||
&CellularLifeTickFeedback::life_id);
|
||||
if (report != state->last_tick_feedback().end() &&
|
||||
report->into_growth != accounting::Inventory{}) {
|
||||
++growth_steps;
|
||||
const auto body_genome = state->archive().find(growing.identity.genome);
|
||||
const auto budget =
|
||||
checked(biology::metabolic_budget(*body_genome, growing.growth, {293'150, {}}, 1000,
|
||||
state->revamp_rules().body),
|
||||
"growing budget");
|
||||
const auto burn = biology::cellular_burn(
|
||||
state->revamp_rules().burn_pj_per_kfg,
|
||||
body_genome->cellular_traits().value_or(biology::founder_cellular_traits).burn, 0);
|
||||
require(biology::cellular_payable_energy(growing.reserve, burn, false) >=
|
||||
budget.demand.value * 60,
|
||||
"growth consumed the resulting body's protected fuel");
|
||||
}
|
||||
if (growing.growth.realized_per_thousand == 1000 || growth_steps == 16)
|
||||
break;
|
||||
}
|
||||
require(growth_steps != 0, "a well-fed juvenile never resumed safe growth");
|
||||
closed(*state);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
safety_split(false);
|
||||
safety_split(true);
|
||||
safe_bud_provision(false);
|
||||
safe_bud_provision(true);
|
||||
starting_wildlife_is_a_funded_opening();
|
||||
shown_bud_charge_includes_the_fee();
|
||||
the_bud_fee_is_paid_in_full_or_refused();
|
||||
|
||||
@@ -36,7 +36,12 @@ void add(Inventory& to, const Inventory& from) {
|
||||
|
||||
// One bubble at (100, 100), or none.
|
||||
std::unique_ptr<CellularHabitat> liquid_map(const Inventory& stock, bool bubble = true) {
|
||||
CellularHabitatConfig config{7, 9, 11, area.width_um, area.height_um, {}};
|
||||
CellularHabitatConfig config{7,
|
||||
9,
|
||||
11,
|
||||
static_cast<std::uint32_t>(area.width_um),
|
||||
static_cast<std::uint32_t>(area.height_um),
|
||||
{}};
|
||||
config.format = cellular_habitat_liquid_format;
|
||||
config.next_deposit = 2;
|
||||
if (bubble) {
|
||||
|
||||
@@ -17,7 +17,7 @@ void check(bool condition, std::source_location at = std::source_location::curre
|
||||
}
|
||||
#define CHECK(expression) check(static_cast<bool>(expression))
|
||||
|
||||
CellularRevampTuning trial() {
|
||||
CellularRevampTuning trial(bool safety = true) {
|
||||
CellularRevampTuning t{.version = 1,
|
||||
.playtest_starting_wildlife_cells = 100,
|
||||
.feeding_collection_percent = 130,
|
||||
@@ -50,7 +50,7 @@ CellularRevampTuning trial() {
|
||||
.mutation_max_offspring = 10,
|
||||
.mutation_carbon_for_light_fg = 20'000'000,
|
||||
.mutation_buds_for_adhesion = 5,
|
||||
.reproduction_split_share_per_mille = 500,
|
||||
.reproduction_split_share_per_mille = 800,
|
||||
.reproduction_split_min_growth_per_mille = 500,
|
||||
.reproduction_bud_fee_e_pj = 250'000,
|
||||
.reproduction_bud_fee_c_fg = 100'000,
|
||||
@@ -62,10 +62,19 @@ CellularRevampTuning trial() {
|
||||
.organism_load_per_mille = 500,
|
||||
.organism_emerge_members = 8,
|
||||
.organism_emerge_mass_fg = 100'000'000,
|
||||
.organism_emerge_reserve_pj = 0};
|
||||
.organism_emerge_reserve_pj = 0,
|
||||
.reproduction_safety_version = 1,
|
||||
.body_growth_reserve_seconds = 60,
|
||||
.reproduction_split_launch_um_per_s = 800};
|
||||
const auto catalog = cellular_catalog();
|
||||
for (std::size_t i = 0; i < catalog.size(); ++i)
|
||||
t.mutations.at(i) = cellular_default_tuning(catalog[i]);
|
||||
if (!safety) {
|
||||
t.reproduction_split_share_per_mille = 500;
|
||||
t.reproduction_safety_version = 0;
|
||||
t.body_growth_reserve_seconds = 0;
|
||||
t.reproduction_split_launch_um_per_s = 0;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -133,6 +142,19 @@ void canonical_round_trip() {
|
||||
|
||||
void refusals() {
|
||||
const auto base = encode_cellular_revamp_tuning(trial());
|
||||
CHECK(error_of(with(base, "reproduction.safety_version", "2")) ==
|
||||
CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "reproduction.safety_version", "0")) ==
|
||||
CellularTuningErrorKind::inconsistent);
|
||||
CHECK(error_of(with(base, "body.growth_reserve_seconds", "0")) ==
|
||||
CellularTuningErrorKind::inconsistent);
|
||||
auto historical = base;
|
||||
for (const auto* key : {"reproduction.safety_version", "body.growth_reserve_seconds",
|
||||
"reproduction.split_launch_um_per_s"}) {
|
||||
const auto at = historical.find(key);
|
||||
historical.erase(at, historical.find('\n', at) - at + 1);
|
||||
}
|
||||
CHECK(parse_cellular_revamp_tuning(historical)->reproduction_safety_version == 0);
|
||||
CHECK(error_of(with(base, "playtest.starting_wildlife_cells", "256")) ==
|
||||
CellularTuningErrorKind::out_of_range);
|
||||
CHECK(error_of(with(base, "playtest.starting_wildlife_cells", "-1")) ==
|
||||
@@ -166,7 +188,7 @@ void refusals() {
|
||||
}
|
||||
|
||||
// The checked-in DEV revamp tuning file must parse; CTest passes its path when it is present.
|
||||
void repository_file(const char* path) {
|
||||
void repository_file(const char* path, bool safety) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
CHECK(file.good());
|
||||
const std::string text{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
@@ -175,7 +197,7 @@ void repository_file(const char* path) {
|
||||
std::fprintf(stderr, "%s: line %zu %s: %s\n", path, parsed.error().line,
|
||||
parsed.error().key.c_str(),
|
||||
std::string{describe(parsed.error().kind)}.c_str());
|
||||
CHECK(parsed && *parsed == trial());
|
||||
CHECK(parsed && *parsed == trial(safety));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -185,7 +207,9 @@ int main(int argc, char** argv) {
|
||||
refusals();
|
||||
mutation_overrides();
|
||||
if (argc > 1)
|
||||
repository_file(argv[1]);
|
||||
repository_file(argv[1], false);
|
||||
if (argc > 2)
|
||||
repository_file(argv[2], true);
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
|
||||
+42
-1
@@ -677,6 +677,44 @@ void cellular_panels(const std::filesystem::path& review) {
|
||||
CHECK(vitals->Pos.x == anchored.x && vitals->Pos.y == anchored.y);
|
||||
drag("Field notes", form.notes_placement, 30, 10);
|
||||
drag("Nearby", form.map_placement, -35, 20);
|
||||
const auto resize_edge = [&](const char* name, HudPanelPlacement& placement, int edge,
|
||||
float delta) {
|
||||
auto* panel = ImGui::FindWindowByName(name);
|
||||
CHECK(panel);
|
||||
const auto before = panel->Size;
|
||||
ImVec2 start{panel->Pos.x + panel->Size.x / 2, panel->Pos.y + panel->Size.y / 2};
|
||||
if (edge == 0 || edge == 2)
|
||||
start.x = panel->Pos.x + (edge == 0 ? panel->Size.x + 1 : -1);
|
||||
else
|
||||
start.y = panel->Pos.y + (edge == 1 ? panel->Size.y + 1 : -1);
|
||||
const ImVec2 end{start.x + (edge % 2 == 0 ? delta : 0),
|
||||
start.y + (edge % 2 != 0 ? delta : 0)};
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, start.x, start.y);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
draw();
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, start.x, start.y);
|
||||
draw();
|
||||
CHECK(!app->take_navigation().click);
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, end.x, end.y);
|
||||
draw();
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, end.x, end.y);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
draw();
|
||||
CHECK(placement.size && placement.anchor && fits(panel));
|
||||
CHECK(edge % 2 == 0 ? panel->Size.x != before.x : panel->Size.y != before.y);
|
||||
CHECK(!app->take_navigation().click);
|
||||
const auto retained = panel->Size;
|
||||
toggle(name, edge == 0 && std::string{name} == "Vitals" ? form.vitals_minimized
|
||||
: std::string{name} == "Field notes" ? form.notes_minimized
|
||||
: form.map_minimized);
|
||||
CHECK(panel->Size.x == retained.x && panel->Size.y == retained.y);
|
||||
CHECK(panel->DC.ChildWindows[0]->ScrollMax.x == 0);
|
||||
};
|
||||
drag("Vitals", form.vitals_placement, 0, 30);
|
||||
resize_edge("Vitals", form.vitals_placement, 0, 35);
|
||||
resize_edge("Field notes", form.notes_placement, 1, 25);
|
||||
resize_edge("Nearby", form.map_placement, 2, -25);
|
||||
resize_edge("Nearby", form.map_placement, 3, -20);
|
||||
if (!review.empty()) {
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, 5, 5);
|
||||
draw();
|
||||
@@ -706,9 +744,12 @@ void cellular_panels(const std::filesystem::path& review) {
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, reset_at.x, reset_at.y);
|
||||
draw();
|
||||
}
|
||||
CHECK(!form.map_placement.anchor && !app->take_navigation().click);
|
||||
CHECK(!form.map_placement.anchor && !form.map_placement.size &&
|
||||
!app->take_navigation().click);
|
||||
form.vitals_placement.anchor.reset();
|
||||
form.notes_placement.anchor.reset();
|
||||
form.vitals_placement.size.reset();
|
||||
form.notes_placement.size.reset();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
draw();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user