Foundation / checks (checks) (push) Successful in 47m40s
Foundation / checks (client) (push) Successful in 17m27s
Foundation / checks (deploy) (push) Successful in 4m17s
Foundation / checks (ecs) (push) Successful in 4m31s
Foundation / checks (network) (push) Successful in 22m1s
Foundation / checks (tsan) (push) Successful in 13m10s
Foundation / checks (postgres) (push) Successful in 20m54s
Foundation / image (push) Successful in 4m15s
Foundation / postgres-tools (push) Successful in 5m32s
Foundation / server-image (push) Successful in 7m15s
Square patches invited camping and left the space between them empty. Rules 8 run on a format-2 habitat of deposits: - pools and single-nutrient bubbles at free micrometre centres, each with a stable id and a contact radius; the cellular-v7 opening scatters bubbles reproducibly from the genesis commit (three in ten in loose clumps) and lists pools with --pool; - every cell drains what it touches, up to its intake rate per tick, with no target; a pool gives at most a quarter of that rate; an emptied deposit disappears; - a dead cell's detritus breaks into one bubble per non-empty channel; - wildlife swims to the nearest non-empty deposit and feeds by touch. Bundle v9 (habitat 2) and schema v43 admit it. Session v11 carries the owner's 512 nearest deposits (id, centre, radius, shape, a drained flag and 16-bit amount codes) instead of patches; every other cellular message is v10's. The client asks for v11, draws bubbles (nutrient-coloured, pulsing while drained, popping when gone) and pools as puddles, slows near food and sends no feed target; the HUD summarises food in range. Earlier rules, regions and v10 clients are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
5.6 KiB
C++
109 lines
5.6 KiB
C++
#pragma once
|
|
#include "evo/client/input.hpp"
|
|
#include "evo/client/organism_view.hpp"
|
|
#include "evo/network/session_protocol.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <optional>
|
|
#include <utility>
|
|
|
|
namespace evo::client_app {
|
|
struct CellularControls {
|
|
bool auto_feed{true}, slow_near_food{true}, precision{};
|
|
int speed_percent{100};
|
|
};
|
|
struct CellularSteering {
|
|
client::Intention intention;
|
|
std::optional<std::pair<std::uint32_t, std::uint32_t>> patch;
|
|
};
|
|
// Assistance uses only the owner's copied view. It never predicts or moves a body.
|
|
// The cellular bridge currently encodes the footprint's lower-left position in x/y
|
|
// (ADR-0102), unlike the centre offsets used by the general organism fixture.
|
|
[[nodiscard]] inline CellularSteering
|
|
steer_cellular(const CellularControls& controls, client::Intention intention,
|
|
const network::CellularPerception* perception,
|
|
const client::OrganismPresentation* organisms,
|
|
std::optional<std::pair<std::uint32_t, std::uint32_t>> manual) {
|
|
CellularSteering result{intention, controls.auto_feed ? std::nullopt : manual};
|
|
double scale = static_cast<double>(std::clamp(controls.speed_percent, 1, 100)) / 100;
|
|
if (controls.precision)
|
|
scale *= 0.2;
|
|
if (perception && organisms && perception->life_identity != 0) {
|
|
const auto cells = organisms->cells();
|
|
const auto own =
|
|
std::ranges::find(cells, perception->life_identity, &client::OrganismCell::id);
|
|
if (own != cells.end()) {
|
|
const double x =
|
|
static_cast<double>(own->voxel.x) * 1'000'000 + static_cast<double>(own->x.value);
|
|
const double y =
|
|
static_cast<double>(own->voxel.y) * 1'000'000 + static_cast<double>(own->y.value);
|
|
const double extent = static_cast<double>(own->phenotype.extent);
|
|
bool target_has_energy = false;
|
|
// ADR-0136 (v11): deposits feed on contact, so no target; slow near any that
|
|
// holds something (within 1 mm of its disc).
|
|
for (const auto& d : perception->deposits) {
|
|
if (std::ranges::all_of(d.amount_codes, [](auto code) { return code == 0; }))
|
|
continue;
|
|
const double cx = static_cast<double>(d.x_um), cy = static_cast<double>(d.y_um);
|
|
const double gx = std::max({x - cx, cx - x - extent, 0.0});
|
|
const double gy = std::max({y - cy, cy - y - extent, 0.0});
|
|
if (controls.slow_near_food &&
|
|
std::hypot(gx, gy) <= 1000.0 + static_cast<double>(d.radius_um) &&
|
|
own->phenotype.movement_speed > 0)
|
|
scale =
|
|
std::min(scale, 500.0 / static_cast<double>(own->phenotype.movement_speed));
|
|
}
|
|
for (const auto& p : perception->patches) {
|
|
if (p.energy_pj == 0 &&
|
|
std::ranges::all_of(p.matter_fg, [](auto v) { return v == 0; }))
|
|
continue;
|
|
const double dx =
|
|
std::max({static_cast<double>(p.x_um) - x - extent, x - p.x_um - 1000, 0.0});
|
|
const double dy =
|
|
std::max({static_cast<double>(p.y_um) - y - extent, y - p.y_um - 1000, 0.0});
|
|
if (controls.auto_feed && dx == 0 && dy == 0 &&
|
|
(!result.patch || (!target_has_energy && p.energy_pj != 0))) {
|
|
result.patch = {p.x_um, p.y_um};
|
|
target_has_energy = p.energy_pj != 0;
|
|
}
|
|
// Presentation preference: approach food at at most 500 um/s (25 um/tick).
|
|
// Recomputed from the current phenotype after every mutation. Authority
|
|
// still determines displacement, contact, funding and intake.
|
|
if (controls.slow_near_food && dx <= 1000 && dy <= 1000 &&
|
|
own->phenotype.movement_speed > 0)
|
|
scale =
|
|
std::min(scale, 500.0 / static_cast<double>(own->phenotype.movement_speed));
|
|
}
|
|
}
|
|
}
|
|
const auto component = [scale](std::int16_t value) {
|
|
const auto scaled = static_cast<std::int16_t>(value * scale);
|
|
// The protocol has finite precision; never turn held movement into a stop.
|
|
return scaled == 0 && value != 0 ? static_cast<std::int16_t>(value > 0 ? 1 : -1) : scaled;
|
|
};
|
|
result.intention.move_x = component(intention.move_x);
|
|
result.intention.move_y = component(intention.move_y);
|
|
return result;
|
|
}
|
|
// ADR-0129 amendment: what one bud needs that the reserve lacks, per channel: energy
|
|
// first, then C, N, P and other matter. Nothing set when it can be paid; a genome that
|
|
// cannot bud reports a zero cost, which this treats as affordable (the button is the guide).
|
|
[[nodiscard]] inline std::array<bool, 5> bud_shortfall(const network::CellularLifeDiagnostics& d) {
|
|
std::array<bool, 5> short_on{};
|
|
short_on[0] = d.bud_cost_energy_pj > d.reserve_energy_pj;
|
|
for (std::size_t i = 0; i < d.bud_cost_matter_fg.size(); ++i)
|
|
short_on[i + 1] = d.bud_cost_matter_fg[i] > d.reserve_matter_fg[i];
|
|
return short_on;
|
|
}
|
|
[[nodiscard]] inline bool can_fund(const network::CellularOfferedCandidate& candidate,
|
|
const network::CellularLifeDiagnostics& reserve) {
|
|
if (candidate.cost_energy_pj > reserve.reserve_energy_pj)
|
|
return false;
|
|
for (std::size_t i = 0; i < candidate.cost_matter_fg.size(); ++i)
|
|
if (candidate.cost_matter_fg[i] > reserve.reserve_matter_fg[i])
|
|
return false;
|
|
return true;
|
|
}
|
|
} // namespace evo::client_app
|