Sometimes travel to other clients

This commit is contained in:
Geoffrey Frogeye 2016-02-13 17:16:33 +01:00
parent 3041f78531
commit d3039918ea

View file

@ -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': []
})