Realistic economy in 4x

Started by
12 comments, last by omikun 6 years, 12 months ago

I was thinking about implementing a realistic economy and happened on this old thread: https://www.gamedev.net/topic/554811-what-makes-a-good-4x-space-game-economy-model/

I like it, and I think it is doable. I would like to write a proof of concept but I am having trouble getting started. Here is my idea:

The economy is a white box with resources and people as inputs. Money is a proxy for value and the mapping between money and value will change with inflation/deflation.

  • Value is in the form of labor from people and resources mined from the environment.
  • The economy start with some amount of money.
  • As resources are brought in, there is more value in the economy than money, so deflation occurs.
  • The player can inject money into the system, inflating the currency. The player can destroy the injected money to cause deflation. (buying/selling treasury bonds)

The player, in this case, controls the government. So if the player wants to spend more money to buy a product or service (raise an army or a space fleet), it must print money and use that money to pay corporations to build it. The corporation takes the money and buys resources and convert that to the product and give that to the government. By printing money, inflation occurs so the price of that product will increase. The more money the player prints, the more expensive everything becomes.

The player also gets money in the form of taxes, so the larger the economy, the more money the nation gets. The player can use tax money to buy products without driving the prices up.

Now what prevents the player from injecting a ton of cash into his economy and then building a massive fleet to conquer the world? Well it would be very expensive, especially early on when the economy is small and the tech is low. But there could be a mid game inflection point when the tech is high enough that the player can hyper inflate her economy and make a one time push for mass militarization. Of course this will take a while, perhaps several years. In that time the rest of the world can see it and will either

  • Raise their own armies and band together
  • Embargo trade with the player to strangle her economy

The second point would require trade between nations and resource distributions where the player cannot have everything it needs to build a massive army. But I feel I'm getting too far ahead now.

So here is my implementation idea in python for readability


class nation:
  var money
  var injectedMoney
  var population
  var productivity #1 is normal,
  var value #all worth in nation
  var govMoney

  def CollectTax(): 
    govMoney += taxRate * gdp

  def GetInflation(): 
    return (money + injectedMoney) / value

  def PrintMoney(moarmoney): 
    injectedMoney+=moarmoney

  def BuyBackBond(money):
    injectedMoney -= money

  def BuyThing(money):
    gdp += money
    valueBought = (1 - profitMargin) * money / GetInflation()
    #collect resources
    value += valueBought
    timeToCompletion = UnitManTime / (population * productivity)

I'm missing a few things, like trade, embargo, and how to actually collect resources and bring that into the economy and what that means. I guess that is where I am stuck. Any suggestions? Anything else I am missing?

Advertisement

From what you've described one solution is a simple map of costs to a base unit.

If you use just one data dictionary, or map, or key/value pair, or whatever you want to call it, that contains every comparison to the base currency. Thing 1 cost 47, thing 2 costs 19, thing 3 costs 493. Repeat for all the things. The key/value pairs may be using strings, or named constants, or whatever, that doesn't matter.

With a system like that inflation or deflation can be modeled by either a global scaling factor to the conversions. A deflated currency may have a multiplier less than one, an inflated currency the multiplier is larger than one. If something would cost 19, the multiplier kicks in and maybe now it costs 28. Deflation kicks in a little more, the multiplier shrinks, and now the costs become 27, then 25, then maybe 21.

As items become more common or more scarce their base costs can also adjust, thing 2 used to cost 19, but due to scarcity it increases to 20, 21, 22... with similar changes as items change over time.

Now for the specific questions:

Value is in the form of labor from people and resources mined from the environment. The economy start with some amount of money.

Sounds good, everyone needs a starting point.

As resources are brought in, there is more value in the economy than money, so deflation occurs.

Instead, have resources modify their value relative to the base. Scarcity increases that resource's cost, abundance decreases the costs.

If you have multiple nations or multiple competing economies, you can even use your abundance against their scarcity. The cost for you to sell a good you have in abundance becomes low, but the cost for them to buy a good that is scarce for them becomes high, so you gain a huge profit. The reverse also happens, if you have scarcity and they have abundance, their low cost to base currency and your high cost to base currency means you will pay a fortune for resources that are scare for you.

The player can inject money into the system, inflating the currency. The player can destroy the injected money to cause deflation. (buying/selling treasury bonds)

Those work with the currency scalar.

The more money the player prints, the more expensive everything becomes. The player also gets money in the form of taxes, so the larger the economy, the more money the nation gets. The player can use tax money to buy products without driving the prices up.

Good. Games need both a source and a sink. If games only have source with no sink then over time currency becomes worthless. High-level players have fortunes that are meaningless to them. However, if the sink is too powerful then players will struggle to succeed. The balancing is sometimes tricky, particularly in online games.

Now what prevents the player from injecting a ton of cash into his economy and then building a massive fleet to conquer the world? ... In that time the rest of the world can see it and will either ...

It is a challenge, but crafting economic simulations is a great design experience. It needs to scale up or down with various economy sizes, prices need to be kept in control to make it difficult for runaway inflation or runaway deflation, but not so much that it becomes impossible unless you really need it to be impossible.

In my experience these are best put together by combining a few simple statistics curves:

Sigmoid curves (they look like a stretched-out S) are very useful. You can set the values so they are asymptotic, on the low end they approach but never quite hit zero, and on the high end they approach but never quite hit one. Then you can give them a tuneable slope in the center. Finally, scale it up or down to the size you need, and it gives you a smooth transition. Even though it is scary for some people on first sight, it is cheap to calculate, you get the result with just some simple operations and a single exponential operation, and the values are easy to visualize and manipulate interactively.

Poisson curves and Gaussian curves are useful. They are both bell curves that allow for slightly different tuning. You can make them scale out so they also have asymptotic behavior. You can skew and spread and condense and flip and otherwise manipulate these curves as much as you want.

Throw in a few simple operations like exponentiation, negation, and +,-,*,/, and you've got a number-processing system that any number-crunching geek can spend years tinkering with.

So here is my implementation idea in python for readability

I'd reduce that so you take keys, then look them up in the table or adjust the table value. Getting the current market value is: costTable[thingKey] * currencyScale; If you are buying some of one thing and selling some of another thing, get the two costs and compare the differences. If you are trading between two nations, the same thing applies, use one economy's cost for a thing and the other economy's cost for the thing, then compare the difference.

The tasks for printing money, taxes, or any other source/sink functions would adjust the currency scale for the economy.

But be careful when adjusting values, you'll want to make the adjustments go through the designer's scaling functions. That's where the sigmoids and other functions become powerful, if you already are very high then increasing it again should result in almost no difference. If you are very low then decreasing it should result in almost no difference. But if you are right near the center point then small change can make an enormous difference. Same things with bell curves, if you are near the slopes the change is rapid and visible, but near the flat areas a change may be nearly unnoticeable.

Whatever you do, have fun with it. These economic systems are crazy fun to set up, and fine-tuning them so they don't collapse starts with hours of pleasure that turns into endless frustration as the shipping date approaches. :-)

Thanks frob! When you are talking about the curves, do you mean inflation versus money supply? I was thinking inflation = money_supply / value, but you are suggesting I do more of an inflation = f(money_supply/value) where f is sigmoid or others?

Is there any literature on this? I know inflation has a psychological component and the f models that perhaps?

What I'm wondering is the in-game effects of all this. If the player can at anytime grow or shrink the money supply, where is the fun in that? It could turn into another knob that the player has to always be fiddling with and that can quickly become an annoyance.

Perhaps it can only be changed at intervals or the money supply can only be changed in fixed amounts. But that's really arbitrary.

So I have a thought experiment that might illustrate the problem with this idea:

Suppose, in a very reduced context, the nation has one company and a uniform population. The company pays the population, and the population consumes the products they help the company produce. Now if the company starts with 100 money, and spends 50 on the population as salary. The population has at most 50 to spend on the products they produced. The company can never make money. Say the pop borrows 50 from the government (gov injected 50 into the economy) now the company can sell 100 worth from spending 50, so it has a 100% profit margin. But in order for the company to keep making profit, the pop has to borrow more and more. Maybe the company is introducing value, but most of that value is in the form of debts owned by the pop. As t->infinity the economy will increase linearly but all the value will exist as debt from the money the government pumps in, which results in hyperinflation.

How do you stop that from happening?

For economy systems I've worked on, what was described above basically boils down to this:

Computing the current value would be direct. Cost = currentCost[key] * inflationModifier.

Computing the change in value would be indirect, going through designer-tuned modification functions. The current stress on a resource may be positive or negative. Maybe it gets adjusted to be more positive when something consumes the resource, more negative when something produces the resource, and an active economy will have the value in constant flux but centered around zero stress. So you assign currentCost[key] = baseCost[key] + DesingersModifiedTuningFunctions(key, valueStress[key]).

Suppose ... if the company starts with 100 money, and spends 50 on the population as salary. The population has at most 50 to spend on the products they produced. The company can never make money. ... As t->infinity the economy will increase linearly but all the value will exist as debt from the money the government pumps in, which results in hyperinflation. How do you stop that from happening?

Part of it looks like a zero sum game. That probably doesn't apply in your case, and certainly doesn't apply in the physical world. Some things produce value, other things destroy value, you have sources and sinks.

The other part of hyperinflation is reduced with the functions described above. The beauty of a sigmoidal function is the asymptotic behavior.

When you compute the current cost of an item, say you want the current cost of wheat, you compute the base cost of wheat (for instance, 3) and you've got high demand for wheat (perhaps 253), you would look up the designer-modified tuning function. The designer's sigmoid means that no matter how high demand goes, the absolute maximum value modification for wheat is 50. The base of 3 plus the computed 48 gives a cost of 51. If the demand increases enormously, perhaps 532, running it through the function the cost only increases slightly, maybe base plus 49 or a cost of 52.

Same thing for computing the current value of inflation. The sigmoidal function can have very slow or very fast asymptotic behavior, but its beauty is that it is asymptotic. The economy can have high inflation stress and the designer-modified tuning function for the inflation modifier may change based on that. While you're in the middle of the sigmoid, maybe the economic stress is +23, running it through the function gives an inflation modifier of 1.4. Bumping the stress to +35 may give an inflation modifier of 1.7. Stress of +106 may give an inflation modifier of 2.1. Stress of 200 may give an inflation modifier of 2.4. Continuing with slow growth thanks to a sigmoid, stress of 500 may give 2.5, stress of 1000 may give 2.6, stress of 10000 may give 2.68.

Is there any literature on this? I know inflation has a psychological component and the f models that perhaps?

The psychological component doesn't really apply. It may be nice to keep in your head, but ultimately the computer is modeling based on statistics functions.

As for books, just a bunch of good understanding of stats. Every senior-level designer I've worked with, no matter how they came up through the ranks from art or engineering or QA or whatever, every single one of them had a love for statistics.

You might need to use visual tools to do it, but developing a solid understanding of how modifying one set of values can change distributions in another set of values is a vital skill in design. The concepts of tightening a spread here or losening one there, changing the shape of a distribution curve or adding some humps or a skew to one side, or using sigmoids to map throughout a range, they are critical for a designer to know.

After reading more on this issue I am beginning to see two parts to a realistic economy, and by realistic I mean an economy driven by first principles (supply/demand of commodities and money supply): which is there is a marketplace of commodities and a meta layer of money that greases the wheel in that marketplace.

I think inflation is interesting but it is not the foundation of trade. I think I need to establish a barebones marketplace first: trade occurs with real money, not nominal money subject to inflation. I'm afraid implementing both inflation and trading will mask hard to tune parameters.

This is my revised idea: everyone start with some initial amount of (real) money, they use this to exchange for good and conduct trade.


UpdateTick():
  for each nation:
    for each corp
      #compute exports
      for each commodity:
        for each foreign nation
          #determine demand or just remember demand from last tick
        #use demand to maximize profit for corp, depends on f(demand/supply), to determine production; do this every month?
        numCommodityProduced = demand (if just using demand/supply)

  for each nation:
    for each commodity:
      sum demand from all sinks: corps, population, gov, foreign bids in the form of export (taken from last tick)
      sum supply from all sources: mines, corp output, imports
      cost per item = f(demand/supply) * innate cost

I do have a question of which should come first: estimate demand or estimate supply? It's like a chicken or the egg problem. Any suggestions?

It also occurs to me that, given a turn based game, maybe don't change production every turn but every fixed period, since it may take some time to produce the product. If one unit of a commodity is made every n turns, then recompute every n turns? Or, if the corp is capable of making n units per turn, then recompute demand every turn.

Those all sound like great options, too.

For the turn based issue, I can see pros and cons to each. If you allow them to modify it mid-production you can have the cost of lost production but it limits the losses; if they cannot modify midway they are forced to pay the full cost, so errors are even more expensive. Either may be good or bad, depending on the game. The more agile the entity is the faster it can respond to change. You might even want some to be more sluggish and other extremely dynamic.

Abuse of money, e.g. (if I understand correctly) arbitrage between spending borrowed money before inflation catches up and paying it back when it has become cheap, can be cured by not relying on money.

Economy consists of the Empire making people work, processing natural resources. If you want more spaceships, assign more people to build them, within the limits of stocks of raw material. The only positive feedback is the natural one between having a big fleet and conquering the resources (workers and materials) to make it even bigger.

Omae Wa Mou Shindeiru

Hi Lorenzo, I think you make a great point. Empires function by treating population like slaves without consequence. Want more production? Get more people and they will work. No need to worry about rebellion if you dangle enough shiny in front of them with entertainment buildings and culture bonuses.

But that's not how the real world works. And I would like games to model the nuances that drives the modern world. People work for credit that they can then redeem for what they want. The price of things fluctuate based on supply and demand. Nations must trade with one another because of unequal resource distributions. There are a lot of interesting and emerging behavior from this kind of system and there aren't many games that even try to model it.

Going back to your example: if I want more space ships, I need more production. But more often than not, I just don't want my enemies to have more spaceships. So instead of building an armada of my own to counter theirs, I can undermine their ability to make more spaceships by driving up the cost of raw material for them with an embargo, an export limit, import tax, or even surgical strikes into key mining/manufacturing sites.

To that end, I'm going to drop inflation for the time being and focus on implementing supply/demand dependent pricing. It's a lot trickier than I originally thought, but it's a lot of fun nevertheless!

if I want more space ships, I need more production. But more often than not, I just don't want my enemies to have more spaceships. So instead of building an armada of my own to counter theirs, I can undermine their ability to make more spaceships by driving up the cost of raw material for them with an embargo, an export limit, import tax, or even surgical strikes into key mining/manufacturing sites.

But if you are at war with them, how can your trade with them? Each empire builds ships within the limits of the resources of their own planets and stations, possibly buying finished starships or appropriate resources from the same third parties in exchange for non-starship goods and resources.

You might say in exchange for money, but money is only a way to decouple buying and selling actually valuable goods: for example, the empire could be paid by the pacifist and neutral Galactic Merchant Union for access to its network of instantaneous travel stargates, and then buy weapons from a number of shady cash-only brokers, even if nobody exists who would accept trading weapons for stargate access.

Omae Wa Mou Shindeiru

But that's not how the real world works. And I would like games to model the nuances that drives the modern world. People work for credit that they can then redeem for what they want. The price of things fluctuate based on supply and demand. Nations must trade with one another because of unequal resource distributions. There are a lot of interesting and emerging behavior from this kind of system and there aren't many games that even try to model it.

At the empire level, getting things done doesn't mean treating workers like slaves. In a purely capitalistic system, the empire would first get money from taxes (no reason to print paper money and cause inflation) and spend it to buy e.g. starships from a self-organized industrial complex of for-profit private companies.

In the real world, war economy tends to be quite planned and constrained: frivolous use of rare resources is forbidden, resources and workers are requisitioned according to public needs, and so on.

In a 4x game, the economic detail level of "the empire builds these spaceships with these resources" represents an important game design boundary: if you want more details, for example assigning fluctuating prices to goods, you also need new major game entities besides the empires and their resources.

Do you want to make a game about corporations, colonies, planetary or regional governments, etc.and their economical incentives? If such entities are autonomous, they are natural "enemies" of the empire, to be manipulated and kept happy; if they are player-controlled, the player can only control one of them coherently, not the empire and not multiple ones. What do you have in mind?

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement