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:
@@ -59,11 +59,16 @@ func run() -> void:
|
||||
world.state.auto_resources = {"H": 10}
|
||||
world.state.batches.H = [{"amount": 10, "start_year": 1, "end_year": 2}]
|
||||
var before: Dictionary = world.state.duplicate(true)
|
||||
check((not world.production.try_production(world.state, world.catalog.entities.N, 1, true)), "Binding failure rejects production")
|
||||
var physical: Dictionary = world.ledger.physical_amounts(world.state)
|
||||
var frozen_physical: Dictionary = physical.duplicate()
|
||||
check((not world.production.try_production(world.state, world.catalog.entities.N, 1, true, physical)), "Binding failure rejects production")
|
||||
check(E.eq(physical, frozen_physical), "Failed production preserves the shared quantity snapshot")
|
||||
check(E.eq(world.state, before), "Failure preserves costs, batches and budget")
|
||||
world.state.amount.S = 10
|
||||
physical = world.ledger.physical_amounts(world.state)
|
||||
var old_batches: Array = world.state.batches.H
|
||||
check(world.production.try_production(world.state, world.catalog.entities.N, 2, true), "Funded production succeeds")
|
||||
check(world.production.try_production(world.state, world.catalog.entities.N, 2, true, physical), "Funded production succeeds")
|
||||
check(E.eq(physical, world.ledger.physical_amounts(world.state)), "Successful production updates exact totals without changing bound-resource totals")
|
||||
check((E.eq(world.state.amount.H, 6) and E.eq(world.state.amount.S, 4)), "Exact cost and binding")
|
||||
check(E.eq(world.state.auto_resources.H, 6), "Exact automatic budget")
|
||||
check((E.eq(old_batches[0].amount, 10) and E.eq(world.state.batches.H[0].amount, 6)), "Consumed batches isolated")
|
||||
|
||||
Reference in New Issue
Block a user