diff --git a/reborn.py b/reborn.py index b70d8c1..fb6936e 100755 --- a/reborn.py +++ b/reborn.py @@ -292,12 +292,13 @@ def think(): # Create a pack to deliver pack = client.pack() # Plan the delivery - # TODO Optimise for same product wanted more than once - for i in pack: - drone.addTask('load', warehouse, Product.get(i), 1) + packOccurences = dict((i, pack.count(i)) for i in pack) + # From http://stackoverflow.com/a/7843090/2766106 + for i in packOccurences: + drone.addTask('load', warehouse, Product.get(i), packOccurences[i]) warehouse.plan(pack) - for i in pack: - drone.addTask('deliver', client, Product.get(i), 1) + for i in packOccurences: + drone.addTask('deliver', client, Product.get(i), packOccurences[i]) client.plan(pack) else: global done