Created
May 21, 2015 06:05
-
-
Save Code-Hex/0e8a405bf7a3e9c8721f to your computer and use it in GitHub Desktop.
Elo rating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/perl env | |
use strict; | |
use warnings; | |
use 5.010; | |
use Math::Round; | |
my $k = 32; | |
my %winner = ( | |
'name' => 'John', | |
'score' => 1500, | |
'win' => 0, | |
'lose' => 0, | |
); | |
my %losser = ( | |
'name' => 'Mike', | |
'score' => 1500, | |
'win' => 0, | |
'lose' => 0, | |
); | |
for (my $var = 1; $var <= 100; $var++) { | |
my $win_expected = expected($losser{'score'}, $winner{'score'}); | |
my $win_new_score = win($winner{'score'}, $win_expected); | |
$winner{'score'} = $win_new_score; | |
my $lose_expected = expected($winner{'score'}, $losser{'score'}); | |
my $lose_new_score = lose($losser{'score'}, $lose_expected); | |
$losser{'score'} = $lose_new_score; | |
say "$var : Winner score: ".nearest(1,$winner{'score'}); | |
say "$var : Losser score: ".nearest(1,$losser{'score'}); | |
} | |
sub expected { | |
my ($Rb, $Ra) = @_; | |
return 1 / (1 + (10 ** (($Rb - $Ra) / 400))) | |
} | |
sub win { | |
my ($score, $expected) = @_; | |
return $score + $k * (1 - $expected); | |
} | |
sub lose { | |
my ($score, $expected) = @_; | |
return $score + $k * (-$expected); | |
} | |
=pod | |
Ra -- Rate of player A | |
Rb -- Rate of player B | |
K -- K-factor : レートの補正の最大値 | |
http://en.wikipedia.org/wiki/Elo_rating_system | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment