I am creating a mobile game where I would like to award prizes (ie. gold) to the players based on how well they did in the game. First place wins the most gold, last place will get a small amount of gold (more than zero).
However, I want the prizes to be awarded in an exponential fashion. By that I mean, if I set the maximum gold that can be won to 100, if there were 10 players in the game, I would award the guy in 1st 100 gold, the guy in 2nd 75 gold, 3rd gets 60, 4th gets 50, 5th gets 43... etc. Note that they do not add up to 100, but each player gets a percentage of the max gold based on their place in the game.
So, I'm really hoping someone can help me figure out a formula I can use in the following function :
function calculatePrize(place, totalPlayers) {
// do some calculation to based on their place to find out what percentage of the max prize the should get (value will be between 0 and 1)
}
// call the function and multiple by max prize
theirPrize = calculatePrize(6, 10) * maxPrize;
(the above code will call the calculatePrize function, telling it there are 10 players and thie particular player got 6th. The function would return a decimal between 0 and 1 (ie .55).
So, if the max prize in this example was 100, that player would get 55 gold.
Any idea how to do this? I've been googling and trying formulas on my own and getting no where :(
Thanks!!!