26
\$\begingroup\$

There are formulas out there for a diminishing return equation; however, those usually involve exponential. What other ways are there for coming up with such an equation? Take, for example, the following test case -- One farm produces 10 food, for every 10 farms produced, the production rate drops by 5%.

\$\endgroup\$
  • 1
    \$\begingroup\$ It might help if you told us why you want to avoid exponentials. In particular, are expressions of the form x^y (x raised to the y-th power) out too (since computers usually calculate those using exponentials, at least for non-integer y)? \$\endgroup\$ – Ilmari Karonen Dec 15 '14 at 16:41
  • 7
    \$\begingroup\$ "For every ten farms produced, the production rate drops by 5%." That's, uh, essentially exponential: y = 0.9^(floor(x / 10)). Like @IlmariKaronen asks, what's wrong with the exponential? \$\endgroup\$ – wchargin Dec 15 '14 at 20:44
  • \$\begingroup\$ 1. Hard to explain to the non-developers (and some developers have issues with exponential) 2. I am under the impression that it is expensive \$\endgroup\$ – Extrakun Dec 17 '14 at 10:37
  • 2
    \$\begingroup\$ there's absolutely nothing inefficient about using exponential equations. I think that what you're thinking of is algorithms in which the number of steps increases exponentially compared to the size of the input (eg the size of an array which you want to sort). This is referred to as "O", eg you might say that a particular algorithm (or function) takes O(n) steps to run. An algorithm in which the steps increase exponentially might be described as taking O(n squared) steps for example. This is totally different to having a single equation which has an exponential term in it. \$\endgroup\$ – Max Williams Dec 17 '14 at 11:14
  • 1
    \$\begingroup\$ I think Extrakun might be thinking of this kind of "expensive:" stackoverflow.com/questions/2940367/…. To reiterate what everyone else is saying: it's not expensive. If you are uncomfortable with exponentials, search for accessible explanations of them (maybe betterexplained.com/articles/…), don't avoid them. \$\endgroup\$ – kristina Dec 19 '14 at 16:25
30
\$\begingroup\$

For formulating a diminishing returns equation, I'd immediately think fractions.

Graph of 1/F This is a graph of y=1/F

y will get smaller as F gets larger. This will give you a steady drop-off that never reaches 0. From this you can transform it to get the sort of curve that you want. Using numbers > 0 will always give positive output that is never 0.

Honestly, I'd recommend going to WolframAlpha and putting in some equations and looking at the graphs that it draws to see if it gives the curve that you want. Other than that, read up of linear and quadratic equations to be able to quickly figure out what it is that you want to alter in a formula. This is because modelling graphs through equations is a bit of a big topic, and if I could explain it here perfectly I'd sell that explanation to some maths teachers first.

Basically, for linear graphs, remember y=mx+c. m is the gradient, and can be positive or negative depending on what you need, and c is the point at which it intercepts the y axis. x is your input variable and y is your output.

y=mx+c This is a graph of y=mx+c where m=1 and c=0

For quadratic graphs, it gets a bit more complicated, so I'll be a bit vague and you'll have to read up on the specifics yourself. Khan Academy is a really good resource for teaching this. It's of the general form y=ax²+bx+c. c is still the y intercept, and you can tweak it to "lift" the graph. a and b both affect the curve similarly, but to different degrees.

y=-x²+2x+10 This is y=-x²+2x+10. Note the -x², which makes the curve inverted.

Basically, play around with the graphs until you get what you want, although I highly recommend reading up on it more if you want to design the experience quickly and cleanly. Basic equations are important to games and really interesting.

Other things to note are exponential and logarithmic graphs, i.e. graphs of y=e^x and y=ln(x) to get rapidly increasing and rapidly decreasing graphs depending on the transformation. As well as this, vectors and transformations are helpful, as they describe what you're doing the the "base" graph.

\$\endgroup\$
  • 6
    \$\begingroup\$ You use "graph theory" a couple times in the post; that is something else entirely. I think what OP is looking for comes closer to modelling. \$\endgroup\$ – Chaosed0 Dec 15 '14 at 14:23
  • 1
    \$\begingroup\$ @Chaosed0 You're absolutely right, I derped. Edited out though, ta :) \$\endgroup\$ – Yann Dec 15 '14 at 14:26
  • \$\begingroup\$ +1, I have played several games where the effect of some statistic is basically 1/x. Obviously for such a curve you never want x to equal zero, though! \$\endgroup\$ – Brian S Dec 15 '14 at 17:33
  • 1
    \$\begingroup\$ I would actually recommend Desmos over WA for designing functions. The two main reasons are that it's real-time and that it's manipulable. That is, set y = a^x, and you can add a slider for a to play with the function. You can have as many of these as you like. You can even animate the sliders. It's quite nice, actually. (Equivalent to Mathematica's Manipulate.) \$\endgroup\$ – wchargin Dec 15 '14 at 20:47
  • 1
    \$\begingroup\$ Graph Toy (which exists since several years) is a nice tool to try some equations. I use it all the time. \$\endgroup\$ – tigrou Dec 17 '14 at 8:53
20
\$\begingroup\$

Diminishing returns = decreasing derivative

  • Since you still want some returns even at higher levels means that the derivative should be positive, otherwise building more farms would decrease the food production (which might even make sense if you take into account logistics and upkeep costs)
  • It should approach zero assymptotically, if it goes towards a non-zero value you will end up with constant increase per farm at some level
  • depending on how fast it goes to zero you can have an upper limit or an unbounded function

So what do you need to do? Pick a function that fits the above criteria and integrate it.
The simplest choice for this task is g(t,n) = 1/(t+1)^n where n=1 marks the boundary between ever increasing and bounded functions.
The integral of g from 0 to x is what you need: f(x,n) = ((x+1)**(1-n) - 1)/(1-n)
Here is how it looks for different n

enter image description here
And here its normalized to the same final value

enter image description here
By changing the exponent n you can easily adjust the balancing
Note: The derivative here is the production per farm, while the integral is the total production for a number of farms

\$\endgroup\$
4
\$\begingroup\$

Would a linear diminishing return do? production per farm = (1 - (0.05 * (f/10)) ) * production rate. This gives a total production (rate * # of farms) peak at f = 100.

\$\endgroup\$
  • \$\begingroup\$ Hey, thanks, though I am looking for general principles at arriving at the equation (As you can see, Math is not my strong suit) \$\endgroup\$ – Extrakun Dec 15 '14 at 9:18
4
\$\begingroup\$

In general, a linear equation will start with y = mx + b, where b is your starting value, and mx is how you adjust the starting value as x increases.

So the first part of your equation, the b, will be 10 because you want farms to start at 10 food.

y = mx + 10

Next, in your case, you want to adjust the food by produced by every ten farms. So you will need to divide by ten to get an equation that works for every ten farms (assuming that the x / 10 returns an integer, ie 13 / 10 = 1:

y = m * (x / 10) + 10.

So finally, we need to figure out how we want the food to change for every x / 10 farms. In your case you want it to decrease by 0.5 (5% of 10), which is linear. So we get:

y = -0.5 * ( x / 10 ) + 10.

So for farm x = 5, we get 5 / 10 = 0, 0 * -0.5 = 0, 0 + 10 = 10. For farm x = 11 we get 11 / 10 = 1, 1 * -0.5 = -0.5, -0.5 + 10 = 9.5, for farm 23, we would get 9.0.

Then you just need to compute the total food for all farms.

y = 0
for( x = 0; x < totalFarms; x++ )
{
    y += -5 * ( x / 10 ) + 10;
}

But maybe you by 5%, you wanted it to decrease by 5% of the previous value. Ie, 10, 10 * 0.95 = 9.5, 9.5 * 0.95 = 9.025 (in this case, the amount we decrease by gets less and less). So lets modify the equation. 5%is an exponential type increase, and the exponential formula is y = b*m^x.

We still have b = 10, and we need to do our divide by 10 trick. So we have y = 10*m^(x/10). m is 0.95, since we want to take 95% of the value each time. So the equation for farm x is y = 10*0.95^(x/10).

\$\endgroup\$
2
\$\begingroup\$

You might want to consider an algorithmic solution that matches the situation.

That is, consider why there are diminishing returns in your game situation, and model those.

Multiple facilities of the same type might have diminishing returns is that there might be other resources or facilities which they depend on, or which result in bottlenecks, or other limiting situations, such as a road network, or available workers or transportation or fresh water or electricity or whatever.

One farm can produce 10 food per day in ideal circumstances, but it requires two farmer-hours per day as well. It also requires one fresh water per food per day, and its own well only provides up to 5 water per day. The rest must be taken from an adjacent stream or river or brought in by transportation. And getting the food to where it needs to be to be useful may also be an issue. Etc. Remove some or add more depending on what you want to represent, but these can be much more interesting and meaningful reasons, which add interest and value to your other game systems, as opposed to an artificial mathematical formula not based on other game elements.

\$\endgroup\$
1
\$\begingroup\$

If you want a generalized equation to mess around with, you could use a cosine graph: A*cos(Bx+C)+D

But modify it to half a period, so it would include the pseudo exponential rise at the beginning, then a short period of linear increases, to a finally diminishing point of returns. The only problem with this is that it would require to to create a impassable ceiling. So after a certain amount of farms you would see no increase.

The Image below is a graph of increases in pace for 30 min runs, doing the exact same workout in preparation. It's obviously not perfect, but you might be able to work off this to find what you're looking for.

Example of Cosine curve used to determine diminishing returns

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.