From d3039918eaf1cf39903556b2316cb61541029b82 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 13 Feb 2016 17:16:33 +0100 Subject: [PATCH] Sometimes travel to other clients --- reborn.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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': [] })