0
$\begingroup$

I'm developing an open-ended strategy game. I am using the following formula to calculate damage (In PHP 'cause I don't know MathJaX!):

$rand = rand($a, $b) + $c;
$damage = $rand * sqrt(($d / 20) * $c));

a, b, c, and d are all values that can be modified by the user over the course of play, either by buying a better item (a and b), investing in the item (c), or investing in their character d.

What I want to do now is add a bit of randomness to the outcome of the equation. Because the game is open ended:

  1. a static value would become unnoticeable/negligible over time.
  2. a percentage based value would allow for too much noise over time.

So, I want to add a random value that is small at first, and grows with increased input, but has diminishing returns. I'm sure I need some kind of logarithmic formula, but I'm not sure how to go about it!

  • 2
    Just pick any increasing concave function $f(damage)$ and produce a random disturbance in the range [-f(damage),f(damage)] (provided I understood your requirements correctly). There are lots of concave functions: log (to any base), $n$-th root for any integer $n$, arctan,... and of course you can scale them in any way you like. Look at the graphs and pick the one that best fits your bill. Note that these functions behave very differently, as damage gets large.2010-12-24

1 Answers 1

2

Let me expand upon my comment: you can pick any positive increasing concave function $f$(damage) and produce a random disturbance in the range [-$f$(damage),+$f$(damage)]. That will give you a disturbance that increases with the damage, but it increases more and more slowly.

There are lots of concave functions: log (to any base), n-th root for any integer n, arctan,... and of course you can scale them in any way you like. Moreover, any composition of concave functions is concave, so you can do e.g. s.th. like $log(\sqrt{x})$. Note that these functions behave very differently, as $x$ gets large: log falls below any $n$-root eventually, but is unbounded. arctan on the other hand asymptotically approaches $2\pi$, so for very large damage it will behave almost like a constant disturbance. You can influence when that happens by dilating, scaling and translating along the $x$-axis.