machines computation
This commit is contained in:
parent
65ab440074
commit
7d9f1bac10
47
calc2.py
47
calc2.py
@ -1,3 +1,5 @@
|
||||
import math
|
||||
import typing as tp
|
||||
from functools import lru_cache
|
||||
|
||||
import pdbp # noqa: F401
|
||||
@ -193,6 +195,13 @@ def add_recipe(targets: ResourceGroup, recipe: ResourceGroup, multiplier: float)
|
||||
}
|
||||
|
||||
|
||||
def sum_recipies(recipies: tp.Iterable[ResourceGroup]) -> ResourceGroup:
|
||||
result = {}
|
||||
for recipe in recipies:
|
||||
result = add_recipe(result, recipe, -1)
|
||||
return result
|
||||
|
||||
|
||||
def reduce_to_base_resources(group: ResourceGroup, base: set[str]) -> tuple[ResourceGroup, ResourceGroup]:
|
||||
group = group.copy()
|
||||
|
||||
@ -219,8 +228,10 @@ def reduce_to_base_resources(group: ResourceGroup, base: set[str]) -> tuple[Reso
|
||||
return reduced, intermediates
|
||||
|
||||
|
||||
def drop_machines(group: ResourceGroup) -> ResourceGroup:
|
||||
return {k: v for k, v in group.items() if not k.startswith(tuple(MACHINES))}
|
||||
def drop_machines(group: ResourceGroup) -> tuple[ResourceGroup, ResourceGroup]:
|
||||
group_wo_machines = {k: v for k, v in group.items() if not k.startswith(tuple(MACHINES))}
|
||||
group_machines = {k: v for k, v in group.items() if k.startswith(tuple(MACHINES))}
|
||||
return group_wo_machines, group_machines
|
||||
|
||||
|
||||
def print_resource_group(group: ResourceGroup) -> None:
|
||||
@ -266,7 +277,7 @@ for group in bus_groups:
|
||||
|
||||
bus_inputs = add_recipe(bus_inputs, reduced, -1)
|
||||
|
||||
bus_inputs = drop_machines(bus_inputs)
|
||||
bus_inputs, bus_machines = drop_machines(bus_inputs)
|
||||
print()
|
||||
print('main bus inputs')
|
||||
print_resource_group(bus_inputs)
|
||||
@ -289,7 +300,7 @@ print_resource_group(intermediates)
|
||||
print('reduced')
|
||||
print_resource_group(chemical_inputs)
|
||||
|
||||
chemical_inputs = drop_machines(chemical_inputs)
|
||||
chemical_inputs, chemical_machines = drop_machines(chemical_inputs)
|
||||
print()
|
||||
print('chemical processing inputs')
|
||||
print_resource_group(chemical_inputs)
|
||||
@ -329,7 +340,7 @@ print()
|
||||
print('oil processing')
|
||||
print_resource_group(oil_inputs)
|
||||
|
||||
oil_inputs = drop_machines(oil_inputs)
|
||||
oil_inputs, oil_machines = drop_machines(oil_inputs)
|
||||
|
||||
if pg := oil_inputs.pop('petroleum-gas', 0) > 0:
|
||||
raise RuntimeError(f'petrolium-gas > 0: {pg=}')
|
||||
@ -352,7 +363,7 @@ print('reduced')
|
||||
print_resource_group(smelting_inputs)
|
||||
|
||||
# mining
|
||||
mining_outputs = drop_machines(smelting_inputs)
|
||||
mining_outputs, smelting_machines = drop_machines(smelting_inputs)
|
||||
mining_base = {'mining-drill', 'pumpjack', 'offshore-pump', 'steam'}
|
||||
|
||||
mining_inputs, intermediates = reduce_to_base_resources(mining_outputs, mining_base)
|
||||
@ -362,3 +373,27 @@ print('mining intermediates')
|
||||
print_resource_group(intermediates)
|
||||
print('reduced')
|
||||
print_resource_group(mining_inputs)
|
||||
_, mining_machines = drop_machines(mining_inputs)
|
||||
|
||||
|
||||
def despecify_machines(group: ResourceGroup) -> ResourceGroup:
|
||||
# assembler[belt-y] -> assembler, etc.
|
||||
result = {}
|
||||
for resource, count in group.items():
|
||||
if '[' in resource:
|
||||
resource = resource[: resource.find('[')]
|
||||
count = math.ceil(count)
|
||||
result[resource] = result.get(resource, 0) + count
|
||||
return result
|
||||
|
||||
|
||||
# TODO: assembers work at 0.75 efficiency...
|
||||
|
||||
machines = sum_recipies([bus_machines, chemical_machines, oil_machines, smelting_machines, mining_machines])
|
||||
machines = despecify_machines(machines)
|
||||
print()
|
||||
print('machines (despecified)')
|
||||
print_resource_group(machines)
|
||||
|
||||
# TODO: total machine count
|
||||
# TODO: belt bandwidth
|
||||
|
Loading…
Reference in New Issue
Block a user