Skip to content

Commit

Permalink
conductor now support multiple gate buidlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Feb 2, 2024
1 parent 677f27b commit 3f10aaa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion behaviours/generic_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def sleep_until_arrived(self):

set_logging(level=logging.DEBUG)
agent = sys.argv[1] if len(sys.argv) > 2 else "CTRI-U-"
ship_number = sys.argv[2] if len(sys.argv) > 2 else "1"
ship_number = sys.argv[2] if len(sys.argv) > 2 else "D"
ship = f"{agent}-{ship_number}"
bhvr = Behaviour(agent, ship, {})
bhvr.ship = bhvr.st.ships_view_one(ship, True)
Expand Down
25 changes: 17 additions & 8 deletions behaviours/refuel_all_fuel_exchanges_in_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from behaviours.generic_behaviour import Behaviour
import logging
from straders_sdk.utils import try_execute_select, set_logging, waypoint_slicer
from straders_sdk.constants import SUPPLY_LEVELS
from straders_sdk.models import Waypoint, System, Market, MarketTradeGoodListing

BEHAVIOUR_NAME = "REFUEL_ALL_IN_SYSTEM"
Expand Down Expand Up @@ -115,7 +116,7 @@ def _run(self):
m = self.st.system_market(w)
fuel = m.get_tradegood("FUEL")
trips = 0
while (fuel.supply != "ABUNDANT" and trips < 5) and self.still_profitable(
while (fuel.supply != "ABUNDANT" and trips < 5) and self.should_still_trade(
fuel_market, m
):
self.ship_intrasolar(fuel_market.symbol)
Expand All @@ -141,15 +142,21 @@ def _run(self):
self.end()
self.st.logging_client.log_ending(BEHAVIOUR_NAME, ship.name, self.agent.credits)

def still_profitable(
def should_still_trade(
self, fuel_market_wp: Waypoint, dest_market_wp: Waypoint
) -> bool:
fuel_market = self.st.system_market(fuel_market_wp)
dest_market = self.st.system_market(dest_market_wp)

fuel_price = fuel_market.get_tradegood("FUEL").purchase_price
source_tg = fuel_market.get_tradegood("FUEL")
fuel_price = source_tg.purchase_price
dest_price = dest_market.get_tradegood("FUEL").sell_price

if source_tg.activity == "STRONG" and SUPPLY_LEVELS[source_tg.supply] < 4:
return False
elif SUPPLY_LEVELS[source_tg.supply] < 3:
return False

return dest_price > fuel_price


Expand All @@ -158,11 +165,13 @@ def still_profitable(

set_logging(level=logging.DEBUG)
agent = sys.argv[1] if len(sys.argv) > 2 else "CTRI-U-"
ship_number = sys.argv[2] if len(sys.argv) > 2 else "3"
ship_number = sys.argv[2] if len(sys.argv) > 2 else "2B"
ship = f"{agent}-{ship_number}"
bhvr = RefuelAnExchange(agent, ship, {})

lock_ship(ship_number, "MANUAL", 60 * 24)
while True:
bhvr = RefuelAnExchange(agent, ship, {})
lock_ship(ship_number, "MANUAL", 60 * 24)

bhvr.run()
lock_ship(ship_number, "MANUAL", 0)
bhvr.run()
bhvr.sleep_until_arrived()
lock_ship(ship_number, "MANUAL", 0)
6 changes: 5 additions & 1 deletion blog/Version 2.1.4 (week 29&30).md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ Once that's completed, a mechanism by which the user token can be used to instan

## performance

* Node U (exp) - Didn't do initial exploration - why?
* Node U (exp 29-30) - Didn't do initial exploration - why?
* The evolution behaviour appears to be buying goods when it's at the end of the chain and there's no profitable location - so it ends up selling them at a loss next time around.

* Node C (27-28) - Didn't do initial exploration - why?
* It actually did in the end!
* But jump gate building wasn't on by default - it should be.
* Node V (26-27) - Didn't do initial exploration - why?


Expand Down
27 changes: 14 additions & 13 deletions conductorWK25.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def system_minutely_update(self, system: "ConductorSystem"):
len(system.haulers) * 50000 + 150000,
)
if resp:
self.haulers.append(resp)
system.haulers.append(resp)
self.set_hauler_tasks(system)
else:
system._next_ship_to_buy = hauler_type
Expand All @@ -366,7 +366,7 @@ def system_minutely_update(self, system: "ConductorSystem"):
len(system.haulers) * 50000 + 150000,
)
if resp:
self.extractors.append(resp)
system.extractors.append(resp)
self.set_extractor_tasks(system)
else:
system._next_ship_to_buy = system.extractor_type_to_use
Expand All @@ -378,7 +378,7 @@ def system_minutely_update(self, system: "ConductorSystem"):
len(system.haulers) * 50000 + 150000,
)
if resp:
self.siphoners.append(resp)
system.siphoners.append(resp)
self.set_siphoner_tasks(system)
else:
system._next_ship_to_buy = "SHIP_SIPHON_DRONE"
Expand All @@ -392,7 +392,7 @@ def system_minutely_update(self, system: "ConductorSystem"):
len(system.haulers) * 50000,
)
if resp:
self.satellites.append(resp)
system.satellites.append(resp)
self.set_probe_tasks(system)
else:
system._next_ship_to_buy = "SHIP_PROBE"
Expand All @@ -415,7 +415,7 @@ def set_probe_tasks(self, system: "ConductorSystem") -> int:
set_behaviour(
probe.name,
BHVR_MONITOR_SPECIFIC_LOCATION,
{"waypoint": target_waypoint},
{"waypoint": target_waypoint, "priority": 5},
)
for shipyard in shipyards:
if len(satellites) == 0:
Expand All @@ -424,7 +424,7 @@ def set_probe_tasks(self, system: "ConductorSystem") -> int:
set_behaviour(
probe.name,
BHVR_MONITOR_SPECIFIC_LOCATION,
{"waypoint": shipyard},
{"waypoint": shipyard, "priority": 5},
)
probe_jobs += len(shipyards) + 1

Expand Down Expand Up @@ -456,8 +456,9 @@ def set_hauler_tasks(self, system: "ConductorSystem") -> int:
+ system.haulers_chain_trading
+ system.haulers_doing_missions
+ system.haulers_evolving_markets
+ (1 if system.construct_jump_gate else 0)
+ system.haulers_constructing_jump_gate
)

# set up the haulers to go to the markets and buy stuff
# chain trade 3
# manage supply chain 4
Expand Down Expand Up @@ -513,7 +514,7 @@ def set_hauler_tasks(self, system: "ConductorSystem") -> int:
bhvr.BHVR_EXECUTE_CONTRACTS,
{"priority": 3},
)
if system.construct_jump_gate:
for i in range(system.haulers_constructing_jump_gate):
if len(ships) == 0:
return hauler_jobs
hauler = ships.pop(0)
Expand Down Expand Up @@ -652,7 +653,7 @@ def _generate_game_plan(self, filename="game_plan.json"):
gate: Waypoint
gate_complete = not gate.under_construction
if gate.under_construction:
start_system.construct_jump_gate = True
start_system.haulers_constructing_jump_gate = 1
start_system.commander_trades = True
else:
start_system.commander_trades = False
Expand All @@ -668,7 +669,7 @@ def _generate_game_plan(self, filename="game_plan.json"):
start_system.mining_sites = [w.symbol for w in e]

if gate_complete:
start_system.construct_jump_gate = False
start_system.haulers_constructing_jump_gate = 0
# we need populate the next HQ system - starting with our own.
factions = st.list_factions()
# sort them by distance to our location
Expand Down Expand Up @@ -710,7 +711,7 @@ def _generate_game_plan(self, filename="game_plan.json"):
next_system.siphoners_per_gas_giant = 0
next_system.commander_trades = True
else:
start_system.construct_jump_gate = True
start_system.haulers_constructing_jump_gate = 1

self._save_game_plan("game_plan.json")

Expand Down Expand Up @@ -793,7 +794,7 @@ class ConductorSystem:
probes_to_monitor_markets: bool = False
probes_to_monitor_shipyards: bool = False
use_explorers_as_haulers: bool = False
construct_jump_gate: bool = False
haulers_constructing_jump_gate: int = 0
mining_sites: list[str] = []

hauler_tradechain_maintain_goods: int = []
Expand Down Expand Up @@ -856,7 +857,7 @@ def to_dict(self):
"haulers_evolving_markets": self.haulers_evolving_markets,
"hauler_tradechain_evolve_prioity": self.hauler_tradechain_evolve_prioity,
"haulers_doing_missions": self.haulers_doing_missions,
"construct_jump_gate": self.construct_jump_gate,
"haulers_constructing_jump_gate": self.haulers_constructing_jump_gate,
"siphoners_per_gas_giant": self.siphoners_per_gas_giant,
}

Expand Down

0 comments on commit 3f10aaa

Please sign in to comment.