spacetraders-v1 v0.8
Trading logic
Big day of work on the trading system. I added flight plan functionality - ships can now create flight plans to destinations and the UI shows a progress indicator with time remaining using a CircularProgressWithLabel component.
The main feature is the cargo determination algorithm in determineCargo.ts. It looks at market prices at the current location and destination, calculates potential profit for each good, and determines what to buy. The shipMachine now has a full trading loop: check fuel, determine destination, determine cargo, buy goods, create flight plan, wait for arrival, repeat.
I also added a Locations component that displays all known locations with their market data, and a Cargo component to show what’s in the ship’s hold. Market data is now cached to localStorage via a locationCache module so we don’t refetch unnecessarily.
Finally, I wrote tests for both the shipMachine and determineCargo logic using an objectMother pattern for test fixtures. The tests verify the state machine transitions and cargo calculation edge cases.
More spacetraders-v1
My first implementation against the spacetraders api is an entirely browser-based UI and automation tool · source · play spacetraders-v1 · spacetraders api · posts