diff --git a/reborn.py b/reborn.py index 02ca540..3a75517 100755 --- a/reborn.py +++ b/reborn.py @@ -289,20 +289,24 @@ def newTurn(): # Algorithm that only works for 1 warehouse def route(roadmap): # Find the nearest client that still has things to be delivered - remainingClients = [c for c in Client.near(roadmap['pos']) if c.plannedNeeds] + remainingClients = [c for c in Client.near(roadmap['pos']) if c.plannedNeeds and c not in roadmap['clients']] if remainingClients: client = remainingClients[0] # Create a pack to deliver - pack = client.pack() - # TODO if pack ... else ... + pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads'])) + if not pack: + return roadmap # Plan the delivery roadmap['warehouse'].plan(pack) client.plan(pack) roadmap['deliverTime'] += distance(roadmap['pos'], client.pos) + len(list(set(pack))) roadmap['pos'] = client.pos roadmap['loads'] += pack + roadmap['clients'].append(client) roadmap['stops'].append((client, pack)) - return roadmap + return route(roadmap) + else: + return roadmap def think(): @@ -315,6 +319,7 @@ def think(): 'warehouse': warehouse, 'deliverTime': 0, 'loads': [], + 'clients': [], 'stops': [] })