Sometimes travel to other clients
This commit is contained in:
parent
3041f78531
commit
d3039918ea
11
reborn.py
11
reborn.py
|
@ -289,19 +289,23 @@ 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 route(roadmap)
|
||||
else:
|
||||
return roadmap
|
||||
|
||||
|
||||
|
@ -315,6 +319,7 @@ def think():
|
|||
'warehouse': warehouse,
|
||||
'deliverTime': 0,
|
||||
'loads': [],
|
||||
'clients': [],
|
||||
'stops': []
|
||||
})
|
||||
|
||||
|
|
Reference in a new issue