Sometimes travel to other clients
This commit is contained in:
parent
3041f78531
commit
d3039918ea
13
reborn.py
13
reborn.py
|
@ -289,20 +289,24 @@ def newTurn():
|
||||||
# Algorithm that only works for 1 warehouse
|
# Algorithm that only works for 1 warehouse
|
||||||
def route(roadmap):
|
def route(roadmap):
|
||||||
# Find the nearest client that still has things to be delivered
|
# 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:
|
if remainingClients:
|
||||||
client = remainingClients[0]
|
client = remainingClients[0]
|
||||||
# Create a pack to deliver
|
# Create a pack to deliver
|
||||||
pack = client.pack()
|
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
|
||||||
# TODO if pack ... else ...
|
if not pack:
|
||||||
|
return roadmap
|
||||||
# Plan the delivery
|
# Plan the delivery
|
||||||
roadmap['warehouse'].plan(pack)
|
roadmap['warehouse'].plan(pack)
|
||||||
client.plan(pack)
|
client.plan(pack)
|
||||||
roadmap['deliverTime'] += distance(roadmap['pos'], client.pos) + len(list(set(pack)))
|
roadmap['deliverTime'] += distance(roadmap['pos'], client.pos) + len(list(set(pack)))
|
||||||
roadmap['pos'] = client.pos
|
roadmap['pos'] = client.pos
|
||||||
roadmap['loads'] += pack
|
roadmap['loads'] += pack
|
||||||
|
roadmap['clients'].append(client)
|
||||||
roadmap['stops'].append((client, pack))
|
roadmap['stops'].append((client, pack))
|
||||||
return roadmap
|
return route(roadmap)
|
||||||
|
else:
|
||||||
|
return roadmap
|
||||||
|
|
||||||
|
|
||||||
def think():
|
def think():
|
||||||
|
@ -315,6 +319,7 @@ def think():
|
||||||
'warehouse': warehouse,
|
'warehouse': warehouse,
|
||||||
'deliverTime': 0,
|
'deliverTime': 0,
|
||||||
'loads': [],
|
'loads': [],
|
||||||
|
'clients': [],
|
||||||
'stops': []
|
'stops': []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Reference in a new issue