1
$\begingroup$

In the game being developed, players will be playing best-of-three matches against one another. XP will be given out depending on their score vs the average score and will receive a bonus for whether or not they win or lose.

Given the nature of our game, players will be able to leave a match in between any of the 3 rounds, able to return to them at a later point in time. In order to decentivize players from starting and immediately leaving games/not continuing if they sense they might just lose, I've designed an equation around the idea that alters/gives bonus xp based on if/how many rounds they have played.

In said equation, I reference variables monitored by our database for recording reasons, specifically 'round,' which notes what round the player is currently on, and 'win,' which refers to whether or not the player won.

The issue I'm having is it's been a good long time since I took any Maths classes and have forgotten a good chunk of notation + terminology, and am struggling to put my thoughts down into words, either to explain to programming or search to help myself.



Eqn: $\text{XP}= \lfloor \frac{p}{a}* R\rfloor + E$

In this equation:

  • p = player's highest score from the 3 rounds
  • a = Game's Average Score / 10
  • R = Rounds played bonus (Bonus based on number of rounds they played)
  • E = End status bonus (Bonus based on whether they won or lost)


My probelm here is the fact that R depends on the round # recorded in the database and similarly E depends on whether or not they won as recorded in database, and in both cases I'm not sure how to notate it.

If in database:

  • round = 1, R = 1
  • round = 2, R = 1.15
  • round = 3, R = 1.35
  • win = 1, E = 15
  • win = 0, E = 5
  • win = 2, E = 0
  • win = 3, E = 0

In relation to my equation, how can I best notate everything?

Edit: Pic of me attempting to explain said equation to programming in poor handwriting

Fairly certain I'm not notating that 100% correctly, given programmer literally said "could you put this part in an equation?" while pointing at my if thens.

$\endgroup$
  • $\begingroup$ R and E are functions of round and win respectively earn, then the equation is $\text{XP}= \lfloor \frac{p}{a}* R(round)\rfloor + E(win)$. $\endgroup$ – Rafael Castro Mar 15 at 18:49
0
$\begingroup$

Since you gave an equation, I'm guessing you are trying to come up with some mathematical expression that will capture the dependence of $R$ on the number of rounds and $E$ on the win? $E$ is easy, and since $R$ has only 3 values, it wouldn't be hard to come with an expression for $R$ either - though since your values do not grow arithmetically, it would be a bit more complicated.

However, programmatically, this is a bad idea. The program will be easier to understand, and easier to modify if you DON'T try to convert this into one big equation. Your programmer is asking for an equation not because they think an equation is the way to go, but because they couldn't follow your mass of if statements, and hoped that by an equation, they could make some sense of it.

What you want is method like this:

int CalculateBonusXP(int PlayerHighestScore, double GameAverageScore, int RoundsPlayed, int Outcome)
{
    double RoundBonus = Math.Max(10d * (double)PlayerHighestScore / GameAverageScore,1d);
    switch (RoundsPlayed) 
    {
        case 1:
            break;
        case 2:
            RoundBonus = RoundBonus * 1.15;
            break;
        case 3:
            RoundBonus = RoundBonus * 1.35;
            break;
    }
    int BonusXP = int(RoundBonus);

    switch (Outcome) 
    {
        case 0:        // loss
            BonusXP = BonusXP + 5;
            break;
        case 1:        // win
            BonusXP = BonusXP + 15;
            break;
        default:       // draw, cancellation
            break;
    }
    return BonusXP
}

Your programmer should be able to follow that, and convert it into whatever language they are using.

$\endgroup$
  • $\begingroup$ Thanks for the extensive answer! Appreciate the bit of code you've given, I'm sure it'll help get my point across. One thing I'm just realizing I forgot to mention in the OP was that p/a is also a function that has a condition on it. So say S=p/a, how could I best express that if p/a < 1 then S = 1, but if p/a > 1 then S = ⌊S⌋ ? $\endgroup$ – Tenkster Mar 18 at 9:42
  • $\begingroup$ Do you want to truncate $S$ down to an integer, the multiply by $R$, then truncate the result to an integer again? If you do it that way, then the player gets no benefit from $R$ unless $S \ge 3$ (or $S \ge 4$ if they only play two rounds). I've made a change above to make sure $S$ is at least one, but another step will be needed if you want the additional truncation. $\endgroup$ – Paul Sinclair Mar 18 at 16:20
  • $\begingroup$ One other comment that may help you with future discussions with your programmer. Mathematicians and physicists love single letter variable names, for a number of very good reasons. But programmers tend to hate them, also for a number of very good reasons. When talking to programmers, it is wisest to use as descriptive names for your variables as possible. $\endgroup$ – Paul Sinclair Mar 18 at 16:23
  • $\begingroup$ To explain a little better my first comment: Suppose a player plays 3 rounds, but their highest score is only $2.9$ times $a$. If you immediately truncate $S$ as you indicated, then $S = 2$, so $S \times R = 2.7$, which still truncates back to $2$, No benefit from those later rounds. If you do not truncate $S$ before multiplying by $R$, then $S \times R = 3.915$, which truncates to $3$, so they do get some benefit from playing all three rounds. $\endgroup$ – Paul Sinclair Mar 18 at 16:36
  • $\begingroup$ Ah, okay, I see what you mean and you're right, it is a bit redundant/detrimental. So say I instead only make it so that if S<1, S = 1 and if S>1, S=S, how would that translate into that code above? Also will casually mention for E I've added 2 more states for when matches end in a Draw or Cancelled (opp dropped out). I'll be seeing the programmer tomorrow and I'm pretty sure with what you've provided above (both the code and helpful info to change my notation) that he should be able to figure it out himself, but wanna look good :p. Thanks for all your help so far! $\endgroup$ – Tenkster Mar 18 at 16:49

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.