Economy Simulation

Made by: Mats de Jong
Student Number: 500827411

Table of Contents

  • Introduction
  • Creating a Galaxy
  • Creating an Simple Space Empire AI
  • Research into Economy
  • Making the Economy Simulation
  • Implementation in Games
  • Real world Economic problems
  • Evaluation


During the weeks in which I worked on this project my goal changed a bit after the first few feedback sessions. My original idea at the start of this project was to make some sort of Space Empire AI so in the first week I researched how to make a simple galaxy. In the second week I started to make a simple starter AI which could build things to manage its resources. But after the feedback of week three my learning goal changed quite a bit to more of an Economy simulation which helped a lot to give my project more direction and focus. With this I eventually did some simulations from which I got results like this:

I further explain this in the Making the Economy Simulation chapter which is the main result of my research and development.

Creating a Galaxy

When creating a galaxy there are a few things to think about like what kind of shape is it going to have and the realism at which it was going to move around.

The different shapes that galaxies can have are (HubbleSite, n.d.):

  • Eliptical
  • Spiral
  • Irregular

I also thought about how the AI empire was going to fit into this and to decide on these things I took a lot of inspiration from the way they made galaxies in Stellaris.

In Stellaris the different stars are connected by hyperlanes to make traveling between them fast. The alternative would be a freer movement where you can simply move to any star by going straight towards it but it might take longer. Deciding between these two or maybe even other options to connect the stars would be important to decide how the AI is going to use them.

I first looked at a video from Sebastian Lague in which he simulates a singular galaxy with realistic physics.

While it seems interesting to make this a close to realistic simulation its not a very big priority to make the galaxy this advanced. It also did not give an example of how to actually generate a galaxy and for that I found this next tutorial series.

This tutorial series was much like the other video a bit more complex than I needed so after watching these videos I decided to go with a simple grid with random offsets to make it look a little bit like the galaxies in stellaris.

Creating a Simple Space Empire AI

When making a Space Empire AI I first decide on which resources it is going to manage and with which buildings it’s going to do that. I decided that the first resources would be Energy, Minerals and Credits. It will be able to get more Energy with solar panels which cost minerals and credits to build, and it gets more minerals with mineral mines which cost energy upkeep. It could then make trade centers to get more Credits which costs a lot of minerals to build and energy upkeep.

It then needs a goal outside of keeping its economy balanced. For this I decided on three main goals: Economy, Military and Technology. During Economy Goal it would build the buildings I have described before. When it has a military goals it would try to build ships which costs minerals to make and energy upkeep. And when it has technology as a goal it would improve the efficiency of things.

I also looked into using this behaviour tree package to make the AI with. This package was suggested to me by Thomas and is made and designed to be used by everyone(Opsive, n.d.).

And looked at an article about behaviour trees to learn of their potential. While I didn’t end up using it could still be interresting too revisit at future research(C. Simpson,18 July 2014).

After looking into using the package I found it quite time consuming to make new variables and manage global ones between the different behaviour trees, so I decided to go with making it in standard C# instead to make sure I had something to show within a week. If I then run into problems I could try to recreate the AI I made in the behaviour tree.

Now I need to think an effective way for the AI to make decisions. It needs to keep track of its resources and make buildings for that resource if it reaches a certain threshold. It also needs a goal with a deadline. For example, if you want to make a large army in a strategy game you usually want to produce resource for as long as possible and than make an army at the last moment.

And also, usually you don’t have only one goal at a time, because while you are preparing to build an army you might want to continue to advance your technology as well.

After looking for making a strategy game AI I found and Article by Ed Welch(E. Welch, 27 July 2007).

Using this article as an Example I started to make the different goals and give them weights. I also made the different buildings and define the amount the AI started with. It also has one thousand of each resource to start with. I didn’t make a good visual for this in the end so here is how it looked in the Inspector instead.

There is one thing you can not see very well here and that is that each goal has an added weight to increase its priority if that is neccesairy. For this I made an Enum for each different one:

public enum GoalWeightChangers
    LowResources, // Increase Economy Priority
    NearingDeficite, // Additional Economy Priority
    PreparingWar, // Increase Economy Priority
    War //Increase Military priority

You can also see the variables called Planning Time and Resource Buffer. Planning time determines how far it looks ahead and if it sees its about to reach a deficit within that time it would increase the priority of Economy. Resource buffer does a similar thing, and it increases Economy priority if a resource drops below that value.

After a while this is what it looked like in the inspector.

It made a lot of solar panels and Trade Centers to balance its economy and it switched to a Military goal quite often because of the high base weight of Military. Technology currently does nothing which is why it has a base weight of 1 for now.

Something I did to make sure I could easily make more buildings later is to make them Scriptable objects here is the Mineral Mine building:

Research into Economy

After more Feedback I made my goal more specific and I decided to increase my focus on Economy Simulation in the end.

Eve online is also an interresting example which I got quite a bit of inspiration from some videos that where made by this guy:

To get started with trying to figure out how I make AI empires have simulated Economies I looked around to see what an Economy is made of. This first page I found had a decent explanation(FutureLearn, 8 August 2013).

“An economy consists of consumers who buy products and services, businesses who employ consumers and make goods, and the government at various level who both buy products, employ labor and levy taxes. Their collective interactions create a simplified economy.”

So what I made before already kind of fits the definition although it’s not nearly as complex. To see how people then use Economy in games I looked at an interesting video from Game Maker’s Toolkit.

Now I look around to see if this has been done before and I find this video which shows how I could make a simple economy with supply and demand.

This looks like a good place to start but before I start, I still want to make sure that this is the most basic part of an economy so I look up “Economy Basics”.

“Four key economic concepts—scarcity, supply and demand, costs and benefits, and incentives—can help explain many decisions that humans make.”(Beattie, A. , 2011, April 6)

This is very similar to the quote I found earlier so this should be a good place to start.

So first I want to define a simple consumer which has a demand for Food and a supply of Workforce. It can turn that workforce into money and buy food. For this I also need some way to keep track of markets and the different values at which they want to sell their food.

Making the Economy Simulation

I will do something similar to how it’s done in the video and every component I will call an actor. This actor always produces something like food and workforce and needs food or workforce. Each Actor will use money to buy the things it needs and sell the things it produces. If it doesn’t sell all the things it produced it will lower the price and if it did sell everything it will increase the price. These prices have a minimum for the person who sells and a maximum for the person who buys. In the video he gives the buyer a maximum value its willing to buy it for and the seller has a minimum value it’s willing to sell it for.

In the video this remains simple but the way I’m going to make it the value he used in the video needs to be flexible and be determined by how much it costs to make the product and by how much money the buyer is making.

In my first version I made two Actors a Human who needs food and produces Workforce and a Farm who needs Workforce and produces food.

When making the Actors the essentially have three stages within each cycle:

  • Production
  • Fulfilling Needs
  • Checking Values

Its important that it does these in this order because otherwise some Actors might produce first and try to fulfill their needs even though no one else has made anything so they can’t fulfill their needs. They then update their expected values for each item they produce depending on if they sold everything or not.

I also made sure that the order in which the different markets and actors updated mattered as little as possible by shuffling them around. Here you can see the Update function that is inside of the MarketManager:

void Update()
    delay -= Time.deltaTime;
    if (delay <= 0 && updateCount > 0)
        delay = updateDelay;
        foreach (Market market in markets)
        foreach (Market market in markets) market.BuyNeeds(traderLessMarketConnections);
        foreach (Market market in markets) market.Check();
        if (continuouslyUpdateHistoryVisual || (!continuouslyUpdateHistoryVisual && updateCount == 0))            

The amount the produced was greater than the amount that they needed which caused the value of both things to go down. I then made a visual for this in unity to show the value of the resources.

If I create a market in which everything is in perfect balance, the values go like this:

The value of things go down when there is still some resource in storage meaning some of the farms didn’t fulfil their needs. This goes correctly the first 3 rounds because the initial expected value for workforce is 1 for the Humans and 2 for the farm causing them to find the price acceptable until cycle 4. You can see that the values go down slightly still and that is because I use x0.9 to lower the value and x1.1 to raise it which causes it to go down slightly. I fixed this in the next scenario.

Then ones the Humans have increased the value of workforce too much and farms have decreased the value of workforce to much it reaches the back and forth you see above where in round 4 they were unwilling to buy workforce causing the price to decrease and in round 5 it has reached an acceptable price again.

Now I want to show what happens when there is a slight shortage in the next example there are slightly more Human Actors than Farm Actors. This means there is a surplus of workforce and a shortage of food.

Because of the surplus of workforce the value goes down until the workers run out of money which causes them to be unable to afford the food which means they can’t produce workforce. This also means that the farms can’t sell their goods which causes the value to drop until the workers can afford it again.

I separated Humans and Farms by market to show their total wealth. Separating by market currently has no effect other than allowing me to show the total difference more easily.

Market1 has all the workforce
Market2 has all the Farms

Up to this point I had not actually added the minimum and maximum price the Actors are willing to sell or buy it for. And when I thought about it the only necessary one of those two is a maximum price its willing to buy things for, because if I also add a minimum price for selling it will cause them to be unwilling to take much of a loss and will be inactive instead. This is important if we want to simulate inflation.

Next, I tried to add multiple markets since that seemed easy enough, but its actually more complex than I originally thought. There are a few ways I can make connected markets interesting.

The first thing I thought of was a trader actor which needs workforce (and maybe fuel) to move goods around. This means that the way I have made current Actors does not work anymore, because what he produces depends on the value of goods between different markets.

The second thing would be Taxes. This would be decently easy to make but it would create a money sink without having anything that puts money back into the system. So, for this I would have to code some sort of government entity which inputs that money back into the system somehow.

These two options are not mutually exclusive and could be interesting enough to have both.

But first I want to make the trader.

I made made the decision that the trader is not all knowing and will simply grab the first resource that he could sell for a profit. He also only looks in one market every cycle and if he made a succesfull trade last cycle he will continue to trade there.

I received some feedback that suggested I add some player interaction and my most basic Idea with that would be a simpel menu.

It shows the name of the actor the thing they are selling and then the amount they want to sell it for.

You can then buy and sell something. In the above picture I had just bought workforce from the abundance market and I now sell it for a higher prive in the worker shortage market.

Next I started to work on adding efficiency needs which would increase the actors production output.

As you can see in the picture above I added the efficiency need for energy in the human actor. I also added a need for energy in the farm and in the Mine. The mine is a new actor which produces resources that the Generator needs. The generator then produces energy for the other actors. This already increases the complexity/realism in the economy quite a bit.

I then found that it is still a problem in economies with shortages that al of the money would flow into the actors that were producing the high demand item. This would cause the value of things to go down a lot as shown in an ealrier food shortage example. To solve this I added generosity. Generosity is a percentage of their wealth an actor is willing to spend extra. This means if a resource is worth less than this percentage of its total wealth it would pay extra.

In this next example I set the generosity of every actor to 10% and I look at the total wealth of generators which are the only shortage in this market.

Without generosity the generators would keep as much money as possible causing prices to the minimum of 0.01. The wealth of generators looks like this then.

With generosity there is also the possibility of inflation that didn’t exist before. Because now people will spend more if they have a lot of money which means that when there is a lot of money products will cost more money and the value of money decreases.

Value of energy when there is a lot of money
Value of energy with less money

There are a few more things I could add to make the economy more realistic:

  • Actors that make more actors when possible to create economy growth.
  • Luxury Needs.
  • A goverment Actor that gets taxes and makes sure the economy runs well.

A higher willingness to spend more? I also want to them too keep track of how long they haven’t had their base needs to determine how much extra they are willing to pay.

Application of this within games

There are a few ways to apply this realistic economy simulation in games. For example you could make a game where the player is some kind of merchant and moves resources between different markets to make a profit, but unlike in simpler economy simulations if you create a large influx of one type of resource it’s going to have some effect on the local economy and if you do that continuously a large part of the economy could become depended on your goods ones you have outpriced all the competition in that local market you could raise prices for example. With this economy simulation method there are a lot of ways you can make interactions with each economy interesting.

Real-World Economic Problems

A more recent relevant economic problem is inflation. This currently doesn’t happen in the way it usually happens in real live as adding extra money to the system does increase prices but not in the same complex way it happens in real life also inflation doesn’t effect the economy of the simulation as much as it does in real life. Another reason that inflation can’t be simulated in the current system is that all the goods in circulation are base needs which means they always want to have it in the same amount and they don’t suddenly start buying more of it when they have more money(J. Fernando, 20 November 2003).

Similar to inflation, deflation doesn’t currently happen in the way it normally does in the real world. Although the money in the simulation often becomes more valuable over time as prices of goods decrease it doesn’t have much effect as the actors does not intentionally save money to spend it more efficiently later as currently there are only base needs. so to get closer to simulating inflation we need more types of needs like the secondary and luxury I mentioned before(The Investopedia Team, 25 November 2003).

In the video I used as an example for how to simulate an economy He also talks about a price equilibrium. While this currently happens it is not too interesting because there is a low variety of actors and they don’t have much of a choise if they want to produce something.

Another interresting which could be interresting for the economy simulation later down the line are natural disasters that disrupt the production of certain goods.


It’s hard to even approach the true complexity of a real-world economy but with this research I think I have come quite a bit closer and my understanding of the economy has increased.

Though because there where few examples, had to make everything myself.

(Small evaluation of the name Actor: Later I realized that Agent might be a better name but it was to late to change it)


Beattie, A. (2011, April 6). Four economic concepts consumers need to know. Investopedia.

Brown, M. (2022, April 25). How video game economies are designed [Video]. YouTube.

Economics Explained. (2019, August 8). The economy of EVE online [Video]. YouTube.

Economics Explained. (2019, August 15). The economy of EVE online (Part 2): The robot problem [Video]. YouTube.

Economics Explained. (2019, August 29). The economy of EVE online (Part 3): Mega projects [Video]. YouTube.

Fernando, J. (2003, November 20). Inflation: What it is, how it can be controlled, and extreme examples. Investopedia.

FutureLearn. (2013, August 8). What is an economy?

Galaxies. (n.d.).

The Investopedia Team. (2003, November 25). Deflation. Investopedia.

Lague, S. (2020, April 17). Coding Adventure: Solar System [Video]. YouTube.

Opsive. (n.d.). Behavior Designer.

Primer. (2019, April 27). Simulating supply and demand [Video]. YouTube.

Quill18creates. (2016, October 5). Unity Tutorial: A Procedurally-Generated Galaxy – Part 1 [Video]. YouTube.

Simpson, C. (2014, July 18). Behavior trees for AI: How they work. Game Developer.

Welch, E. (2007, July 27). Designing AI algorithms for turn-based strategy games. Game Developer.






Leave a Reply

Your email address will not be published. Required fields are marked *