spacetraders-v2 · Mar 19–23, 2024 · v2.4–v2.6

First automation, first contract delivered

first automation v2.4

I’ve implemented some fairly rudimentary automation that covers the first five of the six quickstart steps. This includes:

  • Registering a new agent should one not be persisted for the current reset date
  • Accepting a contract
  • Purchasing a mining drone and sending it out the an asertoid
  • Refueling and mining the asteroid
  • Transiting to markets to sell the ore

I went down a particularly unpleasant PostgreSQL docker container permission issue and was ultimately unable to solve it. I’ve improved the error handling and have stack traces available in Seq, and solved wrong line numbers in ts-node/Node v20 stack traces. I’m now persisting market data in postgres to reduce api calls and have also introduced bottleneck to stay within the rate limits of the spacetraders api.

To complete this first round of automation I still need to:

  • Add some routing capability so ships can move between waypoints for journeys that otherwise can’t be made directly due to fuel constraints
  • Deliver contract goods to their destination and fulfil the contract

first contract delivered v2.5

I’ve completed the first round automation such that a new agent can be spawned and it will complete all actions of the Quickstart including Fulfilling the contract. I’ve also added code to pickup subsequent contracts but the first time this occurred the contract required a resource that is not the result of mining, so I’ll need to add further automation to cater for that case.

I’m saving state from some of the api responses to postgres and using the existing types the api returns in combination with postgres jsonb columns to store the data. By default Adminer truncates long JSON columns. While a plugin exists to solve this the adminer docker container only includes official plugins. To solve for this, i’ll use the docker compose feature dockerfile_inline:

adminer:
    build:
      dockerfile_inline: |
        FROM adminer
        ADD --chmod=644 https://raw.githubusercontent.com/staff0rd/adminer-plugins/master/AdminerJsonPreview.php /var/www/html/plugins/AdminerJsonPreview.php
    restart: unless-stopped
    ports:
      - '8080:8080'
    environment:
      ADMINER_PLUGINS: 'AdminerJsonPreview'

This approach allows me to extend the adminer container without having to have a Dockerfile on disk, and thankfully ADD supports fetching files from the internet, so I don’t need the plugin on disk either.

extracting ship automation v2.6

I’ve written logic to automate negotiation of new contracts, but the first time this executed it resulted in a contract that required a resource that is not the result of mining. I’ll need to add further automation to cater for this case.

I have extracted the mining drone logic out such that a similar logic loop can be used with any ship:

  1. If in transit, wait for the ship to arrive
  2. Perform some action based on inspecting current state
  3. Repeat

The command ship now uses this same logic and additonally spawns additional actors, in this case the single mining drone. I’m logging a bunch more data, like credits and waypoint status and am now set to choose the next optimisation to apply.

credit charts

The mining drone logic is very slow as it uses the same ship to both extract and once the cargo hold is full, deliver the excess trade goods. I intend to add additional mining drones to the fleet, but before I do this I’ll add shuttle logic so the mining drones can focus on mining, while cheaper shuttles perform the delivery.