M11.1: environmental rules 3 with per-second rates (ADR-0099, segment 3)
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m58s
Foundation / checks (client) (push) Successful in 12m20s
Foundation / checks (network) (push) Successful in 13m53s
Foundation / checks (tsan) (push) Successful in 8m9s
Foundation / checks (checks) (push) Successful in 33m4s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 21m43s
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m58s
Foundation / checks (client) (push) Successful in 12m20s
Foundation / checks (network) (push) Successful in 13m53s
Foundation / checks (tsan) (push) Successful in 8m9s
Foundation / checks (checks) (push) Successful in 33m4s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 21m43s
Rules 3 is rules 2 with irradiance, growth, intake and decay per second. The community derives its per-tick form once at creation and restore (rationals exact via the tick in numerator and denominator, caps rounded down); steps and the snapshot layout are rules 2's; the codec reads formats 1-3. At 50 ms a x20 per-second twin steps identically through feeding, death and decay and across a snapshot; at 25 ms caps halve. Rules 1/2 and the development-v1 opening are unchanged. Development version 1 outputs stay tied to their 50 ms quantum and the tick-abstract M2 fixtures are not migrated (recorded). environmental-qualification's "unknown rules" case moves from 3 to 4. Refresh the dev session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,7 +117,7 @@ std::expected<world::WorldBytes, CommunityError> EnvironmentalCommunity::snapsho
|
||||
auto resource = resources_->snapshot();
|
||||
if (!resource)
|
||||
return std::unexpected{CommunityError::resources};
|
||||
const bool extended = config_.rules == 2;
|
||||
const bool extended = config_.rules >= 2; // Rules 3 has rules 2's layout.
|
||||
const auto length = (extended ? 712 : 616) + count_ * (extended ? 304 : 200) + resource->size();
|
||||
if (length > max_snapshot_bytes)
|
||||
return std::unexpected{CommunityError::budget};
|
||||
@@ -150,8 +150,8 @@ EnvironmentalCommunity::restore(std::span<const std::uint8_t> bytes, world::Worl
|
||||
if (r.get() != magic)
|
||||
return std::unexpected{CommunityError::format};
|
||||
const auto version = r.get();
|
||||
const bool extended = version == 2;
|
||||
if (version != 1 && version != 2)
|
||||
const bool extended = version >= 2;
|
||||
if (version < 1 || version > 3)
|
||||
return std::unexpected{CommunityError::version};
|
||||
if (r.get() != bytes.size())
|
||||
return std::unexpected{CommunityError::format};
|
||||
@@ -189,8 +189,11 @@ EnvironmentalCommunity::restore(std::span<const std::uint8_t> bytes, world::Worl
|
||||
o->budget_ = budget;
|
||||
o->count_ = static_cast<std::size_t>(count);
|
||||
o->next_ = o->count_ % history_limit;
|
||||
if (!configuration(o->config_, *o->resources_) ||
|
||||
o->resources_->adoption_command_ != o->progress_.tick ||
|
||||
const auto step = configuration(o->config_, *o->resources_);
|
||||
if (!step)
|
||||
return std::unexpected{CommunityError::format};
|
||||
o->step_ = *step;
|
||||
if (o->resources_->adoption_command_ != o->progress_.tick ||
|
||||
o->resources_->fields().last_command() != o->progress_.tick ||
|
||||
std::ranges::any_of(o->resources_->history_,
|
||||
[](const auto& h) { return h.receipt.command != 0; }) ||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "evo/processes/environmental_community.hpp"
|
||||
#include "evo/accounting/rates.hpp"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
namespace evo::processes {
|
||||
@@ -16,12 +17,46 @@ std::uint64_t portion(std::uint64_t x, std::uint64_t a) {
|
||||
bool EnvironmentalCommunity::rebind_world(std::uint64_t world) noexcept {
|
||||
if (world == 0)
|
||||
return false;
|
||||
config_.world = world;
|
||||
config_.world = step_.world = world;
|
||||
resources_->rebind({world, config_.frame});
|
||||
return true;
|
||||
}
|
||||
bool EnvironmentalCommunity::configuration(const EnvironmentalConfig& c,
|
||||
const world::EnvironmentalTransfers& r) noexcept {
|
||||
std::optional<EnvironmentalConfig>
|
||||
EnvironmentalCommunity::configuration(const EnvironmentalConfig& given,
|
||||
const world::EnvironmentalTransfers& r) noexcept {
|
||||
if (given.rules < 1 || given.rules > 3)
|
||||
return std::nullopt;
|
||||
// Rules 3 runs as rules 2 with its per-second rates converted at the tick (ADR-0099):
|
||||
// the rationals exactly (the tick folds into numerator and denominator), the caps
|
||||
// rounded down.
|
||||
auto c = given;
|
||||
if (given.rules == 3) {
|
||||
const auto tick = given.tick_microseconds;
|
||||
constexpr auto second = accounting::microseconds_per_second;
|
||||
if (tick == 0 || tick > accounting::max_tick_microseconds ||
|
||||
given.irradiance_numerator > maximum / tick ||
|
||||
given.irradiance_denominator > maximum / second ||
|
||||
given.growth_numerator > maximum / tick || given.growth_denominator > maximum / second)
|
||||
return std::nullopt;
|
||||
c.rules = 2;
|
||||
c.irradiance_numerator = given.irradiance_numerator * tick;
|
||||
c.irradiance_denominator = given.irradiance_denominator * second;
|
||||
c.growth_numerator = given.growth_numerator * tick;
|
||||
c.growth_denominator = given.growth_denominator * second;
|
||||
for (std::size_t j = 0; j < c.intake.size(); ++j) {
|
||||
const auto cap =
|
||||
accounting::per_tick(given.intake[j], tick, accounting::Rounding::down);
|
||||
if (!cap)
|
||||
return std::nullopt;
|
||||
c.intake[j] = *cap;
|
||||
}
|
||||
for (std::size_t k = 0; k < c.decay.size(); ++k) {
|
||||
const auto cap = accounting::per_tick(given.decay[k], tick, accounting::Rounding::down);
|
||||
if (!cap)
|
||||
return std::nullopt;
|
||||
c.decay[k] = *cap;
|
||||
}
|
||||
}
|
||||
if ((c.rules != 1 && c.rules != 2) ||
|
||||
(c.rules == 1 && std::ranges::any_of(c.decay, [](auto v) { return v != 0; })) ||
|
||||
c.world == 0 || c.frame == 0 ||
|
||||
@@ -30,21 +65,21 @@ bool EnvironmentalCommunity::configuration(const EnvironmentalConfig& c,
|
||||
c.growth_denominator == 0 || c.efficiency > 1000 || c.assimilation > 1000 ||
|
||||
c.growth_cost == 0 || c.producer_min_mK == 0 || c.consumer_min_mK == 0 ||
|
||||
c.producer_min_mK > c.producer_max_mK || c.consumer_min_mK > c.consumer_max_mK)
|
||||
return false;
|
||||
return std::nullopt;
|
||||
if (r.fields().sites().size() != 1 || r.terrain().size() != 1 || r.organisms().size() != 2 ||
|
||||
r.organisms()[0].id.value != c.producer || r.organisms()[1].id.value != c.consumer)
|
||||
return false;
|
||||
return std::nullopt;
|
||||
const auto measure = world::measure_habitat(r.fields().sites()[0].box);
|
||||
if (!measure || c.area_um2 > measure->area.value ||
|
||||
c.irradiance_numerator > maximum / c.area_um2)
|
||||
return false;
|
||||
return std::nullopt;
|
||||
for (std::size_t k = 0; k < 10; ++k)
|
||||
if (!r.fields().read(0, static_cast<world::Field>(k)))
|
||||
return false;
|
||||
return std::nullopt;
|
||||
for (std::size_t k = 0; k < 4; ++k)
|
||||
if (c.recipe[k] == 0)
|
||||
return false;
|
||||
return true;
|
||||
return std::nullopt;
|
||||
return c;
|
||||
}
|
||||
EnvironmentalCommunity::State EnvironmentalCommunity::state() const noexcept {
|
||||
State s;
|
||||
@@ -58,8 +93,8 @@ EnvironmentalCommunity::State EnvironmentalCommunity::state() const noexcept {
|
||||
bool EnvironmentalCommunity::valid(const State& s) const noexcept {
|
||||
const auto& p = s.progress;
|
||||
if ((p.last_funded == 0 && (p.source_remainder != 0 || p.efficiency_remainder != 0)) ||
|
||||
p.source_remainder >= config_.irradiance_denominator ||
|
||||
p.growth_remainder >= config_.growth_denominator || p.efficiency_remainder >= 1000 ||
|
||||
p.source_remainder >= step_.irradiance_denominator ||
|
||||
p.growth_remainder >= step_.growth_denominator || p.efficiency_remainder >= 1000 ||
|
||||
p.last_funded > p.tick || p.producer_terminal > 1 || p.consumer_terminal > 1 ||
|
||||
(config_.rules == 1 && p.consumer_terminal != 0) ||
|
||||
(p.tick == 0 && p != EnvironmentalProgress{}))
|
||||
@@ -88,13 +123,15 @@ std::expected<std::unique_ptr<EnvironmentalCommunity>, CommunityError>
|
||||
EnvironmentalCommunity::create(EnvironmentalConfig c,
|
||||
std::unique_ptr<world::EnvironmentalTransfers> r,
|
||||
std::size_t budget) {
|
||||
if (!r || !configuration(c, *r) || r->fields().last_command() != 0 || r->adoption_command_ != 0)
|
||||
const auto step = r ? configuration(c, *r) : std::nullopt;
|
||||
if (!step || r->fields().last_command() != 0 || r->adoption_command_ != 0)
|
||||
return std::unexpected{CommunityError::config};
|
||||
if (budget < sizeof(EnvironmentalCommunity) + 2 * scratch_bytes ||
|
||||
r->accounted_bytes() > budget - sizeof(EnvironmentalCommunity) - 2 * scratch_bytes)
|
||||
return std::unexpected{CommunityError::budget};
|
||||
auto o = std::unique_ptr<EnvironmentalCommunity>(new EnvironmentalCommunity);
|
||||
o->config_ = c;
|
||||
o->step_ = *step;
|
||||
o->resources_ = std::move(r);
|
||||
o->budget_ = budget;
|
||||
o->anchor_ = o->state();
|
||||
@@ -106,7 +143,7 @@ EnvironmentalCommunity::step(State& s, std::uint64_t tick,
|
||||
if (input.temperature_mK == 0 || input.source_enabled > 1)
|
||||
return std::unexpected{CommunityError::input};
|
||||
auto& p = s.progress;
|
||||
const auto& c = config_;
|
||||
const auto& c = step_;
|
||||
EnvironmentalReport report{};
|
||||
report.tick = tick;
|
||||
if (input.terminal[0] > 1 || input.terminal[1] > 1 ||
|
||||
|
||||
Reference in New Issue
Block a user