Skip to content

Commit a4190c3

Browse files
committed
extra debugging and fix recipes
1 parent 0813f0f commit a4190c3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

factorio_recipes

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Launch builds at 1
1010

1111
# Modules. Note the short names for easier typing on cli.
1212
speed 1 module affects speed .2
13-
speed 1 module affects speed .3
14-
speed 1 module affects speed .5
13+
speed 2 module affects speed .3
14+
speed 3 module affects speed .5
1515
prod 1 module affects speed -.15, prod .04
16-
prod 1 module affects speed -.15, prod .06
17-
prod 1 module affects speed -.15, prod .1
16+
prod 2 module affects speed -.15, prod .06
17+
prod 3 module affects speed -.15, prod .1
1818

1919
# Special 'items' that aren't really items
2020
# A rocket could be represented by 100 rocket parts, but that doesn't really capture

factoriocalc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import re
44
import sys
55
from collections import OrderedDict, Counter
6+
from pprint import pprint
67

78
# We use ceil() at the end of calculations, and don't want floating point error
89
# to make us slightly over an integer and cause us to add another for no reason.
910
from fractions import Fraction
1011

1112

12-
def get_recipes(datafile, module_priorities):
13+
def get_recipes(datafile, module_priorities, verbose=False):
1314
"""Data file consists of one entry per line. Each entry is either a recipe, building or module.
1415
Building lines look like:
1516
BUILDING builds at SPEED[ with N modules]
@@ -69,6 +70,8 @@ def get_recipes(datafile, module_priorities):
6970
input_amount, input_name = part.split(' ', 1)
7071
input_amount = int(input_amount)
7172
inputs[input_name] = input_amount
73+
if name in items:
74+
raise ValueError('Recipe for {!r} already declared'.format(name))
7275
items[name] = amount, time, building, inputs, prod
7376
continue
7477

@@ -78,6 +81,8 @@ def get_recipes(datafile, module_priorities):
7881
speed = Fraction(speed)
7982
prod = Fraction(prod) if prod else 0
8083
name = name.lower()
84+
if name in modules:
85+
raise ValueError('Module {!r} already declared'.format(name))
8186
modules[name] = speed, prod
8287
continue
8388

@@ -102,6 +107,9 @@ def get_recipes(datafile, module_priorities):
102107
inputs = {input_name: Fraction(input_amount) / amount for input_name, input_amount in inputs.items()}
103108
results[item] = building, throughput, inputs, mods
104109

110+
if verbose:
111+
pprint(results)
112+
105113
return results
106114

107115

@@ -155,7 +163,7 @@ def merge_into(a, b):
155163
a[k] = a.get(k, 0) + v
156164

157165

158-
def main(item, rate, datafile='factorio_recipes', modules='', fractional=False):
166+
def main(item, rate, datafile='factorio_recipes', modules='', fractional=False, verbose=False):
159167
"""Calculate ratios and output number of production facilities needed
160168
to craft a specific output at a specific rate in Factorio.
161169
Requires a data file specifying available recipies and buildings. See source for syntax.
@@ -173,7 +181,7 @@ def main(item, rate, datafile='factorio_recipes', modules='', fractional=False):
173181
- No dependency cycles (eg. coal liquification, Kovarex enrichment)
174182
"""
175183
modules = [name.strip().lower() for name in modules.split(',')] if modules else []
176-
recipes = get_recipes(datafile, modules)
184+
recipes = get_recipes(datafile, modules, verbose)
177185
rate = Fraction(rate)
178186
results = solve(recipes, item, rate)
179187
for item, amount in results.items():

0 commit comments

Comments
 (0)