Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

C++의 Elo 평가 알고리즘

<시간/>

Elo 평가 알고리즘 경쟁 게임에서 플레이어의 순위를 매기는 데 사용되는 평가 알고리즘입니다. 대회의 선수 순위는 다음과 같이 선수의 성과에 따라 변하는 란팅을 기준으로 합니다.

등급이 다른 두 플레이어 간의 게임입니다. 두 명의 플레이어가 서로 경쟁하고 있다고 가정해 보겠습니다.-

플레이어1 플레이어2

player1의 평가가 player2보다 큽니다.

플레이어1 인 경우 게임에서 이기면 일부 플레이어는 player1에서 player2로, 그리고 그 반대로도 player2가 이기면 전송됩니다.

그러나 승리를 위해 이전되는 등급의 양은 일정하지 않습니다. 대신 게임에서 이긴 사람에 따라 다릅니다.

플레이어 1이 게임에서 이기면 이전된 점수가 더 적습니다.
player2가 게임에서 이기면 이전된 포인트가 더 많습니다.

이전되는 포인트의 양은 공식에 따라 다릅니다.

플레이어 1의 경우

새 등급 =이전 등급 + RatingConstant * (successProb - P1)

플레이어 2의 경우

새 등급 =이전 등급 + RatingConstant * (successProb - P2)

여기,

RatingConstant는 상수이며 게임 커뮤니티에서 결정합니다.

P1, 플레이어 1이 이길 확률.
P2, 플레이어 2가 이길 확률.

Rating1은 player1의 등급입니다.
Rating2는 player2의 등급입니다.

플레이어가 이기면 successProb는 1이고 그렇지 않으면 0입니다.

ELO 등급 알고리즘의 작동을 이해하기 위해 예를 들어 보겠습니다.

입력: 등급1 =782, 등급2 =1432,
RatingConstant =100, player1이 게임에서 승리합니다.

출력: 등급1 =780, 등급2 =1434

설명 -

Player1이 이기고

플레이어 1의 경우

성공 확률 =1

새 등급 =782 + 100*(1 - 0.98) =782 + 100*(0.02) =782 + 2 =784

플레이어 2의 경우

성공 확률 =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<<"Player 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<<"Player 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:
Player 1 : 782       Player 2 : 1432
Player 1 wins the game!
Ratings After the game
Player 1 : 784.316 Player 2 : 1429.68