Эх сурвалжийг харах

supply: fix a bunch of calculation bugs

raylu 3 долоо хоног өмнө
parent
commit
d47450eb15
1 өөрчлөгдсөн 6 нэмэгдсэн , 3 устгасан
  1. 6 3
      supply.py

+ 6 - 3
supply.py

@@ -40,9 +40,10 @@ def main() -> None:
 		print(planet.name, f'consumes {vol_per_day:.1f}㎥, {weight_per_day:.1f}t per day')
 
 	load_more = True
-	optimal: dict[str, dict[str, int]] = dict.fromkeys(p.name for p in planets) # pyright: ignore[reportAssignmentType]
+	optimal: dict[str, dict[str, int]] = None # pyright: ignore[reportAssignmentType]
 	target_days = round(target_days + 0.05, 1)
 	while load_more:
+		buys: dict[str, dict[str, int]] = {}
 		total_weight_used = total_volume_used = 0
 		for planet in planets:
 			buy, weight_used, volume_used = planet.buy_for_target(materials, target_days)
@@ -51,8 +52,10 @@ def main() -> None:
 			if total_weight_used > args.weight or total_volume_used > args.volume:
 				load_more = False
 				break
-			optimal[planet.name] = buy
-			target_days += 0.1
+			buys[planet.name] = buy
+		if load_more:
+			optimal = buys
+		target_days += 0.1
 	print('supply for', round(target_days, 1), 'days')
 
 	for planet in planets: