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:
@@ -12,7 +12,7 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- {name: REGION_SESSION, value: "dev"}
|
- {name: REGION_SESSION, value: "dev"}
|
||||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
||||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261009T171039-559d:1791579639"}
|
- {name: REGION_SESSION_WINDOW, value: "dev-20261009T184926-c2b9:1791585566"}
|
||||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||||
ports:
|
ports:
|
||||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||||
|
|||||||
+7
-2
@@ -24,8 +24,13 @@ the maintainer chose directional rounding):
|
|||||||
read ×20 and never rewritten. Development version 1 converts at its own 50 ms
|
read ×20 and never rewritten. Development version 1 converts at its own 50 ms
|
||||||
quantum, mutation keeps a lineage's schema, and an archive of schema 1 records keeps
|
quantum, mutation keeps a lineage's schema, and an archive of schema 1 records keeps
|
||||||
its bytes. No behaviour or golden changed.
|
its bytes. No behaviour or golden changed.
|
||||||
- **Segment 3 (next):** development outputs, feeding and decay limits per second,
|
- **Segment 3 (done):** environmental community rules 3 states irradiance, growth,
|
||||||
converted at each process's tick.
|
intake and decay per second. At 50 ms it steps identically to its rules 2 twin. The
|
||||||
|
dev world's rules 2 opening is unchanged. Development version 1 outputs stay tied to
|
||||||
|
their declared 50 ms quantum. The tick-abstract M2 fixtures are not migrated. ADR-0089's
|
||||||
|
rate migration is complete.
|
||||||
|
- **Next in 11.1:** development version 2, a first bud fundable within a session
|
||||||
|
(ADR-0098 decision 7).
|
||||||
|
|
||||||
Open from M10 (BACKLOG):
|
Open from M10 (BACKLOG):
|
||||||
- the maintainer's native-client observation, moved to the later 2k drill;
|
- the maintainer's native-client observation, moved to the later 2k drill;
|
||||||
|
|||||||
@@ -98,6 +98,31 @@ contract and a versioned migration that preserves 50 ms behaviour.
|
|||||||
- **Tests that used 2 as an unknown future schema** now use the next unknown one. The
|
- **Tests that used 2 as an unknown future schema** now use the next unknown one. The
|
||||||
archive decoder refuses a header that misstates its contents.
|
archive decoder refuses a header that misstates its contents.
|
||||||
|
|
||||||
|
## Segment 3 as implemented (2026-10-09)
|
||||||
|
- **Environmental community rules 3** is rules 2 with every rate per second:
|
||||||
|
irradiance and growth as rationals per second, and intake and decay caps per
|
||||||
|
second.
|
||||||
|
- At creation and restore, the community derives its per-tick form once. The
|
||||||
|
rationals convert exactly, because the tick folds into numerator and denominator.
|
||||||
|
The caps round down.
|
||||||
|
- Steps run on that form unchanged, the snapshot keeps rules 2's layout, and the
|
||||||
|
codec reads rules 1 to 3.
|
||||||
|
- At 50 ms, a ×20 per-second twin of a rules 2 configuration steps identically
|
||||||
|
through feeding, death and decay, and across a snapshot. At 25 ms the caps halve.
|
||||||
|
- Rules 1 and 2, including the dev world's fixed `development-v1` opening, are
|
||||||
|
unchanged.
|
||||||
|
- **Development version 1 outputs** (maintenance, movement, intake limit) stay per
|
||||||
|
tick of its 50 ms quantum, which is how that version is defined.
|
||||||
|
- A live process at another tick reads them through `per_second_from_per_tick` and
|
||||||
|
`per_tick`.
|
||||||
|
- Development version 2 (the birth-cost re-derivation, ADR-0098) is defined per
|
||||||
|
second natively.
|
||||||
|
- **The M2 ecosystem fixtures** (consumer and producer configurations, the feeding
|
||||||
|
decomposition limit) are tick-abstract test oracles with no time base, and are not
|
||||||
|
migrated. New gameplay processes (11.3) use per-second rates from the start.
|
||||||
|
- **Result:** every rate that a live world can run on is now either per second
|
||||||
|
(genome schema 2, rules 3) or tied to a declared quantum it converts from.
|
||||||
|
|
||||||
## Consequences
|
## Consequences
|
||||||
- Segment 1: `accounting/rates.hpp` (`per_tick`, `exact_per_tick`,
|
- Segment 1: `accounting/rates.hpp` (`per_tick`, `exact_per_tick`,
|
||||||
`per_second_from_per_tick`) and the `rate-contracts` test.
|
`per_second_from_per_tick`) and the `rate-contracts` test.
|
||||||
|
|||||||
@@ -5399,3 +5399,27 @@ Executed:
|
|||||||
- The 18 Postgres suites passed, including region upgrade and clone comparison, so
|
- The 18 Postgres suites passed, including region upgrade and clone comparison, so
|
||||||
checkpoints are unchanged.
|
checkpoints are unchanged.
|
||||||
- Windows `debug`: 61/61.
|
- Windows `debug`: 61/61.
|
||||||
|
|
||||||
|
## 2026-10-09 — M11.1 time-based rates, segment 3: environmental rules 3 (ADR-0099)
|
||||||
|
|
||||||
|
Environmental community rules 3 has rules 2's layout with irradiance, growth, intake
|
||||||
|
and decay per second. It derives a per-tick form at creation and restore: exact
|
||||||
|
rationals, caps rounded down. Its format is 3 (`schemas/environmental-community.md`).
|
||||||
|
Development version 1 outputs stay tied to their 50 ms quantum, and the
|
||||||
|
tick-abstract M2 fixtures are not migrated. Both are recorded in ADR-0099.
|
||||||
|
|
||||||
|
`rules3_per_second` tests:
|
||||||
|
- a ×20 twin of a rules 2 configuration over 60 ticks, through feeding, a consumer
|
||||||
|
death and decay, with reports and every inventory equal each tick;
|
||||||
|
- snapshot and restore as format 3, then identical steps;
|
||||||
|
- at 25 ms, a 2000-per-second intake cap admits 50 and refuses 51;
|
||||||
|
- an overflowing rate and an over-long tick are refused.
|
||||||
|
|
||||||
|
`environmental-qualification` used rules 3 as "unknown". It now uses 4, with the same
|
||||||
|
intent.
|
||||||
|
|
||||||
|
Executed:
|
||||||
|
- WSL `linux-debug` and `linux-asan`: 61/61 after that change.
|
||||||
|
- clang-tidy 19 on the changed sources and tests: clean.
|
||||||
|
- The 18 Postgres suites: passed.
|
||||||
|
- Windows `debug`: 61/61.
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "evo/world/transfers.hpp"
|
#include "evo/world/transfers.hpp"
|
||||||
|
#include <optional>
|
||||||
namespace evo::processes {
|
namespace evo::processes {
|
||||||
// Explicit fixture parameters; units and array order in environmental-community.md.
|
// Explicit fixture parameters; units and array order in environmental-community.md.
|
||||||
|
// Rules 1 and 2 state rates per tick of `tick_microseconds`. Rules 3 (ADR-0099) is rules
|
||||||
|
// 2 with every rate per second: irradiance and growth as rationals per second (converted
|
||||||
|
// exactly), and intake and decay caps per second (rounded down at the tick).
|
||||||
struct EnvironmentalConfig {
|
struct EnvironmentalConfig {
|
||||||
std::uint64_t rules{1}, world{}, frame{}, producer{}, consumer{}, source{}, tick_microseconds{},
|
std::uint64_t rules{1}, world{}, frame{}, producer{}, consumer{}, source{}, tick_microseconds{},
|
||||||
area_um2{}, irradiance_numerator{}, irradiance_denominator{1}, efficiency{},
|
area_um2{}, irradiance_numerator{}, irradiance_denominator{1}, efficiency{},
|
||||||
@@ -9,7 +13,8 @@ struct EnvironmentalConfig {
|
|||||||
std::array<std::uint64_t, 5> recipe{}, intake{};
|
std::array<std::uint64_t, 5> recipe{}, intake{};
|
||||||
std::uint64_t assimilation{}, producer_min_mK{}, producer_max_mK{}, consumer_min_mK{},
|
std::uint64_t assimilation{}, producer_min_mK{}, producer_max_mK{}, consumer_min_mK{},
|
||||||
consumer_max_mK{};
|
consumer_max_mK{};
|
||||||
std::array<std::uint64_t, 10> decay{}; // Rules 2: shared source-channel caps per tick.
|
std::array<std::uint64_t, 10> decay{}; // Rules 2+: shared source-channel caps per tick
|
||||||
|
// (rules 3: per second).
|
||||||
auto operator<=>(const EnvironmentalConfig&) const = default;
|
auto operator<=>(const EnvironmentalConfig&) const = default;
|
||||||
};
|
};
|
||||||
struct EnvironmentalInput {
|
struct EnvironmentalInput {
|
||||||
@@ -89,11 +94,14 @@ class EnvironmentalCommunity {
|
|||||||
EnvironmentalCommunity() = default;
|
EnvironmentalCommunity() = default;
|
||||||
[[nodiscard]] State state() const noexcept;
|
[[nodiscard]] State state() const noexcept;
|
||||||
[[nodiscard]] bool valid(const State& s) const noexcept;
|
[[nodiscard]] bool valid(const State& s) const noexcept;
|
||||||
[[nodiscard]] static bool configuration(const EnvironmentalConfig& c,
|
// Validates a configuration and returns its per-tick form (itself for rules 1 and 2;
|
||||||
const world::EnvironmentalTransfers& r) noexcept;
|
// rules 3's rates converted at its tick), or nothing when invalid.
|
||||||
|
[[nodiscard]] static std::optional<EnvironmentalConfig>
|
||||||
|
configuration(const EnvironmentalConfig& c, const world::EnvironmentalTransfers& r) noexcept;
|
||||||
[[nodiscard]] std::expected<EnvironmentalReport, CommunityError>
|
[[nodiscard]] std::expected<EnvironmentalReport, CommunityError>
|
||||||
step(State& candidate, std::uint64_t tick, const EnvironmentalInput& input) const noexcept;
|
step(State& candidate, std::uint64_t tick, const EnvironmentalInput& input) const noexcept;
|
||||||
EnvironmentalConfig config_{};
|
EnvironmentalConfig config_{}; // As configured and persisted.
|
||||||
|
EnvironmentalConfig step_{}; // Its per-tick form, which every step uses.
|
||||||
std::unique_ptr<world::EnvironmentalTransfers> resources_;
|
std::unique_ptr<world::EnvironmentalTransfers> resources_;
|
||||||
EnvironmentalProgress progress_{};
|
EnvironmentalProgress progress_{};
|
||||||
State anchor_{};
|
State anchor_{};
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
# Environmental community envelope v1 (M6.5c)
|
# Environmental community envelope v1 (M6.5c)
|
||||||
|
|
||||||
|
## Version 3: rates per second (M11.1, ADR-0099)
|
||||||
|
|
||||||
|
Format 3 requires rules 3 and has format 2's layout byte for byte. Only the units of
|
||||||
|
five rates change:
|
||||||
|
- **irradiance:** `irradiance_numerator / irradiance_denominator`, in pJ per um^2 per
|
||||||
|
second;
|
||||||
|
- **growth:** `growth_numerator / growth_denominator`, in units per second;
|
||||||
|
- **intake[5] and decay[10]:** whole fg or pJ per second.
|
||||||
|
|
||||||
|
At creation and restore, the community derives a per-tick rules 2 form at
|
||||||
|
`tick_microseconds` (1 us to 1 s).
|
||||||
|
- The rationals become `numerator * tick / (denominator * 10^6)`, which is exact.
|
||||||
|
Their remainders are stored at that scale.
|
||||||
|
- The caps round down, never exceeding the per-second rate.
|
||||||
|
- A rate that overflows at the tick is a configuration error.
|
||||||
|
|
||||||
|
Formats 1 and 2 are unchanged and replay their own rules.
|
||||||
|
|
||||||
## Version 2 extension (M6.6, ADR-0056)
|
## Version 2 extension (M6.6, ADR-0056)
|
||||||
|
|
||||||
Format 2 requires rules 2; format 1 requires rules 1. The v1 layout below is
|
Format 2 requires rules 2; format 1 requires rules 1. The v1 layout below is
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ std::expected<world::WorldBytes, CommunityError> EnvironmentalCommunity::snapsho
|
|||||||
auto resource = resources_->snapshot();
|
auto resource = resources_->snapshot();
|
||||||
if (!resource)
|
if (!resource)
|
||||||
return std::unexpected{CommunityError::resources};
|
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();
|
const auto length = (extended ? 712 : 616) + count_ * (extended ? 304 : 200) + resource->size();
|
||||||
if (length > max_snapshot_bytes)
|
if (length > max_snapshot_bytes)
|
||||||
return std::unexpected{CommunityError::budget};
|
return std::unexpected{CommunityError::budget};
|
||||||
@@ -150,8 +150,8 @@ EnvironmentalCommunity::restore(std::span<const std::uint8_t> bytes, world::Worl
|
|||||||
if (r.get() != magic)
|
if (r.get() != magic)
|
||||||
return std::unexpected{CommunityError::format};
|
return std::unexpected{CommunityError::format};
|
||||||
const auto version = r.get();
|
const auto version = r.get();
|
||||||
const bool extended = version == 2;
|
const bool extended = version >= 2;
|
||||||
if (version != 1 && version != 2)
|
if (version < 1 || version > 3)
|
||||||
return std::unexpected{CommunityError::version};
|
return std::unexpected{CommunityError::version};
|
||||||
if (r.get() != bytes.size())
|
if (r.get() != bytes.size())
|
||||||
return std::unexpected{CommunityError::format};
|
return std::unexpected{CommunityError::format};
|
||||||
@@ -189,8 +189,11 @@ EnvironmentalCommunity::restore(std::span<const std::uint8_t> bytes, world::Worl
|
|||||||
o->budget_ = budget;
|
o->budget_ = budget;
|
||||||
o->count_ = static_cast<std::size_t>(count);
|
o->count_ = static_cast<std::size_t>(count);
|
||||||
o->next_ = o->count_ % history_limit;
|
o->next_ = o->count_ % history_limit;
|
||||||
if (!configuration(o->config_, *o->resources_) ||
|
const auto step = configuration(o->config_, *o->resources_);
|
||||||
o->resources_->adoption_command_ != o->progress_.tick ||
|
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 ||
|
o->resources_->fields().last_command() != o->progress_.tick ||
|
||||||
std::ranges::any_of(o->resources_->history_,
|
std::ranges::any_of(o->resources_->history_,
|
||||||
[](const auto& h) { return h.receipt.command != 0; }) ||
|
[](const auto& h) { return h.receipt.command != 0; }) ||
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "evo/processes/environmental_community.hpp"
|
#include "evo/processes/environmental_community.hpp"
|
||||||
|
#include "evo/accounting/rates.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
namespace evo::processes {
|
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 {
|
bool EnvironmentalCommunity::rebind_world(std::uint64_t world) noexcept {
|
||||||
if (world == 0)
|
if (world == 0)
|
||||||
return false;
|
return false;
|
||||||
config_.world = world;
|
config_.world = step_.world = world;
|
||||||
resources_->rebind({world, config_.frame});
|
resources_->rebind({world, config_.frame});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool EnvironmentalCommunity::configuration(const EnvironmentalConfig& c,
|
std::optional<EnvironmentalConfig>
|
||||||
const world::EnvironmentalTransfers& r) noexcept {
|
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) ||
|
if ((c.rules != 1 && c.rules != 2) ||
|
||||||
(c.rules == 1 && std::ranges::any_of(c.decay, [](auto v) { return v != 0; })) ||
|
(c.rules == 1 && std::ranges::any_of(c.decay, [](auto v) { return v != 0; })) ||
|
||||||
c.world == 0 || c.frame == 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_denominator == 0 || c.efficiency > 1000 || c.assimilation > 1000 ||
|
||||||
c.growth_cost == 0 || c.producer_min_mK == 0 || c.consumer_min_mK == 0 ||
|
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)
|
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 ||
|
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)
|
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);
|
const auto measure = world::measure_habitat(r.fields().sites()[0].box);
|
||||||
if (!measure || c.area_um2 > measure->area.value ||
|
if (!measure || c.area_um2 > measure->area.value ||
|
||||||
c.irradiance_numerator > maximum / c.area_um2)
|
c.irradiance_numerator > maximum / c.area_um2)
|
||||||
return false;
|
return std::nullopt;
|
||||||
for (std::size_t k = 0; k < 10; ++k)
|
for (std::size_t k = 0; k < 10; ++k)
|
||||||
if (!r.fields().read(0, static_cast<world::Field>(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)
|
for (std::size_t k = 0; k < 4; ++k)
|
||||||
if (c.recipe[k] == 0)
|
if (c.recipe[k] == 0)
|
||||||
return false;
|
return std::nullopt;
|
||||||
return true;
|
return c;
|
||||||
}
|
}
|
||||||
EnvironmentalCommunity::State EnvironmentalCommunity::state() const noexcept {
|
EnvironmentalCommunity::State EnvironmentalCommunity::state() const noexcept {
|
||||||
State s;
|
State s;
|
||||||
@@ -58,8 +93,8 @@ EnvironmentalCommunity::State EnvironmentalCommunity::state() const noexcept {
|
|||||||
bool EnvironmentalCommunity::valid(const State& s) const noexcept {
|
bool EnvironmentalCommunity::valid(const State& s) const noexcept {
|
||||||
const auto& p = s.progress;
|
const auto& p = s.progress;
|
||||||
if ((p.last_funded == 0 && (p.source_remainder != 0 || p.efficiency_remainder != 0)) ||
|
if ((p.last_funded == 0 && (p.source_remainder != 0 || p.efficiency_remainder != 0)) ||
|
||||||
p.source_remainder >= config_.irradiance_denominator ||
|
p.source_remainder >= step_.irradiance_denominator ||
|
||||||
p.growth_remainder >= config_.growth_denominator || p.efficiency_remainder >= 1000 ||
|
p.growth_remainder >= step_.growth_denominator || p.efficiency_remainder >= 1000 ||
|
||||||
p.last_funded > p.tick || p.producer_terminal > 1 || p.consumer_terminal > 1 ||
|
p.last_funded > p.tick || p.producer_terminal > 1 || p.consumer_terminal > 1 ||
|
||||||
(config_.rules == 1 && p.consumer_terminal != 0) ||
|
(config_.rules == 1 && p.consumer_terminal != 0) ||
|
||||||
(p.tick == 0 && p != EnvironmentalProgress{}))
|
(p.tick == 0 && p != EnvironmentalProgress{}))
|
||||||
@@ -88,13 +123,15 @@ std::expected<std::unique_ptr<EnvironmentalCommunity>, CommunityError>
|
|||||||
EnvironmentalCommunity::create(EnvironmentalConfig c,
|
EnvironmentalCommunity::create(EnvironmentalConfig c,
|
||||||
std::unique_ptr<world::EnvironmentalTransfers> r,
|
std::unique_ptr<world::EnvironmentalTransfers> r,
|
||||||
std::size_t budget) {
|
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};
|
return std::unexpected{CommunityError::config};
|
||||||
if (budget < sizeof(EnvironmentalCommunity) + 2 * scratch_bytes ||
|
if (budget < sizeof(EnvironmentalCommunity) + 2 * scratch_bytes ||
|
||||||
r->accounted_bytes() > budget - sizeof(EnvironmentalCommunity) - 2 * scratch_bytes)
|
r->accounted_bytes() > budget - sizeof(EnvironmentalCommunity) - 2 * scratch_bytes)
|
||||||
return std::unexpected{CommunityError::budget};
|
return std::unexpected{CommunityError::budget};
|
||||||
auto o = std::unique_ptr<EnvironmentalCommunity>(new EnvironmentalCommunity);
|
auto o = std::unique_ptr<EnvironmentalCommunity>(new EnvironmentalCommunity);
|
||||||
o->config_ = c;
|
o->config_ = c;
|
||||||
|
o->step_ = *step;
|
||||||
o->resources_ = std::move(r);
|
o->resources_ = std::move(r);
|
||||||
o->budget_ = budget;
|
o->budget_ = budget;
|
||||||
o->anchor_ = o->state();
|
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)
|
if (input.temperature_mK == 0 || input.source_enabled > 1)
|
||||||
return std::unexpected{CommunityError::input};
|
return std::unexpected{CommunityError::input};
|
||||||
auto& p = s.progress;
|
auto& p = s.progress;
|
||||||
const auto& c = config_;
|
const auto& c = step_;
|
||||||
EnvironmentalReport report{};
|
EnvironmentalReport report{};
|
||||||
report.tick = tick;
|
report.tick = tick;
|
||||||
if (input.terminal[0] > 1 || input.terminal[1] > 1 ||
|
if (input.terminal[0] > 1 || input.terminal[1] > 1 ||
|
||||||
|
|||||||
@@ -523,6 +523,83 @@ void interval_boundaries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
// Rules 3 (ADR-0099): rules 2 with every rate per second. At 50 ms a per-second twin of a
|
||||||
|
// rules 2 configuration (rates times 20) steps identically, through feeding, a death and
|
||||||
|
// its decay, and across a snapshot; at another tick the caps scale and round down.
|
||||||
|
void rules3_per_second() {
|
||||||
|
auto two = config();
|
||||||
|
two.rules = 2;
|
||||||
|
two.growth_numerator = 3;
|
||||||
|
two.growth_denominator = 2;
|
||||||
|
two.decay.fill(2);
|
||||||
|
auto three = two;
|
||||||
|
three.rules = 3;
|
||||||
|
three.irradiance_numerator *= 20;
|
||||||
|
three.growth_numerator *= 20;
|
||||||
|
for (auto& v : three.intake)
|
||||||
|
v *= 20;
|
||||||
|
for (auto& v : three.decay)
|
||||||
|
v *= 20;
|
||||||
|
const std::array<std::uint64_t, 10> stock{5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
|
||||||
|
auto made_a = EnvironmentalCommunity::create(
|
||||||
|
two, resources({100, 100, 100, 100, 0, 0, 100, 0, 10, 0}, stock, stock), 8000000);
|
||||||
|
auto made_b = EnvironmentalCommunity::create(
|
||||||
|
three, resources({100, 100, 100, 100, 0, 0, 100, 0, 10, 0}, stock, stock), 8000000);
|
||||||
|
CHECK(made_a && made_b);
|
||||||
|
auto a = std::move(*made_a);
|
||||||
|
auto b = std::move(*made_b);
|
||||||
|
const auto same = [&] {
|
||||||
|
for (std::size_t k = 0; k < 10; ++k)
|
||||||
|
if (*a->resources().fields().read(0, static_cast<Field>(k)) !=
|
||||||
|
*b->resources().fields().read(0, static_cast<Field>(k)))
|
||||||
|
return false;
|
||||||
|
return a->resources().organisms()[0].balances == b->resources().organisms()[0].balances &&
|
||||||
|
a->resources().organisms()[1].balances == b->resources().organisms()[1].balances;
|
||||||
|
};
|
||||||
|
const auto input = [](std::uint64_t tick) {
|
||||||
|
EnvironmentalInput in{290000, tick % 7 == 0 ? 0U : 1U, {}, {}};
|
||||||
|
if (tick == 6)
|
||||||
|
in.bite = {1, 1, 1, 1, 1};
|
||||||
|
if (tick == 20)
|
||||||
|
in.terminal = {0, 1};
|
||||||
|
return in;
|
||||||
|
};
|
||||||
|
for (std::uint64_t tick = 1; tick <= 40; ++tick) {
|
||||||
|
const auto ra = a->advance(tick, input(tick));
|
||||||
|
const auto rb = b->advance(tick, input(tick));
|
||||||
|
CHECK(ra.has_value() == rb.has_value());
|
||||||
|
if (ra)
|
||||||
|
CHECK(*ra == *rb);
|
||||||
|
CHECK(same());
|
||||||
|
}
|
||||||
|
// Rules 3 persists as rules 3 and replays from its snapshot.
|
||||||
|
const auto saved = b->snapshot();
|
||||||
|
CHECK(saved && (*saved)[8] == 3);
|
||||||
|
auto restored = EnvironmentalCommunity::restore(*saved, identity, 8000000);
|
||||||
|
CHECK(restored && (*restored)->snapshot() == saved);
|
||||||
|
b = std::move(*restored);
|
||||||
|
for (std::uint64_t tick = 41; tick <= 60; ++tick) {
|
||||||
|
const auto ra = a->advance(tick, input(tick));
|
||||||
|
const auto rb = b->advance(tick, input(tick));
|
||||||
|
CHECK(ra && rb && *ra == *rb && same());
|
||||||
|
}
|
||||||
|
// At 25 ms a cap of 2000 per second is 50 per tick: 51 is over it, 50 is within it.
|
||||||
|
auto fast = three;
|
||||||
|
fast.tick_microseconds = 25000;
|
||||||
|
auto quick = make(fast);
|
||||||
|
const auto over = quick->advance(1, {290000, 0, {51, 0, 0, 0, 0}, {}});
|
||||||
|
CHECK(!over && over.error() == CommunityError::input);
|
||||||
|
const auto within = quick->advance(1, {290000, 0, {50, 0, 0, 0, 0}, {}});
|
||||||
|
CHECK(!within && within.error() == CommunityError::insufficient); // Past the cap check.
|
||||||
|
// A rate that cannot be converted at the tick is a configuration error.
|
||||||
|
auto huge = three;
|
||||||
|
huge.irradiance_numerator = std::numeric_limits<std::uint64_t>::max();
|
||||||
|
CHECK(!EnvironmentalCommunity::create(huge, resources(), 8000000));
|
||||||
|
auto slow = three;
|
||||||
|
slow.tick_microseconds = 1'000'001;
|
||||||
|
CHECK(!EnvironmentalCommunity::create(slow, resources(), 8000000));
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
vectors();
|
vectors();
|
||||||
@@ -533,6 +610,7 @@ int main() {
|
|||||||
decay_continuation();
|
decay_continuation();
|
||||||
scheduled_intervals();
|
scheduled_intervals();
|
||||||
interval_boundaries();
|
interval_boundaries();
|
||||||
|
rules3_per_second();
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::fprintf(stderr, "%s\n", e.what());
|
std::fprintf(stderr, "%s\n", e.what());
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ void refusals() {
|
|||||||
auto c = config();
|
auto c = config();
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case 0:
|
case 0:
|
||||||
c.rules = 3; // Rules 2 are the M6.6 terminal/decay extension.
|
c.rules = 4; // Unknown: 2 is the M6.6 terminal/decay extension, 3 per second.
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
c.world = 8;
|
c.world = 8;
|
||||||
|
|||||||
Reference in New Issue
Block a user