Compare commits

..
2 Commits
Author SHA1 Message Date
dingoandClaude Opus 5.5 6b1e5b1ad4 feat(client): recent actions show what each engulf or bud did
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (ecs) (push) Canceled after 45s
Foundation / checks (checks) (push) Canceled after 49s
Foundation / checks (client) (push) Canceled after 49s
Foundation / checks (postgres) (push) Canceled after 48s
Foundation / checks (deploy) (push) Canceled after 54s
Foundation / checks (network) (push) Canceled after 53s
A history entry only said "Committed", so a refused engulf (membrane too
thick) looked like a success. The engulf or bud result reported in the
action's tick view is now attached to that entry: Recent actions shows the
action, its tick and the region's result, green only when it took effect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:03:23 -04:00
dingoandClaude Opus 5.5 bed069e91c fix(wildlife): rules-11 foragers short of energy seek energy, not the nearest mote
The controller steered to the nearest non-empty deposit of any kind and held
still once touching it. A bud parked on a carbon mote fed on carbon until it
starved, and later buds stopped on the first bubble of a corpse's row rather
than its energy one. On rules 11 a wildlife cell whose energy reserve covers
fewer than 1,200 ticks (60 s) of its full demand now passes over energy-free
deposits while it perceives any energy; a fed cell, or one with no energy in
view, still takes the nearest food. Earlier rules are unchanged, so their
recorded and population histories replay exactly. The choice is the new
wildlife_food(), tested directly in photosynthesis-contracts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:03:23 -04:00
7 changed files with 169 additions and 47 deletions
+28 -3
View File
@@ -32,6 +32,9 @@ struct CellActionRecord {
std::uint64_t id{}, life{}, tick{};
MutationChoice choice{};
network::AdmitStatus refusal{network::AdmitStatus::admitted};
// The region's reported effect of this engulf or bud, once a view carries it.
std::optional<network::CellularEngulfResult> engulf;
std::optional<network::CellularBudOutcome> bud;
};
struct CellEnergyChange {
std::uint64_t from_tick{}, to_tick{}, amount{};
@@ -107,11 +110,17 @@ class CellularPlay {
if (view.diagnostics && view.diagnostics->has_tick_effects) {
const auto& d = *view.diagnostics;
if (d.engulf != network::CellularEngulfResult::not_reported &&
d.engulf != network::CellularEngulfResult::not_requested)
d.engulf != network::CellularEngulfResult::not_requested) {
engulf_feedback_ = std::pair{view.tick, d.engulf};
if (auto* record = awaiting_effect(CellAction::engulf, view.tick))
record->engulf = d.engulf;
}
if (d.bud != network::CellularBudOutcome::not_reported &&
d.bud != network::CellularBudOutcome::not_requested)
d.bud != network::CellularBudOutcome::not_requested) {
bud_feedback_ = std::pair{view.tick, d.bud};
if (auto* record = awaiting_effect(CellAction::bud, view.tick))
record->bud = d.bud;
}
}
if (life_ != 0) {
birth_pending_ = false;
@@ -154,7 +163,9 @@ class CellularPlay {
const auto id = allocate_id();
if (id == 0)
return false;
pending_ = CellActionRecord{kind, CellActionState::queued, id, life_, tick, choice};
pending_ = CellActionRecord{
kind, CellActionState::queued, id, life_, tick,
choice, network::AdmitStatus::admitted, std::nullopt, std::nullopt};
return true;
}
void sent() {
@@ -298,6 +309,20 @@ class CellularPlay {
history_.push_back(*pending_);
pending_.reset();
}
// The newest engulf/bud of this life, at or before `tick`, still without a reported
// effect: the view for its tick carries what the region did with it.
CellActionRecord* awaiting_effect(CellAction kind, std::uint64_t tick) {
const auto waiting = [&](const CellActionRecord& r) {
return r.kind == kind && r.life == life_ && r.tick <= tick &&
!(kind == CellAction::engulf ? r.engulf.has_value() : r.bud.has_value());
};
if (pending_ && waiting(*pending_))
return &*pending_;
for (auto it = history_.rbegin(); it != history_.rend(); ++it)
if (waiting(*it))
return &*it;
return nullptr;
}
std::uint64_t next_id_{1}, life_{}, view_tick_{}, birth_tick_{}, birth_request_{}, seen_end_{};
bool connected_{}, fresh_{}, birth_pending_{};
network::PrimitiveLifeResult birth_result_{network::PrimitiveLifeResult::pending};
+37 -23
View File
@@ -587,10 +587,40 @@ const char* cell_action_state(CellActionState state) {
}
return "Unknown";
}
// What the region did with an engulf or bud, as its tick's view reports it ("" when none).
const char* engulf_text(network::CellularEngulfResult result) {
constexpr std::array text{"",
"",
"Prey engulfed",
"No prey in contact",
"Engulf unsupported here",
"Engulf failed: no cell touching yours",
"Engulf failed: prey too large",
"Engulf failed: prey's membrane too thick"};
const auto index = static_cast<std::size_t>(result);
return index < text.size() ? text.at(index) : "";
}
const char* bud_text(network::CellularBudOutcome outcome) {
constexpr std::array text{"",
"",
"Bud created: a descendant split off",
"Bud failed: not fully grown",
"Bud failed: not enough resources",
"Bud failed: no space beside you"};
const auto index = static_cast<std::size_t>(outcome);
return index < text.size() ? text.at(index) : "";
}
void cell_record(const CellActionRecord& record) {
ImGui::TextColored(record.state == CellActionState::committed ? green : amber, "%s",
cell_action_name(record.kind));
ImGui::TextWrapped("%s", cell_action_state(record.state));
const char* effect = record.engulf ? engulf_text(*record.engulf)
: record.bud ? bud_text(*record.bud)
: "";
const bool succeeded =
record.state == CellActionState::committed &&
(!record.engulf || *record.engulf == network::CellularEngulfResult::engulfed) &&
(!record.bud || *record.bud == network::CellularBudOutcome::budded);
ImGui::TextColored(succeeded ? green : amber, "%s (tick %llu)", cell_action_name(record.kind),
static_cast<unsigned long long>(record.tick));
ImGui::TextWrapped("%s", *effect != '\0' ? effect : cell_action_state(record.state));
if (record.state == CellActionState::refused &&
record.refusal != network::AdmitStatus::admitted)
disabled_wrapped(std::string{cellular_admission_message(record.refusal)}.c_str());
@@ -1129,26 +1159,10 @@ void hud_dock(const PanelView& v, FormBuffers& form, PanelActions& a, bool compa
}
}
if (play) {
constexpr std::array engulf{"",
"",
"Prey engulfed",
"No prey in contact",
"Engulf unsupported here",
"Engulf failed: no cell touching yours",
"Engulf failed: prey too large",
"Engulf failed: prey's membrane too thick"};
constexpr std::array bud{"",
"",
"Bud created: a descendant split off",
"Bud failed: not fully grown",
"Bud failed: not enough resources",
"Bud failed: no space beside you"};
if (const auto& f = play->engulf_feedback();
f && !std::string_view{engulf.at(static_cast<std::size_t>(f->second))}.empty())
ImGui::TextWrapped("%s", engulf.at(static_cast<std::size_t>(f->second)));
if (const auto& f = play->bud_feedback();
f && !std::string_view{bud.at(static_cast<std::size_t>(f->second))}.empty())
ImGui::TextWrapped("%s", bud.at(static_cast<std::size_t>(f->second)));
if (const auto& f = play->engulf_feedback(); f && *engulf_text(f->second) != '\0')
ImGui::TextWrapped("%s", engulf_text(f->second));
if (const auto& f = play->bud_feedback(); f && *bud_text(f->second) != '\0')
ImGui::TextWrapped("%s", bud_text(f->second));
if (const auto& pending = play->pending(); pending) {
cell_record(*pending);
if (pending->state == CellActionState::unresolved) {
@@ -12,7 +12,7 @@ spec:
env:
- {name: REGION_SESSION, value: "dev"}
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261021T125059-4a2c275e:1792601459"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261021T145645-22cbb2ac:1792609005"}
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
ports:
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
@@ -4,6 +4,8 @@
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <vector>
// M11.5d (ADR-0125): the bounded deterministic wildlife controller. It reads only the
@@ -16,11 +18,22 @@ namespace evo::server {
inline constexpr std::uint64_t wildlife_bud_interval_ticks = 20; // 1 s
inline constexpr std::uint64_t wildlife_wander_interval_ticks = 40; // 2 s
inline constexpr std::int16_t wildlife_full_speed = 1'000;
// Rules 11 (trial value): a wildlife cell whose energy reserve covers fewer than this many
// ticks of its full demand seeks energy-bearing deposits only, so it never parks on a
// carbon or nutrient mote while it starves. Earlier rules keep nearest-any foraging.
inline constexpr std::uint64_t wildlife_energy_hunger_ticks = 1'200; // 60 s
// Full speed toward (dx, dy): the intent's length is at most wildlife_full_speed, as a
// cellular intent requires (a longer one is refused and fails the whole tick).
[[nodiscard]] biology::CellularIntent wildlife_toward(std::int64_t dx, std::int64_t dy) noexcept;
// The perceived food a forager centred at (x, y) heads for: the nearest non-empty deposit
// (or, before rules 8, the nearest energy patch). A hungry forager on deposits passes over
// energy-free ones while it perceives any energy; otherwise it takes the nearest anything.
[[nodiscard]] std::optional<biology::CellularPatchPerception>
wildlife_food(std::span<const biology::CellularPatchPerception> perceived, std::int64_t centre_x,
std::int64_t centre_y, bool deposits, bool hungry);
// One intention per wildlife life (zero account), sorted by life id: bud when the reserve
// funds one, else steer to and feed from the nearest perceived patch holding energy,
// else wander. Owned lives are left to their players. ADR-0175: under rules 11 with
+39 -20
View File
@@ -56,6 +56,37 @@ biology::CellularIntent wildlife_toward(std::int64_t dx, std::int64_t dy) noexce
return {static_cast<std::int16_t>(x), static_cast<std::int16_t>(y)};
}
std::optional<biology::CellularPatchPerception>
wildlife_food(std::span<const biology::CellularPatchPerception> perceived, std::int64_t centre_x,
std::int64_t centre_y, bool deposits, bool hungry) {
// 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 auto offset = deposits ? 0 : half_pitch;
// A hungry forager ignores energy-free deposits while it perceives any energy.
const bool energy_only =
deposits && hungry && std::ranges::any_of(perceived, [](const auto& patch) {
return patch.available.energy.value != 0;
});
std::optional<biology::CellularPatchPerception> chosen;
std::uint64_t nearest_distance{};
for (const auto& patch : perceived) {
if (deposits ? patch.available == accounting::Inventory{}
: patch.available.energy.value == 0)
continue;
if (energy_only && patch.available.energy.value == 0)
continue;
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 (!chosen || distance < nearest_distance) {
chosen = patch;
nearest_distance = distance;
}
}
return chosen;
}
std::expected<std::vector<CellularLifeIntent>, CellularLivesError>
wildlife_intents(const CellularLives& state, std::uint64_t tick) {
constexpr std::array<biology::CellularIntent, 8> wander{{{1'000, 0},
@@ -154,27 +185,15 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
return std::unexpected{perceived.error()};
const auto centre_x = static_cast<std::int64_t>(life.position.x_um) + extent / 2;
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 (deposits ? patch.available == accounting::Inventory{}
: patch.available.energy.value == 0)
continue;
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;
}
}
// Rules 11: a cell short of energy forages for energy (wildlife_food).
const auto demand_period = budget->rate_microseconds / 50'000;
const auto demand_per_tick = demand_period == 0 ? 0 : budget->demand.value / demand_period;
const bool hungry =
state.rules_version() >= cellular_lives_photosynthesis_rules && demand_per_tick != 0 &&
life.reserve.energy.value / demand_per_tick < wildlife_energy_hunger_ticks;
const auto chosen = wildlife_food(*perceived, centre_x, centre_y, deposits, hungry);
const auto nearest = chosen ? std::optional{chosen->address} : std::nullopt;
if (nearest && deposits && chosen) {
biology::CellularPatch disc{};
disc.address = chosen->address;
+25
View File
@@ -472,6 +472,30 @@ void cellular_play() {
exhausted.initialize(std::numeric_limits<std::uint64_t>::max());
CHECK(exhausted.allocate_id() == 0 && exhausted.allocate_id() == 0);
}
// Recent actions keep what the region did: the effect reported in the action's tick view
// is attached to that engulf, even after its committed outcome moved it to the history.
void cellular_action_effects() {
using namespace evo::client_app;
using namespace evo::network;
CellularPlay play;
play.initialize(50);
play.connected();
play.observe({200, 700, {}, CellularLifeDiagnostics{}});
CHECK(play.queue(CellAction::engulf, 203));
const auto id = required(play.pending()).id;
play.sent();
play.outcome({id, ActionResult::committed, 203, 1});
CHECK(!play.pending() && !play.history().back().engulf);
CellularLifeDiagnostics effect;
effect.has_tick_effects = true;
effect.engulf = CellularEngulfResult::membrane_too_thick;
play.observe({203, 700, {}, effect});
CHECK(play.history().back().engulf == CellularEngulfResult::membrane_too_thick);
// A later engulf result does not overwrite the reported one.
effect.engulf = CellularEngulfResult::engulfed;
play.observe({204, 700, {}, effect});
CHECK(play.history().back().engulf == CellularEngulfResult::membrane_too_thick);
}
void cellular_energy_and_birth_wait() {
using namespace evo::client_app;
using namespace evo::network;
@@ -551,6 +575,7 @@ int main() try {
outcome_log();
session_host();
cellular_play();
cellular_action_effects();
cellular_energy_and_birth_wait();
cellular_assistance();
cell_headings();
+26
View File
@@ -1,8 +1,10 @@
#include "evo/biology/founder.hpp"
#include "evo/biology/mutation.hpp"
#include "evo/server/lifecycle/cellular_light.hpp"
#include "evo/server/lifecycle/wildlife_controller.hpp"
#include <algorithm>
#include <array>
#include <iostream>
#include <stdexcept>
#include <string>
@@ -130,6 +132,29 @@ void offers() {
}
require(offered, "schema 5 never offered photosynthesis");
}
// Rules 11 foraging: a hungry cell passes a nearer carbon mote for energy, a fed cell takes
// the nearest food, and with no energy in view the hungry cell still takes the nearest.
void foraging() {
const auto mote = [](std::uint32_t x, bool energy) {
CellularPatchPerception p{};
p.address = {x, 0};
p.radius_um = cellular_mote_radius_um;
p.kind = CellularDepositKind::mote;
if (energy)
p.available.energy.value = 1'000;
else
p.available.matter[0].value = 1'000; // Carbon only.
return p;
};
const std::array view{mote(40, false), mote(400, true)};
const auto hungry = wildlife_food(view, 0, 0, true, true);
const auto fed = wildlife_food(view, 0, 0, true, false);
require(hungry && hungry->address.x_um == 400, "a hungry cell parked on carbon");
require(fed && fed->address.x_um == 40, "a fed cell skipped the nearest food");
const std::array carbon{mote(40, false)};
const auto only = wildlife_food(carbon, 0, 0, true, true);
require(only && only->address.x_um == 40, "a hungry cell ignored the only food in view");
}
} // namespace
int main() {
@@ -137,6 +162,7 @@ int main() {
founders();
costs();
offers();
foraging();
std::cout << "photosynthesis contracts passed\n";
return 0;
} catch (const std::exception& error) {