logo

Elo 評価アルゴリズム

Elo 評価アルゴリズム は、多くの対戦ゲームでプレイヤーをランク付けするために広く使用されている評価アルゴリズムです。 

  • ELO レーティングが高いプレーヤーは、ELO レーティングが低いプレーヤーよりもゲームに勝つ確率が高くなります。
  • 各ゲームの後、プレイヤーの ELO レーティングが更新されます。
  • より高い ELO レーティングを持つプレイヤーが勝った場合、より低いレーティングのプレイヤーから数ポイントだけが転送されます。
  • ただし、低レーティングのプレーヤーが勝った場合、高レーティングのプレーヤーから転送されるポイントははるかに大きくなります。

アプローチ: この問題を解決するには、次のアイデアに従ってください。

P1: レーティング 2 のプレイヤーが勝つ確率 P2: レーティング 1 のプレイヤーが勝つ確率。 
P1 = (1.0 / (1.0 + pow(10 ((評価 1 - 評価 2) / 400)))); 
P2 = (1.0 / (1.0 + pow(10 ((評価 2 - 評価 1) / 400)))); 



明らかに、P1 + P2 = 1 です。プレーヤーの評価は、以下の式を使用して更新されます。 
評価 1 = 評価 1 + K*(実際のスコア - 期待されるスコア); 

Java 置換オール

ほとんどのゲームでは、「実際のスコア」は 0 または 1 で、プレイヤーが勝つか負けるかを意味します。 Kは定数です。 K の値が低い場合、評価はわずかな割合で変化しますが、K の値が高い場合、評価の変化は大きくなります。組織が異なれば、K の値も異なります。

例:

chess.com 上で 2 人のプレイヤーの間でライブ試合があるとします。 
評価 1 = 1200 評価 2 = 1000; 

パイソンヘビ vs アナコンダ

P1 = (1.0 / (1.0 + pow(10 ((1000-1200) / 400)))) = 0.76 
P2 = (1.0 / (1.0 + pow(10 ((1200-1000) / 400))) = 0.24 
そして、定数 K=30 と仮定します。 

ケース-1: 
プレイヤー 1 が勝ったとします。 Rating1 = Rating1 + k*(実際 - 期待値) = 1200+30(1 - 0.76) = 1207.2; 
評価 2 = 評価 2 + k*(実際 - 予想) = 1000+30(0 - 0.24) = 992.8; 

ケース-2:  
プレーヤー 2 が勝ったとします。 Rating1 = Rating1 + k*(実際 - 期待値) = 1200+30(0 - 0.76) = 1177.2; 
評価 2 = 評価 2 + k*(実際 - 予想) = 1000+30(1 - 0.24) = 1022.8;

問題を解決するには、次の手順に従ってください。

  • 上記の式を使用してプレーヤー A と B が勝つ確率を計算します。
  • プレーヤー A が勝った場合、またはプレーヤー B が勝った場合、レーティングは次の式を使用してそれに応じて更新されます。
    • 評価 1 = 評価 1 + K*(実際のスコア - 期待されるスコア)
    • 評価 2 = 評価 2 + K*(実際のスコア - 期待されるスコア)
    • 実際のスコアが 0 または 1 の場合
  • 更新された評価を印刷する

上記のアプローチの実装を以下に示します。

Javaは文字列をintに変換します
CPP
#include    using namespace std; // Function to calculate the Probability float Probability(int rating1 int rating2) {  // Calculate and return the expected score  return 1.0 / (1 + pow(10 (rating1 - rating2) / 400.0)); } // Function to calculate Elo rating // K is a constant. // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. void EloRating(float Ra float Rb int K float outcome) {  // Calculate the Winning Probability of Player B  float Pb = Probability(Ra Rb);  // Calculate the Winning Probability of Player A  float Pa = Probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  cout << 'Updated Ratings:-n';  cout << 'Ra = ' << Ra << ' Rb = ' << Rb << endl; } // Driver code int main() {  // Current ELO ratings  float Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  float outcome = 1;  // Function call  EloRating(Ra Rb K outcome);  return 0; } 
Java
import java.lang.Math; public class EloRating {  // Function to calculate the Probability  public static double Probability(int rating1 int rating2) {  // Calculate and return the expected score  return 1.0 / (1 + Math.pow(10 (rating1 - rating2) / 400.0));  }  // Function to calculate Elo rating  // K is a constant.  // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw.  public static void EloRating(double Ra double Rb int K double outcome) {  // Calculate the Winning Probability of Player B  double Pb = Probability(Ra Rb);  // Calculate the Winning Probability of Player A  double Pa = Probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  System.out.println('Updated Ratings:-');  System.out.println('Ra = ' + Ra + ' Rb = ' + Rb);  }  public static void main(String[] args) {  // Current ELO ratings  double Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  double outcome = 1;  // Function call  EloRating(Ra Rb K outcome);  } } 
Python
import math # Function to calculate the Probability def probability(rating1 rating2): # Calculate and return the expected score return 1.0 / (1 + math.pow(10 (rating1 - rating2) / 400.0)) # Function to calculate Elo rating # K is a constant. # outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. def elo_rating(Ra Rb K outcome): # Calculate the Winning Probability of Player B Pb = probability(Ra Rb) # Calculate the Winning Probability of Player A Pa = probability(Rb Ra) # Update the Elo Ratings Ra = Ra + K * (outcome - Pa) Rb = Rb + K * ((1 - outcome) - Pb) # Print updated ratings print('Updated Ratings:-') print(f'Ra = {Ra} Rb = {Rb}') # Current ELO ratings Ra = 1200 Rb = 1000 # K is a constant K = 30 # Outcome: 1 for Player A win 0 for Player B win 0.5 for draw outcome = 1 # Function call elo_rating(Ra Rb K outcome) 
C#
using System; class EloRating {  // Function to calculate the Probability  public static double Probability(int rating1 int rating2)  {  // Calculate and return the expected score  return 1.0 / (1 + Math.Pow(10 (rating1 - rating2) / 400.0));  }  // Function to calculate Elo rating  // K is a constant.  // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw.  public static void CalculateEloRating(ref double Ra ref double Rb int K double outcome)  {  // Calculate the Winning Probability of Player B  double Pb = Probability((int)Ra (int)Rb);  // Calculate the Winning Probability of Player A  double Pa = Probability((int)Rb (int)Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  }  static void Main()  {  // Current ELO ratings  double Ra = 1200 Rb = 1000;  // K is a constant  int K = 30;  // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw  double outcome = 1;  // Function call  CalculateEloRating(ref Ra ref Rb K outcome);  // Print updated ratings  Console.WriteLine('Updated Ratings:-');  Console.WriteLine($'Ra = {Ra} Rb = {Rb}');  } } 
JavaScript
// Function to calculate the Probability function probability(rating1 rating2) {  // Calculate and return the expected score  return 1 / (1 + Math.pow(10 (rating1 - rating2) / 400)); } // Function to calculate Elo rating // K is a constant. // outcome determines the outcome: 1 for Player A win 0 for Player B win 0.5 for draw. function eloRating(Ra Rb K outcome) {  // Calculate the Winning Probability of Player B  let Pb = probability(Ra Rb);  // Calculate the Winning Probability of Player A  let Pa = probability(Rb Ra);  // Update the Elo Ratings  Ra = Ra + K * (outcome - Pa);  Rb = Rb + K * ((1 - outcome) - Pb);  // Print updated ratings  console.log('Updated Ratings:-');  console.log(`Ra = ${Ra} Rb = ${Rb}`); } // Current ELO ratings let Ra = 1200 Rb = 1000; // K is a constant let K = 30; // Outcome: 1 for Player A win 0 for Player B win 0.5 for draw let outcome = 1; // Function call eloRating(Ra Rb K outcome); 

出力
Updated Ratings:- Ra = 1207.21 Rb = 992.792 

時間計算量: アルゴリズムの時間計算量は、主に pow 関数の複雑さに依存します。関数の複雑さはコンピューター アーキテクチャに依存します。 x86 では、これは定数時間演算です:-O(1)
補助スペース: ○(1)