vendredi 20 mai 2016

Best way to calculate several iterations with different parameters?

I am making a program that calculates what requirements need to be met in order to win an achievement from a game.

An achievement can have multiple levels, each with different requirements, and a player could have already fulfilled part of the requirements. So, for example:

Achievement A level 1 requires 10 rat tails
Achievement A level 2 requires 8 rat tails and 2 wolf tails

In order to get Achievement A level 2 a player would need a total of 18 rat tails and 2 wolf tails, but if he already has 5 rat tails I'd like the program to tell him he needs 13 rat tails and 2 wolf tails.

Therefore I am looking for a mathematical equation or programming method that can easily (maybe in a loop) calculate the requirements of each level and substract what the player already has, in other words some sort of a loop that calculates a different equation each time. The reason for that is that a player can choose which level he wants, so he can choose "Tell me what I need for level 1" or "Tell me what I need for level 10" and after his selection the program needs to do the total calculation, which I can do by hand like:

int wolftail, rattail;
int wolftailInv, rattailInv;
if (level == 1)
{
  wolftail = 0;
  rattail = 10 - rattailInv;
}

if (level == 2)
{
  wolftail = 2 - wolftailInv;
  rattail = 18 - rattailInv;
}

Or, in other words the mathematical equation for the total for level 2 would be (let's for a moment ignore what the player already has):

Level 2 = Level 1 + 2x wolftail + 8x rattail
Level 1 = 10x rattail
=>
Level 2 = 10x rattail + 2x wolftail + 8x rattail

while the equation for level 1 would be only:

Level 1 = 10x rattail

So I am wondering if there is a mathematical or programmatical method which could automate this.

Aucun commentaire:

Enregistrer un commentaire