Refactor civilization flow mechanics: enhance commit and colonization logic, add tests for flow application and resource allocation, and optimize performance metrics.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
extends "res://tests/test_civilization_evolution.gd"
|
||||
|
||||
func run():
|
||||
var rules: Dictionary = root.get_node("Global").CivilizationRules
|
||||
for count in [103, E.of("10000000000000000000000000000000000000103"), E.add(E.of("1e400"), 103)]:
|
||||
var world = fixture()
|
||||
var third: Variant = E.floor_value(E.divide(count, 3))
|
||||
var free: Variant = E.subtract(count, E.multiply(third, 2))
|
||||
world.state.amount["C0.2"] = free
|
||||
world.state.binds.RD = {"C0.2": third}
|
||||
world.state.binds.OD = {"C0.2": third}
|
||||
var counts: Dictionary = {"C0.2": third, "C0.3": third, "HP": free}
|
||||
var profile: Dictionary = {"m": 0.4, "l": 0.2, "w": 0.1, "d": 0.1, "c": 0.1, "b": 0.1}
|
||||
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)
|
||||
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"]:
|
||||
var held: Variant = 0
|
||||
for id in counts: held = E.add(held, world.state.binds[owner].get(id, 0))
|
||||
check(E.eq(held, third), "Commit preserves each owner's exact population")
|
||||
for id in ["C0.2", "C0.3"]:
|
||||
for ethic in profile: check(absf(world.state.ethics[id][ethic] - profile[ethic]) < 1e-12, "Commit preserves incoming ethical profile")
|
||||
invariants(world)
|
||||
dispose(world)
|
||||
world = fixture()
|
||||
world.state.binds.RD = {"C4.4": count}
|
||||
var terminal: Dictionary = {"Ct": State.empty_profile()}
|
||||
world.civilization_flow._commit(world.state, world.ledger.physical_amounts(world.state), {"C4.4": {"counts": {"Ct": count}, "profiles": terminal}}, rules, 100)
|
||||
check(E.eq(world.state.amount.Ct, count), "Transcendent population is entirely free")
|
||||
check(E.eq(world.state.binds.RD.get("Ct", 0), 0), "Transcendent population cannot retain a stellar owner")
|
||||
dispose(world)
|
||||
world = fixture()
|
||||
var original_owners: Dictionary = {}
|
||||
for owner in ["RD", "OD", "YD", "WYD"]:
|
||||
world.state.binds[owner] = {}
|
||||
for resource in ["GG", "AB", "RP", "HP"]:
|
||||
world.state.binds[owner][resource] = count
|
||||
original_owners[owner] = E.multiply(count, 4)
|
||||
var colonies: Dictionary = {
|
||||
"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)
|
||||
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")
|
||||
check(E.eq(world.state.civilization_stats.colonies, E.multiply(count, 8)), "Colonization statistics equal exact granted total")
|
||||
for owner in original_owners:
|
||||
var held: Variant = 0
|
||||
for id in ["GG", "AB", "RP", "HP", "C1.4", "C1.5"]: held = E.add(held, world.state.binds[owner].get(id, 0))
|
||||
check(E.eq(held, original_owners[owner]), "Colonization preserves each owner's occupied worlds")
|
||||
var remaining_planets: Variant = 0
|
||||
for id in ["GG", "AB", "RP", "HP"]: remaining_planets = E.add(remaining_planets, world.ledger.physical_amount(world.state, id))
|
||||
check(E.eq(remaining_planets, E.multiply(count, 8)), "Planet loss equals colonies created")
|
||||
invariants(world)
|
||||
dispose(world)
|
||||
print("Flow commit: %d checks, %d failures" % [checks, failures])
|
||||
quit(1 if failures else 0)
|
||||
Reference in New Issue
Block a user