How do you simulate...
 
Notifications
Clear all

How do you simulate an economy?


auryx
(@auryx)
Warrant Officer Registered
Joined: 7 years ago
Posts: 202
Topic starter  

This is something I've always wondered about, ever since I first started dreaming about writing a space sim many years ago. How do you build the economic aspect of the simulation?

I'm thinking of nothing too complex, just the basic kind of trading model you find in the Elite games or in Privateer - so, stuff like:

- different categories of trade goods with different prices and volumes

- different planets have different wants and needs

- one-off events can push up prices

- prices fluctuate realistically depending on how much is available

- some items are contraband; some are perishable; some require specially modified cargo holds to transport

and so on. Does anyone know what kind of model is generally used to code this klind of thing? How do you make it realistic without drowning in detail?

auryx

You look good through a crosshair.


Quote
Cody
 Cody
(@cody)
Captain Registered
Joined: 7 years ago
Posts: 1957
 
'auryx' wrote:
... just the basic kind of trading model you find in the Elite games ...

It may be worth your while looking at the innards of Oolite - that follows the trade-model of the original Elite, with some good OXPs (mods) adding additional possibilities - and it's a cracking game too!

Oolite Naval Attaché


ReplyQuote
Hypnotron
(@hypnotron)
Petty Officer Registered
Joined: 14 years ago
Posts: 29
 

I think the way to do this is to build many many small experimental applications where you test various concepts. Store them all in your EconExperimentsExp## folders and go from there.

I think the wrong way to go is to try and design and build a monolithic model from start to finish in a single effort.

Don't worry about multi-threading, don't worry about performance, don't worry about hard coding things, just experiment on different economic models.


ReplyQuote
Simbad
(@simbad)
Senior Chief Registered
Joined: 13 years ago
Posts: 61
 

If you are talking about how to realize it in code. Its all about state machines.


ReplyQuote
auryx
(@auryx)
Warrant Officer Registered
Joined: 7 years ago
Posts: 202
Topic starter  

Thanks everyone, those are all really interesting (and useful) replies. Cody, I haven't looked at Oolite in years, and stupidly had thought that the source code wasn't available - d'oh! I'll definitely have a look and see what I can dig out from it.

I think the advice to just play with lots of different models and see which "works" is probably very sound. I'd be in danger of trying to plan it all out in advance and then just getting frustrated! I guess it's the kind of area where you could go as deep as you wanted, but the level of detail required would just get huge as everything started to interact with everything else (and would make it very hard to test).

Simbad, I'm intrigued by your mention of state machines - I don't really know much about that concept. I'll look it up!

I did have a search on Google, but of course searching for things like "trade", "simulator", "economy" etc brings up lots of results for stock market simulations <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_smile.gi f"' class='bbc_emoticon' alt=':-)' />

auryx

You look good through a crosshair.


ReplyQuote
Hypnotron
(@hypnotron)
Petty Officer Registered
Joined: 14 years ago
Posts: 29
 

Also, what is your goal with the economy? A lot of games seem to try fancy realtime supply/demand economies but to what end? If it's just for passable valuations of products based on relative equilibrium between a lot of factors, then supply/demand isn't necessary at all. You can just fake the entire thing with a simplified elasticity model.

I think a lot of games have spent time and energy making fancy economies but for relatively little point when a simpler model would have delivered virtually the same experience. Economies aren't fun in and of themselves. So spend time thinking why you want a fancy economy and that might help you decide what kind of economy to program. How does the economy affect gameplay? You should be very critical as to your need for a complex economy when a simple one will do.


ReplyQuote
Hypnotron
(@hypnotron)
Petty Officer Registered
Joined: 14 years ago
Posts: 29
 

I suppose you could go hog wild... not many folks would find that particularly fun though... but you can't please everyone <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_smile.gi f"' class='bbc_emoticon' alt=':)' />

[media]

"Let's Play Capitalism 2"


ReplyQuote
auryx
(@auryx)
Warrant Officer Registered
Joined: 7 years ago
Posts: 202
Topic starter  

Hah hah, thanks.

I'd be quite happy to "fake" it, but wasn't even sure how to do that and yet still make it realistic, and I began to wonder if actually doing supply/demand would be easier.....guess not <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_smile.gi f"' class='bbc_emoticon' alt=':-)' /> I really need to just start playing around with some values, as suggested here, and see how it goes!

You look good through a crosshair.


ReplyQuote
Magnox
(@magnox)
Petty Officer Registered
Joined: 12 years ago
Posts: 11
 
'Hypnotron' wrote:
I think a lot of games have spent time and energy making fancy economies but for relatively little point when a simpler model would have delivered virtually the same experience. Economies aren't fun in and of themselves. So spend time thinking why you want a fancy economy and that might help you decide what kind of economy to program. How does the economy affect gameplay? You should be very critical as to your need for a complex economy when a simple one will do.

This is an excellent post and worth thinking about. If you need a fully dynamic economy the coding is referred to as a 'finite state machine' as Simbad mentioned. This is just a fancy way of saying you essentially code a flowchart. IF this condition exists, move to a particular outcome (which may also have conditions) OR move to a secondary outcome. They can be as simple or complex as you wish. If you wish to code combat AI you will probably be using one of these. Basically, you take a complex situation (3D combat with variable speeds, differing weapons, differing initial scenarios) and break it down into simple steps. For example, our AI has ten levels of NPC skill and we simply pass that skill level to the state machine. The chances of the NPC performing the most efficient or correct action is a percentage based on their skill level. We are not trying to code 'stress levels' for pilots, or anything remotely close - it's a weighted random event. There is a chance that rookie you're facing pulls off some nice moves initially, but the chances of that continuing or remaining constant diminish on a probability bell curve with each decision applied. The more decisions you force the AI to make (i.e. the better you fly), the more likely it is to fail. The easier the time you give it, the fewer 'decisions' it has to make and therefore the probability that it will be effective increases. Simple maths. There is also a chance that the 'Ace' NPC you go up against makes a mistake. If it didn't, it would probably be unbeatable and this mirrors human decision making, but it will give you a hard fight. When you see that weakness you need to exploit it before it gets back on track.

The economy in our game is properly dynamic, rather than random or elastic, because we believe there are players who enjoy the trading role. This is how we've done ours (simplified version!):

Every station and planet has products they produce and products they consume, the input and output of which are set at the start of the game. Consumption and production is based on demand from both you and the NPC factions. If planet X produces rare metals, it will have a demand for mining equipment and consumables. If no one buys the metals, the stockpile causes the price to drop and the demand for mining equipment etc. reduces. Consequently the output of rare metals reduces. This, if you run it as a number simulation, actually ends up with a static economy, so what we have done is essentially hard-coded an existing economy into the game; planet Y wants rare metals, because it creates computer components.

Therefore, if no one wants computer components, planet Y's economy will stagnate and impact on planet X. I'm sure you can see where this is going. What we've done is set up a fairly stable economic system so that there is always demand for produced materials that pretty much balances availability. So it's a static economy with minor price fluctuations and you can see why Hypnotron posted the recommendations. Thing is, NPC factions in our system are looking to disrupt or steal from the economy of their rivals. If a freighter is destroyed which carries computer components, the supply is now starting to be limited and prices will rise. Production will need to step up so demand for secondary materials rises in a knock-on effect. This is where you can dive in to fill a niche. Or.. you could destroy a freighter yourself, causing the rival trading house to have to build a new ship (which takes a lot of in-game time) and opening up an opportunity you could exploit.

As prices rise and routes become more profitable, the NPCs will look to exploit that themselves and price balancing starts to happen. Except that as the routes become more profitable, they become more risky as pirates look to exploit the freighters. We calculate risk for NPCs by assigning a value to their ships (offense/defence) and the possible profit. If the value is too low, they don't bother. That's where you can run a high risk/high reward scenario. That's as complex as we've gone and it works nicely.

We couldn't do that with a 'fake' economy, but you can be very convincing with the right maths model. If you want to talk equations drop me a PM <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_smile.gi f"' class='bbc_emoticon' alt=':)' />


ReplyQuote
auryx
(@auryx)
Warrant Officer Registered
Joined: 7 years ago
Posts: 202
Topic starter  

Thanks guys - Magnox, it's especially interesting to get an in-depth picture of how your model works, so appreciate that. I like the idea of implementing a semi-stable "basic economy", with a few hardcoded values to set it going (planet Y wants rare metals, etc), and then spicing up the mix by introducing piracy and economic sabotage to keep things fun!

I wonder if this would work if you had a game with thousands of procedurally-generated worlds; I suppose it would, as you could hardcode the values into planet "types" rather than individual planets (e.g. a capitalist, tech level X, industrial world will always need commodity y, and so on).

I started this thread just because it's a topic that has always interested me, but now I'm tempted to go try and write a model myself, taking all the suggestions into account!

auryx

You look good through a crosshair.


ReplyQuote
Simbad
(@simbad)
Senior Chief Registered
Joined: 13 years ago
Posts: 61
 

What programming language do you want to use?

For C/C++ I could help you a bit with some code fragments and other information about how to solve.


ReplyQuote
auryx
(@auryx)
Warrant Officer Registered
Joined: 7 years ago
Posts: 202
Topic starter  

Thanks Simbad, that's a generous offer!

It's a long time since I actually did any coding, so I'm pretty rusty in all languages. I'd probably aim for something like Python, to be honest, since I find it less scary than C <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_smile.gi f"' class='bbc_emoticon' alt=':-)' /> but will see. First I need to spend some time finding all my old notes, and working out the overall model, before actually trying to program anything.

auryx

You look good through a crosshair.


ReplyQuote
JamesCoote
(@jamescoote)
Petty Officer Registered
Joined: 12 years ago
Posts: 33
 

I did a similar thing to Magnox. However, in my game, the object of the game is to do the job of the NPC freighters!

Since I've not yet put in AI competitors, I put in some additional constraints. Firstly, I cap the price of tradeable stuff to within x% of a 'base price'. So say the price of rare metals is $100, and the 'range' 10%

If the factory is getting zero supply, it will offer a price of $110. If it is getting too much, it'll still buy, but only at $90. Since some rare metals mine some other place is using the same pricing scheme, the cheapest possible price the player can buy is $90, meaning a loss is made by the player (after transport costs)

To work out the % value based on supply and demand, I record the supply / demand over a period of 30 turns, then I calculate what the max supply/demand is (depending on the factory/mine. How much it input/output it needs/produces per turn).

I divide the average by the max to get a figure between -1 and 1.

Multiply this by the % range, and then multiply that by the 'base price' to get the actual price

In addition, I fluctuate the base price according to random brownian motion to simulate the general price of a product or raw material going up and down. This also means technically players can speculate on the price of goods, though I haven't implemented storage facilities that the player controls yet, so they have to just drive their ships round in circles at the moment, and that gets expensive fast.

There are other neat things I could add in as well, such as some factories/mines having lower non-material production costs, so being able to offer a higher buy price or lower sell price.

Eventually under this model, the game reaches equilibrium, and the player can no longer make any profit. However, it's fairly simple to just add in a mechanic whereby if x,y,z resource is supplied for w amount of time, there is a v chance of a random new factory being built on that planet/station. Equally, you can have 'population growth,' which increases demand for consumable goods. And you can have at any time a random chance of a 'new ore deposit' being found and a mine built on it.

I always look to Transport Tycoon for inspiration. You can get it free here: http://www.openttd.org/en/ It has a very simple economy which is just as described in my last paragraph above. Each factory / mine produces x amount of stuff per month, and you get paid for transporting the cargo. You don't have to buy, then sell at the other end. The prices follow a simple equation that roughly works out as the greater the distance transported, the higher the price, the more time taken, the lower the price


ReplyQuote
Locke
(@locke)
Petty Officer Registered
Joined: 10 years ago
Posts: 14
 

Supply and demand.


ReplyQuote