• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Just a simple, and painful to use calculator for the game Factorio written in Python


Commit MetaInfo

Révisionfb2acd03a0a290adbe4199e47f2f446edd753d63 (tree)
l'heure2017-08-06 04:55:22
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Next iteration. Factory planning list, actual production estimate.

Change Summary

Modification

diff -r 8f46c1620439 -r fb2acd03a0a2 factorio_calc.py
--- a/factorio_calc.py Sat Aug 05 11:23:09 2017 -0700
+++ b/factorio_calc.py Sat Aug 05 12:55:22 2017 -0700
@@ -28,14 +28,23 @@
2828
2929 @property
3030 def base_rate(self):
31- base_rate = (self._produced / _F(1,1)) / (self._time / _F(1,1))
32- return base_rate
31+ if self._produced is None:
32+ return None
33+ else:
34+ base_rate = (self._produced / _F(1,1)) / (self._time / _F(1,1))
35+ return base_rate
3336
3437 def factories(self, rate):
35- return rate / self.base_rate
38+ if self._produced is None:
39+ return None
40+ else:
41+ return rate / self.base_rate
3642
3743 def rate_with_factories(self, numfactories):
38- return numfactories * self.base_rate
44+ if self._produced is None:
45+ return None
46+ else:
47+ return numfactories * self.base_rate
3948
4049 class ItemSet(set):
4150 def __init__(self, *args, **kargs):
@@ -77,7 +86,7 @@
7786 return 0
7887 produced = dest_item._produced / _F(1,1)
7988 scale = rate / produced
80- print(f"name, scale == {dest_item._name}, {scale}")
89+# print(f"name, scale == {dest_item._name}, {scale}")
8190 total = 0
8291 for sub_item_ct, sub_item in dest_item._ingredients:
8392 sub_rate = production_rate(sub_item, scale * sub_item_ct, source_item)
@@ -87,3 +96,36 @@
8796 def how_many_produced(source_item, rate, dest_item):
8897 forward_rate = production_rate(dest_item, _F(1,1), source_item)
8998 return rate / forward_rate
99+
100+def factories_for_each(dest_item, rate):
101+ items_so_far = set()
102+ factory_list = []
103+ def recursive_count(dest_item, rate, cur_source=None):
104+ if cur_source is None:
105+ cur_source = dest_item
106+ if cur_source in items_so_far:
107+ return
108+ items_so_far.add(cur_source)
109+ source_rate = production_rate(dest_item, rate, cur_source)
110+ if cur_source._produced is None:
111+ factory_list.append((None, None, source_rate, cur_source))
112+ else:
113+ factories = cur_source.factories(source_rate)
114+ int_fact = factories // _F(1,1)
115+ if (factories - int_fact) > 0:
116+ int_fact += 1
117+ assert(int_fact >= factories)
118+ factory_list.append((int_fact, factories, source_rate, cur_source))
119+ for _, next_source in cur_source._ingredients:
120+ recursive_count(dest_item, rate, next_source)
121+ recursive_count(dest_item, rate)
122+ return factory_list
123+
124+def actual_production(dest_item, factory_list):
125+ def produced_for_each(dest_item, factory_list):
126+ for int_fact, _, _, item in factory_list:
127+ if int_fact is not None:
128+ rate = (_F(int_fact, 1) * item._produced) / item._time
129+ cur_produced = how_many_produced(item, rate, dest_item)
130+ yield cur_produced
131+ return min(produced_for_each(dest_item, factory_list))
diff -r 8f46c1620439 -r fb2acd03a0a2 item-db.pickle
Binary file item-db.pickle has changed