Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: C# library for game economy?  (Read 5959 times)

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
C# library for game economy?
« on: May 07, 2011, 01:15:22 pm »

So, as a business minded person learning C# and planning to create a business simulation game, last night I spent quite some time trying to figure out how I would implement a realistic supply-demand model of economy in the context of my game. Then it occurred to me that other people must have tried the same before me and I might be trying to reinvent the wheel. And then I wondered whether it could be possible to code a class library that encapsulates the broad principles of such an economic system, and that can be used by a number of different games related to business simulation or general strategy (Victoria forum discussions on economy overhaul come to mind).

Question 1: Do you think it could be done?
Question 2: Is it already done?
Question 3: If Q1=true & Q2=false, then would anyone like to help me try?
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: C# library for game economy?
« Reply #1 on: May 07, 2011, 01:19:17 pm »

A1: I'm not savvy about economics (>_>) but I don't see why not
A2: A quick Google search revealed nothing of the sort. So if it exists, it's probably not well known.
A3: How exactly help ya?
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: C# library for game economy?
« Reply #2 on: May 07, 2011, 01:29:22 pm »

A1: Definitely.
A2: Nothing well-known.
A3: Not proficient in C#, but I might be up for it. I'm reasonably good at C++, and if I remember correctly the languages are pretty similar.
Logged

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
Re: C# library for game economy?
« Reply #3 on: May 07, 2011, 01:42:25 pm »

A3: How exactly help ya?

As in help me with the design of its mathematical foundation first of all, and then the coding. Regarding the foundation, in my experience there are many different ideas on how to do it, how far to go, and what compromises to make for the sake of simplification. I could try and do it myself but I think I would be missing out on valuable ideas by other people. So I imagine this could start with a discussion on the scope and the definition of a good economic simulation.
Logged

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
Re: C# library for game economy?
« Reply #4 on: May 07, 2011, 02:28:51 pm »

I'll start the discussion with what I've got so far:
Obviously there are some key parameters in any economic system relating to supply and demand.

The overall market size for any goods or service can be simplified as such: Market Size = Df x Pop where Pop is the population, and Df is the percentage of the population actively in need of the product in question. In the context of a game, the market size can be changed by changes in the population of the region that the market represents. It can also be changed by changes to the value of Df  - i.e. if there is a disease outbreak, Df for a certain medicine will increase. Similar game events could modify this parameter.

Demand and Price: Demand is not a static figure and is not to be confused with market size. It represents the number of people willing to purchase a good at a price P. A simple mathematical expression of Price in terms of Demand is: P = aD + b, where a < 0 so that when the price increases, demand falls.

Supply and Price: The total output of manufacturers in the game can be represented by the Supply parameter. P = cS + d, where c > 0 so that when the price increases, supply also increases.

Demand and Market Size: Market Size could be thought of as the maximum value of Demand, kinda like assuming everyone who needs something are able to afford it - which happens at a price of $0. 

Equilibrium Price: Happens where the Supply and Demand curves cross.

These cover the basics of the model I've got so far.
« Last Edit: May 07, 2011, 05:11:12 pm by Chandos »
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: C# library for game economy?
« Reply #5 on: May 07, 2011, 02:30:07 pm »

Hmm, somewhere in there should also be banks and interest and stuff.
Logged

Reelyanoob

  • Bay Watcher
    • View Profile
Re: C# library for game economy?
« Reply #6 on: May 07, 2011, 05:54:12 pm »

Best business game ever : Capitalism II. Look at the Industry guide here, maybe read the faq too.

It's the DF of business games. Shame they never made Cap III

Combine with ideas from Transport Tycoon and you'd have the most killer business game ever.


EDIT: The main issue I'd have with the maths you present is not their "correctness" but how will this become a game / integrate with a game. Better to create the framework for the market, define products and processes much like Toady does in the raws, and have distinct AIs to trade, set prices, compete etc.

You need Genetic Algorithms and/or Neural networks to tune the AI's through tournaments, it's a lot easier than manually trying to balance stuff that will get broken if you change any of the simulation's rules (i.e raw editing)
« Last Edit: May 07, 2011, 06:10:23 pm by Reelyanoob »
Logged

mainiac

  • Bay Watcher
  • Na vazeal kwah-kai
    • View Profile
Re: C# library for game economy?
« Reply #7 on: May 07, 2011, 06:27:07 pm »

I think every economic simulation is going to be so different though that you couldn't achieve much in the way of serious time savings from a library.  The assumptions behind every model will be different and the actors are going to be different so it's all going to be different.  Maybe I'm not just visualizing what you are visualizing?  I'm thinking of something like the game Vicky 2 and failing to see how a library of terms based on that would apply to another game which isn't going to have most of the same variables.
Logged
Ancient Babylonian god of RAEG
--------------
[CAN_INTERNET]
[PREFSTRING:google]
"Don't tell me what you value. Show me your budget and I will tell you what you value"
« Last Edit: February 10, 1988, 03:27:23 pm by UR MOM »
mainiac is always a little sarcastic, at least.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: C# library for game economy?
« Reply #8 on: May 07, 2011, 06:31:11 pm »

Not that I know of, no. Something like the economy is part of what we call the 'Model', and people don't often make libraries for the model because
1. It rarely carries over to a unrelated project.
2. It is often one of the easier bits to program. Unlike view and services.

Really, you should be able to build your own working economic model. Although good to see that your looking to cut work through use of libraries.

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
Re: C# library for game economy?
« Reply #9 on: May 07, 2011, 06:57:16 pm »

You might be right about different games needing different models, but part of me suspects that's because The Model in any case is a broad approximation that game designers come up with, and the goal is rarely modeling a real economy, just something that works reasonably close enough.

The assumptions behind every model will be different and the actors are going to be different so it's all going to be different...


That's the thing I'm curious about: whether the assumptions could be expressed in variable form, so that they can be changed quantitatively.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: C# library for game economy?
« Reply #10 on: May 07, 2011, 07:02:07 pm »

That's the thing I'm curious about: whether the assumptions could be expressed in variable form, so that they can be changed quantitatively.

Yes, in fact this has been done, and I think you might have access to it. It is called c#, you tell it what classes, fields, functions, enums, delegates and everything else you need, and it figure out how to make it into a form the computer can use. Really useful that.

mainiac

  • Bay Watcher
  • Na vazeal kwah-kai
    • View Profile
Re: C# library for game economy?
« Reply #11 on: May 07, 2011, 07:44:43 pm »

I feel my initial assessment was too negative upon further reflection.  In particular the areas of interest rates and exchange rates seem to me to be things that belong libraries.  Not coincidentally, they are things that are nearly always absent from games and presented as black boxes when they are included.

The financial side of economies are usually missing from most simulations.  Production we can intuitively understand or at least fudge.  Finances not so much.
Logged
Ancient Babylonian god of RAEG
--------------
[CAN_INTERNET]
[PREFSTRING:google]
"Don't tell me what you value. Show me your budget and I will tell you what you value"
« Last Edit: February 10, 1988, 03:27:23 pm by UR MOM »
mainiac is always a little sarcastic, at least.

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
Re: C# library for game economy?
« Reply #12 on: May 07, 2011, 07:58:34 pm »

That's the thing I'm curious about: whether the assumptions could be expressed in variable form, so that they can be changed quantitatively.

Yes, in fact this has been done, and I think you might have access to it. It is called c#, you tell it what classes, fields, functions, enums, delegates and everything else you need, and it figure out how to make it into a form the computer can use. Really useful that.

Max, thanks for your input. Really helpful.
Logged

Chandos

  • Bay Watcher
  • bork bork bork!
    • View Profile
Re: C# library for game economy?
« Reply #13 on: May 07, 2011, 10:30:47 pm »

I feel my initial assessment was too negative upon further reflection.  In particular the areas of interest rates and exchange rates seem to me to be things that belong libraries.  Not coincidentally, they are things that are nearly always absent from games and presented as black boxes when they are included.

The financial side of economies are usually missing from most simulations.  Production we can intuitively understand or at least fudge.  Finances not so much.

You can't really have a financial system in a vacuum. Inflation, interest rates and money supply are all things deeply related to production. An incomplete implementation of the supply and demand could be the reason for the black box model of the financial aspects.

When you think of what money actually is, you find that it is a proxy for value of resources collected, goods produced and services rendered. For instance, agriculture produces food, and that food is adding a certain value to the overall economy. When one eats the food, the value is consumed and needs to be replaced. When the consumption outstrips the production, you have a shortage of resources in the system. Money supply being the same, that means the same amount of money can now purchase less resources (too much money chasing too little goods) which is known as inflation. Or if the resources are the same but the money supply is increasing (printing money, gold mine, etc), then you have the same situation again.

The inflation rate dictates how much value your money will lose if it stays the same amount. If a corporation or individual is not growing their money at a rate equal to or greater than the inflation rate, they are essentially losing money. So let's say the inflation rate is 5% annual, and I as an entrepreneur come to your bank, asking for a loan of $100 at 4% interest rate. If you gave me that loan and I repaid you $104 after a year, the real value of that money in today's terms would be $98.80 and you would have made a net loss. Similarly, the entrepreneurs compare the pay-offs of their investments to the inflation rate and the interest rates to decide whether an investment (in opening a new factory, or mining operation, or trade post, etc) is worthwhile.

As you can see, the inflation rate and the interest rate are things only meaningful when they have the supply-demand system as a reference point. 96% inflation is not necessarily too high, if the average business venture can easily turn 500% return on investment. Whether it can have that kind of return or not is deeply rooted in the supply-demand dynamics of the market. Similarly, a business venture that gives a 10% return on initial investment is not necessarily a good one, if one could have 20% interest on their money risk-free in a bank's vault. Low demand for goods in the market would mean fewer enterprises and less return on investment, which would cause more people favoring to put their money in the bank, which would mean shrinking cash supply, which would mean deflation, which would mean dropping interest rates. Conversely, booming demand would mean more demand for cash (for purchasing the goods demanded, or for producing the goods), more people taking their money out of the bank and putting into a business, which would mean inflation and rising interest rates.

Does that make sense now that I'm thinking of the whole and not just the financial side? The production side, I believe, is the foundation of any economy.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: C# library for game economy?
« Reply #14 on: May 07, 2011, 10:42:11 pm »

You might be making it more complex then it needs to be. While in all reality the value of money is derived from goods and services, in a logical system it works the same if you make the value of goods derive from money.
You should have rival entities trying to outbid each other for the cost of something, and when entities start finding themselves unsustainable at a certain price, they drop out, and the item value evens out, while remaining sensitive to changes in the market. You don't need to mess with the value of the currency, just use that as your frame of reference for everything else. Although computers can do these calculations very quickly, so you might find your game making companies that run at 100% effectiveness, and you can not compete.

But still, I think it might be best if you learn a little about delegation of responsibly, that way you can build a nice simple model, and if you want it more advanced, it is easy to upgrade with little effort.

Start small with these games, and build up. You can't go making simcity as your first game.