Update analyzer.py and commander.py

This commit is contained in:
Richard Bronkhorst 2023-06-14 16:55:45 +02:00
parent 0c1ec40090
commit f079403535
2 changed files with 8 additions and 5 deletions

View File

@ -27,7 +27,7 @@ class Analyzer:
def __init__(self, store):
self.store = store
def find_markets(self, resource, sellbuy, location):
def find_markets(self, resource, sellbuy):
for m in self.store.all(Marketplace):
resources = m.imports if sellbuy == 'sell' else m.exports
if resource in resources:

View File

@ -77,12 +77,15 @@ class Commander(CommandLine):
pprint(r)
def do_query(self):
location = None # self.ask_obj(Waypoint, 'Where are you? ')
location = self.ask_obj(System, 'Where are you? ')
resource = input('what resource?').upper()
sellbuy = self.ask_multichoice(['sell','buy'], 'do you want to sell or buy?')
print('Found markets:')
for m in self.analyzer.find_markets(resource, sellbuy, location):
print(m)
for m in self.analyzer.find_markets(resource, sellbuy):
system = self.store.get(System, m.system())
p = self.analyzer.find_path(location, system)
if p is None: continue
print(m, f'{len(p)} hops')
def do_path(self):
orig = self.ask_obj(System, 'from: ')