How to "invent" a function? I'm currently making a game. I was given some numbers the leader wants me to stick close to. They are used for leveling; level 1, for example, needs 100 experience points, level 2 needs 250 experience points, etc.
Is there any way, maybe with a computer program, to calculate a function that will do something like this, instead of having to hard-code it?
Thanks in advance!
Simon.
 A: Depending on the number of levels that you have in your game, it may make more sense to hard code the values. Really depends if these experience points are never going to change, or if in a couple weeks your leader has a new set of values (and thus a new function you have to produce).
Ask your leader how he/she came up with the values and they have a heuristic that they are using. Likely it will be something like "$x$ times as many points as the previous level required".
Otherwise, you can go to wikipedia and read up on Regression analysis.
A: I think interpolation is not the way to go, as levels are discrete in any way and especially the lagrange interpolation might really not do what you want (most answers suggest to use it to interpolate the few first values, but then the function can even be negative for higher levels although it fits what you originally wanted, and if you interpolate over all values you could directly use a table, I see no advantage here).
The experience function is something that should be carefully designed as it is one of the main goals for the player to level up (and the game should not get too boring after a few levels, at the same time it shouldn't be too fast to level up). Also you have to consider that the experience you gain from defeating enemys should maybe also increase over the time.
Therefore there are a few things you should consider in your formula:


*

*The level of the character (of course, this will be the main parameter)

*The average amount of experience the character gets by defeating an enemy

*A difficulty factor?
As an example you can learn from the experience function of this popular game. I can assure you that they thought a lot about balance and especially experience. For example in patch 2.3 they added a different factor to speed up the level process in certain levels because it was too difficult to level up. I also recommend this. I would recommend you to use a similar approach and maybe you should use a hardcoded table.
A: I know you said you wanted to avoid a hardcoded table, but honestly that's what you should use.  The mathematical approaches given here are all well and good, but using them you will probably have to settle for an approximation of what you really want, and it may not be easy to make changes later.
Just write an array indexed by level with the XP needed to level up.  This is what World of Warcraft does (WoW) as do most MMOs.  It's a tiny bit of memory, super-fast, and completely flexible.
A: There are plenty of ways; it all depends on what kind of function you want.
One way is to use Lagrange interpolation to get a polynomial that will have the values you want (e.g., $f(1)=100$, $f(2)=250$, etc). This, however, may not give you the "correct" long-term behavior, and the long-term growth is not going to be exponential. You will "hit" all the right values for the points you are given, but you may not have good control later.
(For example, if you use Lagrange polynomial interpolation to find a function that satisfies
$$f(0)=1,\quad f(1)=2,\quad f(2)=4,\quad f(3)=8,\quad\text{and}\quad f(4)=16,$$
then this function will give $f(5)=31$ (rather than the perhaps expected $32$).
A more likely long-term behavior will be given by exponential functions. If the rate of growth is relatively constant, then that's the way to go. Consider the sequence of quotients of successive values:
$$\frac{f(2)}{f(1)},\quad\frac{f(3)}{f(2)},\quad\frac{f(4)}{f(3)},\quad\frac{f(5)}{f(4)},\ldots$$
and if these are all reasonably close to one another, then take $a$ to be their average. You can approximate the values pretty well with
$$f(n) = f(1)a^{n-1}.$$
This is what Ross gives you, with $a=2.5$ and $f(1)=100$, except he's writing it as 
$$f(n) = 100(2.5)^{n-1} = \left(\frac{100}{2.5}\right)2.5^n = 40\times 2.5^n.$$
If the rate of growth is (the successive factors) are changing a lot, though, it's going to be a lot harder to come up with a good exponential approximation.
A: It depends upon how accurately you want to reproduce the numbers.  For example, you could use $40*2.5^{level}$.  This gives 100, 250,625,1562.5,3906.25 and so on.  The first two match exactly.  Exponential growth seems to be what many games want.  Does this meet your needs?
A: Depending on every data your given, you might want to choose some polynomial interpolation.
You will notice that there are different approaches to find such a polynomial, but since it is unique, you'll always find the same.
I'm not an expert either in numerical methods nor in programming, so there might be other ways I'm not aware of.
Also, like Arturo says, this will be best if your scale of levels doesn't go too far to infinity (see his answer for more insight).
