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>
This commit is contained in:
dingo
2026-10-21 11:03:23 -04:00
co-authored by Claude Opus 5.5
parent 3498da4130
commit bed069e91c
3 changed files with 78 additions and 20 deletions
+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) {