C ++中的Elo评分算法

Elo评分算法 是一种用于对竞技游戏中的玩家进行排名的评分算法。比赛选手的排名是根据球员的表现而定的,而球员的表现会随着球员的表现而变化,如下所示:

对于两个不同评级的玩家之间的游戏。假设有两个玩家互相竞争-

播放器1播放器2

玩家1的评分大于玩家2的评分。

如果玩家1赢得游戏,则如果玩家2 获胜,则某些玩家将从玩家1转移到玩家2,反之亦然。

但是,为胜利而转移的等级数量不是恒定的。相反,它取决于赢得比赛的人,

如果玩家1赢得比赛,则转移的积分会减少。
如果玩家2赢得比赛,则转移的积分更多。 

转移的积分数量取决于公式,

对于玩家1,

新等级=旧等级+等级常数*(成功概率-P1)

对于玩家2,

新等级=旧等级+等级常数*(成功概率-P2)

这里,

ratingConstant是一个常数,由游戏社区决定。

P1,玩家1获胜的概率。
P2,玩家2获胜的概率。

等级1是玩家1的等级。
等级2是玩家2的等级。

如果玩家获胜,则SuccessProb为1,否则为0。

让我们举一个例子来了解ELO评级算法的工作原理,

输入: 等级1 = 782,等级2 = 1432,
等级常量= 100,玩家1赢得比赛。

输出: 等级1 = 780,等级2 = 1434

解释-

玩家1获胜,

对于玩家1,

successProb = 1

新评分= 782 + 100 *(1-0.98)= 782 + 100 *(0.02)= 782 + 2 = 784

对于玩家2,

successProb = 0

新评分= 1432 + 100 *(0-0.02)= 1432-2 = 1430

用来说明ELO评分算法工作的程序,

示例

#include <bits/stdc++.h>
using namespace std;

void updateRatingUsingELoRating(float rating1, float rating2, int ratingConstant, bool player1SuccessProb) {

   float P1, P2;
   if(rating1 > rating2){
      P1 = (1.0 / (1.0 + pow(10.0, ((rating1 - rating2) / 400.0)) ) );
      P2 = 1 - P1;
   }
   else {
      P2 = (1.0 / (1.0 + pow(10.0, ((rating2 - rating1) / 400.0)) ) );
      P1 = 1 - P2;
   }

   if (player1SuccessProb == 1) {
      rating1 = rating1 + ratingConstant * (1 - P1);
      rating2 = rating2 + ratingConstant * (0 - P2);
   }
   else {
      rating1 = rating1 + ratingConstant * (0 - P1);
      rating1 = rating1 + ratingConstant * (1 - P2);
   }

   cout<<"Ratings After the game\n";
   cout<<"玩家1: "<<rating1<<"\t Player 2 : "<<rating2;
}

int main()
{
   float rating1 = 782, rating2 = 1432;
   int ratingConstant = 100;
   bool player1SuccessProb = 1;
   cout<<"Ratings before the game: \n";
   cout<<"玩家1: "<<rating1<<"\t Player 2 : "<<rating2<<endl;
   if(player1SuccessProb)
      cout<<"Player 1 wins the game!\n";
   else
      cout<<"Player 2 wins the game!\n";
   updateRatingUsingELoRating(rating1, rating2, ratingConstant, player1SuccessProb);

   return 0;
}

输出-

Ratings before the game:
玩家1: 782       Player 2 : 1432
Player 1 wins the game!
Ratings After the game
玩家1: 784.316 Player 2 : 1429.68