Sub topic 2
Balancing Inflow and Outflow
A currency's stock is the amount players hold. Flows are the amounts that enter (sources) and leave (sinks) each day. This chapter assumes you know what sources and sinks are and can read simple Python.
Balancing inflow and outflow
When inflow equals outflow, the stock stays flat. When inflow is larger, the stock grows. A fixed income combined with a percentage sink settles at a steady level. The code below models a sink that removes 10% of the balance each day.
def simulate(days, income_per_day, sink_rate, start=0.0):
balance = start
history = []
for _ in range(days):
balance += income_per_day
balance -= balance * sink_rate
history.append(round(balance, 2))
return history
print(simulate(60, 100, 0.10)[-1]) # about 898; the balance approaches 900Inflation and deflation
Inflation happens when the balance grows faster than players can spend it, so prices lose meaning. Deflation happens when currency is scarce, so players hoard it and stop buying. The steady-state balance is income × (1 − rate) / rate. With an income of 100 and a sink rate of 0.10, the balance settles at 900. Halving the sink rate to 0.05 doubles the balance to 1900. A large jump like that signals inflation.
Setting prices and rewards from target pacing
Choose how many hours a player should work to afford an item, then price the item from the measured income rate.
def price_for_target(hours, income_per_hour):
return round(hours * income_per_hour)
print(price_for_target(3, 450)) # 1350Soft and hard currencies
Soft currency is earned in play and is plentiful. Hard currency is bought with real money and is scarce. Keep the two separate so that paid purchases do not undermine earned progress.
| Currency type | How obtained | Typical role |
|---|---|---|
| Soft | Earned in play | Routine upgrades and repairs |
| Hard | Purchased with money | Speed-ups and premium items |
Exercise
A game adds 200 gold per day, and a sink removes 20% of the balance each day. What is the steady-state balance?
Show answer
200 × 0.8 / 0.2 = 800 gold.