I'm trying to make a market for a multiplayer game where players can buy and sell resources to a global market. Ideally the market would react to player trades and respond accordingly (i.e. everyone buying large amounts of a certain resource will drive up the price). Some element of randomness would be ideal though.
This seems like something that should be pretty easy, but getting a result that feels right has proven more difficult than I thought. Read over a lot of stuff so far including:
Currently I have it so that a resource has a hidden base price and random numbers that are weighted towards returning to this price are added to this number as well as a modifier for the net sell/buy volume that players have traded.
I'm currently determining the price change each turn with something like below, where x is related to the distance from the hidden base price. This seems OK, but still feels a little off. http://stackoverflow.com/questions/4420 ... low-values
I have a feeling there is a somewhat simple equation I am missing that would help greatly. Or maybe there is just a totally better way to go about doing this. Any thoughts?
Consider using a simple supply/demand model. For each resource, store how much of it available because people are selling to the market, and store how much of it is wanted because of people buying from the market. Set a base price for each item, and then modify this price based on demand vs supply. For example; if demand is twice as high as supply, the base price is doubled, while if supply is twice as high as demand, the base price is halved.
In order to introduce randomness, add a random amount to both supply and demand each turn. To make the market self-balancing, base the random amount on previous values; ie if in the previous round(s) the demand for something was much higher than its supply, then a larger amount is added to the supply to simulate new companies starting up to sell the currently expensive product, while if the supply is higher than the demand you can add more the demand as new companies start up to make use the currently cheap product.
It'll still be fairly simplistic but should at least look a little bit like a real market.
(I'm not sure how important the market is to your game; if it's a major part then this might be still too simplistic, but if it's sort of a tack-on (like for example it is in Age of Empires games) then this should work just fine.)
(Although this might also be fairly close to what you're planning already)
+1 Plu, I'm taking economics and what Plu said is the basic of a Perfect Competition market and that's the best course of action for a market simulation, this graphs will help you out.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping