real resource counts

This commit is contained in:
Michael Peters 2024-03-18 20:25:16 -07:00
parent 7d9f1bac10
commit 77d475f6a9

View File

@ -172,6 +172,10 @@ MACHINES = {
'offshore-pump', 'offshore-pump',
} }
MACHINES_REAL = {
'assembler': ('_assembler-2', 0.75),
}
def get_resource_name(orig_name: str, recipe_name: str) -> str: def get_resource_name(orig_name: str, recipe_name: str) -> str:
if orig_name in MACHINES: if orig_name in MACHINES:
@ -234,20 +238,37 @@ def drop_machines(group: ResourceGroup) -> tuple[ResourceGroup, ResourceGroup]:
return group_wo_machines, group_machines return group_wo_machines, group_machines
def get_real_resource_counts(group: ResourceGroup) -> list[tuple[str, float]]:
def get_real_rc(rc: tuple[str, float]) -> tuple[str, float]:
resource, count = rc
for resource_from, (resource_real, ratio) in MACHINES_REAL.items():
if resource.startswith(resource_from):
resource = resource.replace(resource_from, resource_real)
count = count / ratio
break
return resource, count
rcs = list(map(get_real_rc, group.items()))
return rcs
def print_resource_group(group: ResourceGroup) -> None: def print_resource_group(group: ResourceGroup) -> None:
for resource, count in sorted(group.items()): rcs = get_real_resource_counts(group)
print(f' {resource:40}: {dot_align(tuple(group.values()), count)}') cs = tuple(map(lambda rc: rc[1], rcs))
for resource, count in sorted(rcs):
print(f' {resource:40}: {dot_align(cs, count)}')
SPM = 1 # science-per-second
SPS = 1
bus_groups: list[ResourceGroup] = [ bus_groups: list[ResourceGroup] = [
{'science-red': SPM}, {'science-red': SPS},
{'science-green': SPM}, {'science-green': SPS},
{'science-gray': SPM}, {'science-gray': SPS},
{'science-blue': SPM}, {'science-blue': SPS},
{'science-purple': SPM}, {'science-purple': SPS},
{'science-yellow': SPM}, {'science-yellow': SPS},
{'science-white': SPM}, {'science-white': SPS},
] ]
bus_base = { bus_base = {
'iron-plate', 'iron-plate',
@ -263,7 +284,7 @@ bus_base = {
'rocket-fuel', 'rocket-fuel',
} }
print(f'{SPM=}') print(f'{SPS=}')
print(f'{bus_base=}') print(f'{bus_base=}')
bus_inputs = {} bus_inputs = {}
for group in bus_groups: for group in bus_groups:
@ -344,6 +365,9 @@ oil_inputs, oil_machines = drop_machines(oil_inputs)
if pg := oil_inputs.pop('petroleum-gas', 0) > 0: if pg := oil_inputs.pop('petroleum-gas', 0) > 0:
raise RuntimeError(f'petrolium-gas > 0: {pg=}') raise RuntimeError(f'petrolium-gas > 0: {pg=}')
# ignore heavy/light oil overflow
oil_inputs.pop('light-oil', 0)
oil_inputs.pop('heavy-oil', 0)
smelting_outputs = add_recipe(bus_inputs, oil_inputs, -1) smelting_outputs = add_recipe(bus_inputs, oil_inputs, -1)
smelting_outputs = add_recipe(smelting_outputs, chemical_inputs, -1) smelting_outputs = add_recipe(smelting_outputs, chemical_inputs, -1)
@ -352,7 +376,7 @@ print('smelting outputs')
print_resource_group(smelting_outputs) print_resource_group(smelting_outputs)
# smelting # smelting
smelting_base = {'furnace', 'iron-ore', 'copper-ore', 'coal', 'stone', 'steam', 'water', 'crude-oil'} smelting_base = {'furnace', 'iron-ore', 'copper-ore', 'coal', 'stone', 'steam', 'water', 'crude-oil', 'light-oil'}
# combine to compute mining requirements # combine to compute mining requirements
smelting_inputs, intermediates = reduce_to_base_resources(smelting_outputs, smelting_base) smelting_inputs, intermediates = reduce_to_base_resources(smelting_outputs, smelting_base)
@ -379,7 +403,7 @@ _, mining_machines = drop_machines(mining_inputs)
def despecify_machines(group: ResourceGroup) -> ResourceGroup: def despecify_machines(group: ResourceGroup) -> ResourceGroup:
# assembler[belt-y] -> assembler, etc. # assembler[belt-y] -> assembler, etc.
result = {} result = {}
for resource, count in group.items(): for resource, count in get_real_resource_counts(group):
if '[' in resource: if '[' in resource:
resource = resource[: resource.find('[')] resource = resource[: resource.find('[')]
count = math.ceil(count) count = math.ceil(count)