Refactor capacity enforcement and production logic
- Updated `enforce_capacity` function to accept an optional `physical` parameter, allowing for more flexible handling of physical amounts. - Modified `initialize_life_batches` to return physical amounts after enforcing capacity, improving data flow. - Enhanced `try_production` to utilize shared physical amounts, reducing redundant calculations. - Adjusted `stellar_environment` to accept an optional `quantities` parameter, streamlining its usage. - Added new test results for physical totals to validate performance improvements across various scenarios.
This commit is contained in:
@@ -14,7 +14,10 @@ func run():
|
||||
var profiles: Dictionary = {}
|
||||
for id in counts: profiles[id] = profile
|
||||
var physical: Dictionary = world.ledger.physical_amounts(world.state)
|
||||
world.civilization_flow._commit(world.state, physical, {"C0.2": {"counts": counts, "profiles": profiles}}, rules, 100)
|
||||
var initial_physical: Dictionary = physical.duplicate()
|
||||
var committed: Dictionary = world.civilization_flow._commit(world.state, physical, {"C0.2": {"counts": counts, "profiles": profiles}}, rules, 100)
|
||||
check(E.eq(committed, world.ledger.physical_amounts(world.state)), "Commit snapshot matches a full physical rebuild")
|
||||
check(E.eq(physical, initial_physical), "Commit does not mutate its input snapshot")
|
||||
for id in counts:
|
||||
check(E.eq(world.ledger.physical_amount(world.state, id), counts[id]), "Commit preserves exact destination quota: " + id)
|
||||
for owner in ["RD", "OD"]:
|
||||
@@ -33,6 +36,14 @@ func run():
|
||||
check(E.eq(world.state.binds.RD.get("Ct", 0), 0), "Transcendent population cannot retain a stellar owner")
|
||||
dispose(world)
|
||||
world = fixture()
|
||||
world.state.amount["C2.0"] = count
|
||||
var initial_capacity: Dictionary = world.ledger.physical_amounts(world.state)
|
||||
var frozen_capacity: Dictionary = initial_capacity.duplicate()
|
||||
var constrained: Dictionary = State.enforce_capacity(world, world.state, rules, 100, initial_capacity)
|
||||
check(E.eq(constrained, world.ledger.physical_amounts(world.state)), "Cascading capacity changes maintain exact physical totals")
|
||||
check(E.eq(initial_capacity, frozen_capacity), "Capacity correction does not mutate the previous snapshot")
|
||||
dispose(world)
|
||||
world = fixture()
|
||||
var original_owners: Dictionary = {}
|
||||
for owner in ["RD", "OD", "YD", "WYD"]:
|
||||
world.state.binds[owner] = {}
|
||||
@@ -43,7 +54,13 @@ func run():
|
||||
"C1.4": {"counts": {"C1.4": E.multiply(count, 3)}, "profiles": {"C1.4": profile}},
|
||||
"C1.5": {"counts": {"C1.5": E.multiply(count, 5)}, "profiles": {"C1.5": profile}}
|
||||
}
|
||||
world.civilization_flow._colonize(world.state, colonies, 100, rules)
|
||||
var physical_before: Dictionary = world.ledger.physical_amounts(world.state)
|
||||
var untouched: Dictionary = physical_before.duplicate()
|
||||
var colonized: Dictionary = world.civilization_flow._colonize(world.state, colonies, 100, rules, physical_before)
|
||||
check(E.eq(colonized, world.ledger.physical_amounts(world.state)), "Colonization snapshot matches a full physical rebuild")
|
||||
check(E.eq(physical_before, untouched), "Colonization does not mutate its input snapshot")
|
||||
var capacity: Dictionary = State.enforce_capacity(world, world.state, rules, 100, colonized)
|
||||
check(E.eq(capacity, world.ledger.physical_amounts(world.state)), "Capacity snapshot matches a full physical rebuild")
|
||||
check(E.eq(world.ledger.physical_amount(world.state, "C1.4"), E.multiply(count, 3)), "Colonization credits exact first quota")
|
||||
check(E.eq(world.ledger.physical_amount(world.state, "C1.5"), E.multiply(count, 5)), "Colonization credits exact second quota")
|
||||
check(E.eq(world.state.stats.total_amount["C1.4"], E.multiply(count, 3)), "Consolidated credit preserves creation statistics")
|
||||
|
||||
Reference in New Issue
Block a user