general leads the startup

This commit is contained in:
Richard 2024-02-11 14:37:46 +01:00
parent cf930fe24b
commit 53867a3257
6 changed files with 49 additions and 13 deletions

View File

@ -11,12 +11,13 @@ def main(args):
a = StoreAnalyzer(verbose=True)
a.run(args.analyze)
else:
c = Commander(args.data_dir)
c = Commander(args.data_dir, auto=args.auto)
c.run()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--data-dir', default='data')
parser.add_argument('-a', '--analyze', type=argparse.FileType('rb'))
parser.add_argument('--analyze', type=argparse.FileType('rb'))
parser.add_argument('-a', '--auto', action='store_true')
args = parser.parse_args()
main(args)

View File

@ -19,7 +19,7 @@ class CommandError(AppError):
pass
class Commander(CommandLine):
def __init__(self, data_dir='data'):
def __init__(self, data_dir='data', auto=False):
store_file = os.path.join(data_dir, 'store.npt')
hist_file = os.path.join(data_dir, 'cmd.hst')
self.cred_file = os.path.join(data_dir, 'creds.txt')
@ -41,6 +41,8 @@ class Commander(CommandLine):
self.ship = None
self.stop_auto = False
if auto:
self.do_auto()
super().__init__()
######## INFRA #########
@ -406,6 +408,9 @@ class Commander(CommandLine):
crew = self.resolve('Crew', arg)
ship.crew = crew
pprint(ship)
def do_phase(self, phase):
self.agent.phase = phase
######## Crews #########
def do_create_crews(self):

View File

@ -24,11 +24,29 @@ class General:
self.create_default_crews()
def find_shipyard(self, stype):
occ = [s.location.symbol for s in self.store.all('Ship') if s.status != 'IN_TRANSIT']
best_price = -1
best_yard = None
for shipyard in self.store.all('Shipyard'):
if stype in shipyard.types:
return stype
return None
if stype in shipyard.prices:
price = shipyard.prices[stype]
if shipyard.symbol in occ:
if best_yard is None or price < best_price:
best_yard = shipyard
best_price = price
return best_yard, best_price
def maybe_purchase(self, stype, role):
sy, price = self.find_shipyard(stype)
if sy is None:
return False
traders = [s for s in self.store.all('Ship') if s.role == 'trader']
safe_buffer = len(traders) * 100000 + 100000
if self.agent.credits < safe_buffer + price:
return # cant afford it!
ship = self.c.api.purchase(stype, sy)
ship.role = role
def tick(self):
phase = self.agent.phase
@ -50,12 +68,25 @@ class General:
command.role = 'probe'
if probe.role is None:
probe.role = 'sitter'
system = command.location.system
markets = list(self.store.all_members(system, 'Marketplace'))
discovered = len([m for m in markets if m.last_prices > 0])
if discovered > len(markets) // 2:
return 'probes'
def phase_probes(self):
ag = self.agent.symbol
command = self.store.get('Ship', f'{ag}-1')
# * probes on all markets
pass
if command.role != 'trader':
command.role = 'trader'
self.c.captain.init_mission(command, 'none')
self.maybe_purchase('SHIP_PROBE', 'sitter')
sitters = [s for s in self.store.all('Ship') if s.role == 'sitter']
markets = [m for m in self.store.all('Marketplace')]
if len(sitters) >= len(markets):
return 'trade'
def phase_trade(self):
# 20? traders
pass

View File

@ -20,5 +20,6 @@ class Agent(Base):
def f(self, detail=1):
r = super().f(detail)
if detail >2:
r += f' c:{self.credits}'
r += f' c:{self.credits}\n'
r+= f'phase: {self.phase}'
return r

View File

@ -6,7 +6,7 @@ def assign_probe(c, s):
m = [m.waypoint for m in c.store.all_members(system, 'Marketplace')]
m = solve_tsp(c, m)
hops = [w.symbol for w in m]
start_hop = randrange(0, len(hops))
start_hop = 0
s.log(f'Assigning {s} to probe {len(hops)} starting at {hops[start_hop]}')
c.captain.init_mission(s, 'probe')

View File

@ -13,8 +13,6 @@ def assign_sitter(c, s):
shipyards = c.store.all_members(system, 'Shipyard')
occupied = [s.mission_state['dest'] for s in ships if s.mission=='sit']
probe_shipyard = [y for y in shipyards if 'SHIP_PROBE' in y.types][0]
print('oc', occupied)
print('proya', probe_shipyard)
if probe_shipyard.symbol not in occupied:
return assign_sitter_at(c, s, probe_shipyard)