Update analyzer.py and commander.py
This commit is contained in:
parent
27bd054e8b
commit
5fbce54285
@ -44,14 +44,21 @@ class Analyzer:
|
|||||||
location = self.store.get(Waypoint, location)
|
location = self.store.get(Waypoint, location)
|
||||||
mkts = self.find_markets(resource, sellbuy)
|
mkts = self.find_markets(resource, sellbuy)
|
||||||
candidates = []
|
candidates = []
|
||||||
|
origin = self.store.get(System, location.system())
|
||||||
for typ, m in mkts:
|
for typ, m in mkts:
|
||||||
system = self.store.get(System, m.system())
|
system = self.store.get(System, m.system())
|
||||||
origin = self.store.get(System, location.system())
|
d = origin.distance(system)
|
||||||
|
candidates.append((typ, m, d))
|
||||||
|
possibles = sorted(candidates, key=lambda m: m[2])
|
||||||
|
possibles = possibles[:10]
|
||||||
|
results = []
|
||||||
|
for typ,m,d in possibles:
|
||||||
|
system = self.store.get(System, m.system())
|
||||||
p = self.find_path(origin, system)
|
p = self.find_path(origin, system)
|
||||||
if p is None: continue
|
if p is None: continue
|
||||||
candidates.append((typ, m, len(p)))
|
results.append((typ,m,d,len(p)))
|
||||||
result = sorted(candidates, key=lambda m: m[2])
|
return results
|
||||||
return result[:10]
|
|
||||||
|
|
||||||
|
|
||||||
def get_jumpgate(self, system):
|
def get_jumpgate(self, system):
|
||||||
|
@ -138,12 +138,13 @@ class Commander(CommandLine):
|
|||||||
raise CommandError('no delivery')
|
raise CommandError('no delivery')
|
||||||
resource = delivery['trade_symbol']
|
resource = delivery['trade_symbol']
|
||||||
destination = delivery['destination']
|
destination = delivery['destination']
|
||||||
m = self.analyzer.find_closest_market(resource, 'buy', destination)
|
m = self.analyzer.find_closest_markets(resource, 'buy', destination)
|
||||||
if m is None:
|
if len(m) is None:
|
||||||
m = self.analyzer.find_closest_market(resource, 'exchange', destination)
|
m = self.analyzer.find_closest_markets(resource, 'exchange', destination)
|
||||||
if m is None:
|
if len(m) is None:
|
||||||
print('no market found')
|
print('no market found')
|
||||||
return
|
return
|
||||||
|
_, m, _, _ = m[0]
|
||||||
site = self.store.get(Waypoint, m.symbol)
|
site = self.store.get(Waypoint, m.symbol)
|
||||||
self.set_mission('haul')
|
self.set_mission('haul')
|
||||||
self.centcom.set_mission_param(self.ship, 'site', site.symbol)
|
self.centcom.set_mission_param(self.ship, 'site', site.symbol)
|
||||||
@ -222,7 +223,7 @@ class Commander(CommandLine):
|
|||||||
location = self.ship.location()
|
location = self.ship.location()
|
||||||
resource = input('what resource?').upper()
|
resource = input('what resource?').upper()
|
||||||
print('Found markets:')
|
print('Found markets:')
|
||||||
for typ, m, plen in self.analyzer.find_closest_markets(resource, 'buy,exchange',location):
|
for typ, m, d, plen in self.analyzer.find_closest_markets(resource, 'buy,exchange',location):
|
||||||
print(m, typ[0], f'{plen-1} hops')
|
print(m, typ[0], f'{plen-1} hops')
|
||||||
|
|
||||||
def do_path(self):
|
def do_path(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user