-1

So I am developing a game where there will be two players both having an initial rating.

Now, I want to calculate new rating based on their score.

For eg: if player1 scores 50(unitless) and player2 scores 30, then player1 rating should increase more then in the case where player1 scores 40 and player2 scores 30 and wins by a great margin.

The Elo rating system only takes account of wins and losses and not the margin of winning.

Any help would be appreciated.

WarpPrime
  • 215
  • 5
  • 20

2 Answers2

1

A simple solution is: increase the winning players rating by abs(player1.score - player2.score) and decrease the loser's rating by the same amount.

I would suggest modifying this method slightly to make it more robust, for example: 10*ln(abs(player1.score - player2.score))

Edit

Define: S(X) = score after X matches and E(X) = elo after X matches. We are interested in calculating S(X+1).

S(X+1) = S(X) + k*(E(X+1)-E(X))*ln(abs(player1.score - player2.score)).

Here, k is a constant that can be tweaked by trial and error. This model takes into account both rating difference (via elo) and score difference.

tersrth
  • 861
  • 6
  • 18
  • thanks for your explaination but this is not what I want. It does not take into account that if a player has low rating and wins against a player with high rating than his rating should increase more than in the case if the lower rating person wins against another lower rating person. Your formula is based on current match and not previous history of the player – louis philippe Jun 04 '20 at 08:46
  • @louisphilippe could you clarify the question? Should the formula take into account past history or not? If it needs to, you can use the elo system to calculate the new rating. Then, do (new rating - old rating) to obtain the change in rating. Then, do ln(abs(player1.score - player2.score)) * (change in rating). – tersrth Jun 04 '20 at 08:50
  • let me explain you with an example let's say in match1- player1 scores 50 and player2 scores 10 and in another match match2- player1 scores 80 and player2 scores 20 then increase in his rating should be more in match2 because he won by a great margin. Now take match1 and derive two cases in one case player1 has rating 1400 and player2 has rating 1000 and in second case player1 has rating 1400 but player2 has rating 2000 than don't u think that we should consider the margin in rating as well while calculating new rating cause in second case player1 has defeated contender with high rating – louis philippe Jun 04 '20 at 09:00
  • @louisphilippe the elo system already takes into account player rating difference. The system I answered was a modification of the elo system to also account for difference in scores. Therefore, the system I gave takes into account both rating difference and score difference. – tersrth Jun 04 '20 at 09:32
  • okay can you please write down a full fledged formula so that I can fully review it – louis philippe Jun 04 '20 at 12:38
  • i've edited my answer. i hope my answer helped you! – tersrth Jun 04 '20 at 13:36
  • thanks for answering by S(X) you mean rating according to my requirement right? – louis philippe Jun 04 '20 at 16:27
  • yes. you can figure out the best value of k with some experimentation. – tersrth Jun 05 '20 at 00:34
0

Let score1 be player1's score, and score2 be player2's score. So the change in rating would be abs(score1 - score2) / x, where x is a variable that you can change. Assuming that you use JavaScript, here is the full code for rating calculation.

The change in rating now depends on the differences in rating:

function calcRating() {
  var i = 1;
  var score1 = document.getElementById('score1').value;
  var score2 = document.getElementById('score2').value;
  var player1 = document.getElementById('player1').value;
  var player2 = document.getElementById('player2').value;
  var a = player1;
  var b = player2;
  
  if (score1 > score2) {
      if (player1 > player2) {
        player1 = a - (0 - Math.round((score1 - score2) / (i * (Math.abs(player1 - player2)))));
        player2 = b - Math.round((score1 - score2) / (i * (Math.abs(player1 - player2))));
      }
      else if (player1 < player2) {
        player1 = a - (0 - Math.round((score1 - score2) / (i / (Math.abs(player1 - player2)))));
        player2 = b - Math.round((score1 - score2) / (i / (Math.abs(player1 - player2))));
      }
      else {
        player1 = a - (0 - Math.round((score1 - score2) / i));
        player2 = b - Math.round((score1 - score2) / i);
      }
  } 
  else if (score1 < score2) {
    if (player1 > player2) {
        player1 = a - Math.round(Math.abs((score1 - score2)) / (i * (Math.abs(player1 - player2))));
        player2 = b - (0 - Math.round(Math.abs(score1 - score2) / (i * (Math.abs(player1 - player2)))));
    }              
      else if (player1 < player2) {
        player1 = a - Math.round(Math.abs(score1 - score2) / (i / (Math.abs(player1 - player2))));
        player2 = b - (0 - Math.round(Math.abs(score1 - score2) / (i / (Math.abs(player1 - player2)))));
      }
      else {
        player1 = a - Math.round(Math.abs(score1 - score2) / i);
        player2 = b - (0 - Math.round(Math.abs(score1 - score2) / i));

      }
  }
    document.getElementById('score1').value = 0;
    document.getElementById('score2').value = 0;
    document.getElementById('player1').value = player1;
    document.getElementById('player2').value = player2;
}
<button id="button" onclick='calcRating()'>Click to calculate ratings</button>

<br> Player1 score: <input type="text" id="score1" value="0"></input>

<br> Player2 score: <input type="text" id="score2" value="0"></input>

<br> Player1 rating: <input type="text" id="player1" value="0"></input>
<br> Player2 rating: <input type="text" id="player2" value="0"></input>

You can mess around with the inputs in the HTML to change the ratings and scores manually, as well as x, which is the number that the difference in score is divided by before appending changes to the rating values.

WarpPrime
  • 215
  • 5
  • 20
  • thanks for your explaination but It does not take into account that if a player has low rating and wins against a player with high rating than his rating should increase more than in the case if the lower rating person wins against another lower rating person. Your formula is based on current match and not previous history of the player – louis philippe Jun 03 '20 at 18:20
  • Here, I completed the edits for the rating-dependent score changes. – WarpPrime Jun 04 '20 at 13:17