From 5fbce542850c7225381bd0ea1993c85f30077c02 Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Fri, 23 Jun 2023 13:49:09 +0200 Subject: [PATCH] Update analyzer.py and commander.py --- nullptr/analyzer.py | 15 +++++++++++---- nullptr/commander.py | 11 ++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/nullptr/analyzer.py b/nullptr/analyzer.py index ca9ffdf..bcc9bba 100644 --- a/nullptr/analyzer.py +++ b/nullptr/analyzer.py @@ -44,14 +44,21 @@ class Analyzer: location = self.store.get(Waypoint, location) mkts = self.find_markets(resource, sellbuy) candidates = [] + origin = self.store.get(System, location.system()) for typ, m in mkts: 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) if p is None: continue - candidates.append((typ, m, len(p))) - result = sorted(candidates, key=lambda m: m[2]) - return result[:10] + results.append((typ,m,d,len(p))) + return results + def get_jumpgate(self, system): diff --git a/nullptr/commander.py b/nullptr/commander.py index b4584a4..af20623 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -138,12 +138,13 @@ class Commander(CommandLine): raise CommandError('no delivery') resource = delivery['trade_symbol'] destination = delivery['destination'] - m = self.analyzer.find_closest_market(resource, 'buy', destination) - if m is None: - m = self.analyzer.find_closest_market(resource, 'exchange', destination) - if m is None: + m = self.analyzer.find_closest_markets(resource, 'buy', destination) + if len(m) is None: + m = self.analyzer.find_closest_markets(resource, 'exchange', destination) + if len(m) is None: print('no market found') return + _, m, _, _ = m[0] site = self.store.get(Waypoint, m.symbol) self.set_mission('haul') self.centcom.set_mission_param(self.ship, 'site', site.symbol) @@ -222,7 +223,7 @@ class Commander(CommandLine): location = self.ship.location() resource = input('what resource?').upper() 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') def do_path(self):