# Price of goods simulation for a shop

## Recommended Posts

Hi all, I've had a very good look around on this before asking this question as I just can't seem to find a suitable answer. Here is the problem: I want the player to be able to walk into a shop and sell a quantity of an item to the shop owner [computer]. This then changes the quantity of stock the store owner has [increasing it] thus the price of the item drops to compensate for the extra supply. If a player goes in and buys something and the shop owner hasn't received any more of it by the time he goes in next then the price should go up to compensate for the demand and hence lack of supply. Looking around I've seen loads of really complex ways of doing this by modelling artificial agents with different trading strategies etc to simulate a real market with movement of goods etc and this is massive overkill as I'm not building a market simulator. All I want though is the ability for the player to make some money if they cannily buy something from one place where supply is high and demand low and take it and sell to a place where demand is high and supply low. I can think of plenty of examples of doing this Elite being the classic one [though I think the prices there were fixed by tech level and a bit of judicious randomisation], as well as Freelancer, Star Flight, UrQuan Masters etc. There was also a nice simulation of this in all of the "Tycoon" games where if you bought or sold stock in another player the buy price would go up or down accordingly. As I say, I'm not after a complex market model just enough to inject a tiny bit of market forces into the simulation. If anyone has some general pointers I'd be extremely grateful as I've hit hair-pulling point on this now. Cheers AndrewF

##### Share on other sites
I use a variant of this:
price = (onhand / totalInWorld) * maximumPrice
That way, as the supply on hand approaches a monopoly, the price also approaches maximum.

Obviously you'd have to add some minimum price value to the system, as well as possibly capping to maximumPrice when it gets "near" to its minimum supply (e.g. for extremely rare items).

For calculating the player's sell price, you'd probably want to take this and then knock off a few bucks for margin.

The nice thing about this is that it's cleanly predictable, whereas in other more complicated systems you have a fair bit of randomness, which players hate when they're doing trading and such. If economics is not the primary focus of your game, keeping it constant is probably best. If you just want to pretend there are intelligent agents, use a random value to knock the price of an item up and down.

If you're worried about shopkeepers getting a monopoly and players not being able to buy back a unique quest-dependent object, then you could always rig up some system to redistribute the supply among other shopkeepers in the game world occasionally.

##### Share on other sites
I think this is a tricky problem to handle well. We have gone around and around trying to get decent market movement in Crown and Cutlass, but never really gotten anything we like.

Ravuya, does it really make sense to charge next to nothing if a shop-keeper has only 1 qty in his shop, but there are 100 total items in the world? Perhaps it does if the other 99 items are at the shop next door (I'm still not convinced), but what if they are on the other side of the world? In a world like Elite or Freelancer, the distance between shops shouldn't just be ignored. Even for trading within a single "town", does it really make sense that a shop with 10% of the inventory of another would be charging 1/10 of the price of the other?

What happens when you come into a town that owns 1/100 items (let's say a max price of 100, giving a price of $1), and you sell 5 items to the shop. Then the price suddenly goes to$6? That doesn't make sense to me. The supply goes up, so the price goes up? I don't think anyone would expect that to happen and it certainly goes against the basic rules of supply and demand.

Edit: Also, consider what happens with 0 qty. The shop keeper won't even give you money if you sell an item just because he happens to have none of it.

##### Share on other sites
Quote:
 Original post by Mr GrinchWhat happens when you come into a town that owns 1/100 items (let's say a max price of 100, giving a price of $1), and you sell 5 items to the shop. Then the price suddenly goes to$6? That doesn't make sense to me. The supply goes up, so the price goes up? I don't think anyone would expect that to happen and it certainly goes against the basic rules of supply and demand.

While the formula needs some work it does make sense in the supply & demand sense. The more of a particular item a shop has, the less supply there is for that item in the rest world. If a shop has 95% of the total quantity of an item, they can pretty much dictate the price since they are practically the only place to get it.

##### Share on other sites
tstrimp, the model doesn't make sense if you look at what psychictreason asked for. He wants to be able to buy low where there is lots of supply, and sell high where there is little supply. This equation has provided him with the opposite. If a player buys from a shop with little supply, it will cost very little. He will then go to a shop with lots of supply and sell for a large profit. It will tend towards monopoly, which won't make for much fun.

##### Share on other sites
Quote:
 Original post by tstrimpWhile the formula needs some work it does make sense in the supply & demand sense. The more of a particular item a shop has, the less supply there is for that item in the rest world. If a shop has 95% of the total quantity of an item, they can pretty much dictate the price since they are practically the only place to get it.
I don't think it does. There is no concept of demand in this model. It doesn't matter if you own 100% of a given commodity (I assume we are talking about commodities, not like semi-unique RPG items where the total number in existence is 3 or something) if there is no market for it. One idea we had in Crown and Cutlass was the assume a constant demand slope (the "elasticity of demand" if I remember my econ) for goods based on how "critical" they are. That is, a low supply of rum won't change it's price much since people won't buy it if the price goes too high. However, grain prices may go up much higher in a shortage because people need it to survive. I guess you could argue that pirates need rum to survive, but you get the idea...

As you can see, we always end up making it way too complicated. I think something along the lines of "at 0-10% of the total amount, calculate the price based on scarcity. At 85-100% of the total, calculate the price based on a monopoly. The rest of the time, do some random movements to keep it interesting" could work. Maybe that isn't enough. My problem with that is that you can't set up a "trade route" and consistently make money. Like I said, we could never get a good system worked out...

psychictreason, what are you looking for? Are you looking for some semi-believable market movement just to keep the game moving, or a more realistic supply-demand system where the player can focus on dependable "economics" that are at least consistent within your world?

##### Share on other sites
Quote:
 Original post by Mr GrinchI think something along the lines of "at 0-10% of the total amount, calculate the price based on scarcity. At 85-100% of the total, calculate the price based on a monopoly. The rest of the time, do some random movements to keep it interesting" could work. Maybe that isn't enough. My problem with that is that you can't set up a "trade route" and consistently make money. Like I said, we could never get a good system worked out...

I like this method.

##### Share on other sites
Quote:
 Original post by tstrimpWhile the formula needs some work it does make sense in the supply & demand sense. The more of a particular item a shop has, the less supply there is for that item in the rest world. If a shop has 95% of the total quantity of an item, they can pretty much dictate the price since they are practically the only place to get it.

If your talking about a price rising only a little then yes it does make sense.
Say a NPC only had 5 of the item.
He could charge say 20 coins for it, if someone sells him 20 of them he might charge 15 coins for it, if he has 95% of the quantity in the economy he might charge 25 coins or even 30 coins.

That would work in supply/demand.

Not:
NPC 5 items 20 coins
NPC 25 items 15 coins
NPC 95 items 100 coins

##### Share on other sites
Well what I would do if I were tasked with making such a system would be to:

A) Keep track of Unique/Rare items and use the stats of the item to determine the price.

B) If the item is not rare and it is produced then it would fall under regular supply and demand laws. If it is food you could factor in the current season (is that crop in season or not? has there been a drought recently? ect). If it is an imported good (you could keep track of this) from another land then it would cost more (perhaps just an import tax).

Then you could keep track of close shops and add some competition factors as well, based on which shop is making more money.

If we get a lot of an item then we focus on if we are the only shop with a lot of the item. If we are then we can charge heavily, otherwise we have to drop the price to move the product depending on the demand.

Then the only real factors that you have to vary from time to time is the distribution of the items in the shops and if it is single player then the demand for the items as well.

We could base the current level of "random" demand based on the season (obviously a glass of lemonade is more in demand in the summer then in the winter) and the occassion (If it is a special event then some items become higher in demand or during a major war close by there will be a higher demand for weapons).

##### Share on other sites
Hi Chaps,

I've had a quick skim of this getting up this morning and there are some great ideas in here without it going too complex which isn't the aim.

I'll have to have a proper read through a bit later after the chores are all done, however one thing that can be discounted is things like rare items.

Trade in this sense is much more along the old elite style of there being only commodities that can be traded. Some will be inherently cheaper than others due to their production cost - a piece of wood would be inherently cheaper than a chair by design as well as that wood will be more available than a chair.

Really what I'm looking for is a general simulation whereby the prices go up and down in a relatively predictable manner so the player can have some semi certainty they'll make a profit by taking goods like wood which is plentiful near a forest to a place like a desert where it isn't.

What I don't want though is a completely realistic market environment where full levels of supply and demand curves have to be modelled and then have artificial agents running in the background producing and buying goods in order to generate a market environment.

To give you more of an idea, this is a single player game for kids of about 11 years old and the bits of trading are only one part - the other main bit being one of exploration of the environment.

Cheers
AndrewF

##### Share on other sites
Hi all,

Finally I've managed to get back to this after that destroyer of plans, "life", came into play for the last few days.

Right, I've had time to digest all the *very* good responses - thanks a lot for this guys.

I think in order to keep it simple I might need to assume that each "market" is essentially stand alone and then peg certain products according to some level of cheap supply. So for example buying grain in the market situated in the middle of the agricultural belt would be cheap as it would be plentiful first and because of it's "zone" it would be generally a cheaper commodity than maybe something like steel which would be in mountains and would be cheaper there.

I don't really need ultra realistic market places in this, just a general addition to the flavour of the rest of the game.

So my next set of questions then are related to this:

Assuming that for each market that we have some banding on rough prices. Take the example above. In the agricultural town [call it A]:

Grain rough cost is around 1credit - 1000 units in stock
Steel rough cost is around 10 credit - 5 units in stock
Sheep rough cost is around 5 credit - 200 units in stock

Town B [the steel mill / mine] has:

Grain rough cost is around 3 credits - 10 units in stock
Steel rough cost is around 6 credits - 150 units in stock
Sheep rough cost is around 7 credits - 30 units in stock

Obviously these prices are arbitrary but lets assume I use some sort of banding algorithm to set the start price in a particular market.

Now if I buy 100 units of grain and 5 sheep from Town A, what happens to the prices there after I've decreased the amount of stock? Presumably go up slightly - but by how much and how do I mathematically calculate it.

Then when I go to sell the grain and sheep to Town B, what happens to the price of the commodities after I sell it? Again it should go down slightly but by how much?

After this I can add some slight randomness in to account for things like season etc as well...

Again any ideas would be gratefully appreciated. I feel like I am almost there from the suggestions thus far but am not quite grasping exactly what I need to do mathematically...

##### Share on other sites
Quote:
 Original post by Mr GrinchI think this is a tricky problem to handle well. We have gone around and around trying to get decent market movement in Crown and Cutlass, but never really gotten anything we like.Ravuya, does it really make sense to charge next to nothing if a shop-keeper has only 1 qty in his shop, but there are 100 total items in the world? Perhaps it does if the other 99 items are at the shop next door (I'm still not convinced), but what if they are on the other side of the world? In a world like Elite or Freelancer, the distance between shops shouldn't just be ignored. Even for trading within a single "town", does it really make sense that a shop with 10% of the inventory of another would be charging 1/10 of the price of the other?What happens when you come into a town that owns 1/100 items (let's say a max price of 100, giving a price of $1), and you sell 5 items to the shop. Then the price suddenly goes to$6? That doesn't make sense to me. The supply goes up, so the price goes up? I don't think anyone would expect that to happen and it certainly goes against the basic rules of supply and demand.Edit: Also, consider what happens with 0 qty. The shop keeper won't even give you money if you sell an item just because he happens to have none of it.

There should be a minimum price, asked and paid regardless of demand and supply: sale price= minimum price + (maximum price - minimum price) * (quantity in store / total quantity).

But monopolistic price increases involve demand, not only supply: a more realistic model should increase the price with respect to other stores if on the whole customers prefer to pay higher prices than travelling to cheaper stores.

For example, suppose there are two fletchers in villages A and B and an adventurer needs to buy n arrows. Going to either village, from wherever he is, costs Ta or Tb (lost work, inns, risk, mere unpleasantness, etc.).
Let's assume the adventurer knows the prices Pa and Pb of fletchers A and B: he'll rationally go to A if n*Pa+Ta < n*Pb+Tb and to B otherwise.

These individual decisions add up, allowing the two fletchers to optimize prices for maximum profit according to their model of how random variables Ta, Tb and n are distributed over the adventurer population.
Simple models can fix n (the purchased amount) at a reasonable uniform level depending on carrying capacity (as would be the case for arrows), amount commonly needed for one use (e.g. rations of perishable food) and other heuristic criteria.
T can be approximated by a discrete distribution containing only the travel costs from known sites of special customer concentration (e.g. dungeon entrances for adventurers) to each store and back, weighed by the customer populations of each source.

##### Share on other sites
Once idea is to have two prices for each good a minimum and maximum. Then for each commodity a store trades in give it a consumption value, and an ideal number of days stock to have. Or just an ideal stock value. Then calculate prices as max * (1-stock/ideal) to a minimum of min.

Then you can do the following.
Grain 10 – 100
TVs 70 – 500

Town A
Grain
- ideal stock = 1
- stock = 5000

TVs
- ideal = 300
- stock = 50

Prices
Grain = 100 * (1 – 5000/1) = 10
TVs = 500 * (1 – 50/300) = 417

Now if player sells 100 TVs the price would change to 250, selling 10 TVs would change to 400

##### Share on other sites
Hi Lorenzo and Techno.

Thanks loads for these additional ideas - this has really pushed things on for me massively. I was really getting bogged down in trying to model supply and demand curves and it was starting to get a bit complex.

I think a combination of these two ideas will work really well as techno's lets me model a particular market and using Lorenzo's idea I can create individual differences so I think the combination of these things will work well.

I'm off now to create a little model and see how it works in practive with several commodities and differences in locations.

Again thanks to everyone for your help on this - much appreciated.

Cheers
Andrew