Rogue Trader

What if your economics textbook was a roguelike game?

View on GitHub
13 April 2018

Bugs and YAML

by Kromey

The coding for Rogue Trader’s economy simulation is very nearly complete. Agents have already been buying from and selling to one another, their interactions in aggregate creating a market with discernable properties, the most obvious (and, arguably, most important) being “market price”, which is going to be what players interact with most.

This week I found a couple of egregious bugs. The first was that once a pair of Orders were matched and resolved, I was not returning any remaining quantities in either Order back to the Auction. For example, if Sally wanted to sell 5 Widgets, and Sue wanted to buy 3 Widgets, the Auction matched them and closed the sale of 3 Widgets from Sally to Sue. Sally, of course, still wants to sell 2 more; unfortunately, due to this bug, she wasn’t permitted to. Fortunately it was a quick fix (once I spotted it), so now Sally goes back into the Auction with her 2 remaining Widgets for sale. As a result, market volume has approximately doubled, and it’s now rarer for my initial set of Agents to go bankrupt.

The other big bug squashed was one that had gone unnoticed since I started the project. When Agents fail to buy/sell their desired amount in a given turn, they do 2 things: They become less certain of their belief of the true “market price”, and then they examine trading statistics again and adjust their belief. Internally, this belief is represented as a pair of numbers, with the Agent certain that the true price is somewhere in the middle. If they’re less certain, this range expands; they’ll also tend to shift this range so that its mean is closer to the mean price of trades that actually happened. While I had noticed almost since the beginning of this project that Agents selling Sand quickly spiralled their prices down to 1 (the minimum the simulation allows), I hadn’t looked into their beliefs. When I did, I was shocked to find that prices were so low because their belief had grown very uncertain (i.e. a very wide range), and the lower boundary was very negative! This meant that they were often trying to pay other Agents to take their Sand! The Order object itself wouldn’t allow this, but only by silently changing the price to a minimum of 1. I added an extra check now so that Agents’ price beliefs can never go below the minimum price; as a result Sand remains very cheap, but doesn’t sink all the way to 1 and stay there, making for more interesting markets.

The biggest improvement to the simulation this week is that when Agents go bankrupt, they now get replaced. The new Agents examine market performance and join the most profitable profession. I’m considering having them also check for any Goods on the market where demand is considerably higher than supply, then analyzing available jobs to find one that produces that Good in high quantity – the idea being that they are seeing an opportunity and jumping at the chance to cash in. That’s for the future, though.

I’ve also moved both goods and jobs into individual YAML files; previously they had been hard-coded directly into the code itself. This is going to make it easier to create more advanced jobs and more complex production chains, which – if everything else goes smoothly – will make for a far more interesting simulation. This will also establish the framework to make the game expandable/modable down the road: Want to give yourself a new uber-ship so you can rule the galaxy? That’s just a few simple lines of YAML! For now it just loads specific files, but the plan is to have it look for sets of files, so that the game would load the core files and then any user-supplied ones, overriding core data as necessary. That, too, is peeking well into the future.

tags: economy - simulation - bugfix