我从PHPClasses网站获得了以下ELO课程。
<?php
class elo_calculator {
public function rating($S1, $S2, $R1, $R2) {
if(empty($S1) or empty($S2) or empty($R1) or empty($R2))
return null;
if($S1 != $S2) {
if($S1 > $S2) {
$E = 120 - round(1 / (1 + pow(10, (($R2 - $R1) / 400))) * 120);
$R['R3'] = $R1 + $E;
$R['R4'] = $R2 - $E;
} else {
$E = 120 - round(1 / (1 + pow(10, (($R1 - $R2) / 400))) * 120);
$R['R3'] = $R1 - $E;
$R['R4'] = $R2 + $E;
}
} else {
if($R1 == $R2) {
$R['R3'] = $R1;
$R['R4'] = $R2;
} else {
if($R1 > $R2) {
$E = (120 - round(1 / (1 + pow(10, (($R1 - $R2) / 400))) * 120)) - (120 - round(1 / (1 + pow(10, (($R2 - $R1) / 400))) * 120));
$R['R3'] = $R1 - $E;
$R['R4'] = $R2 + $E;
} else {
$E = (120 - round(1 / (1 + pow(10, (($R2 - $R1) / 400))) * 120)) - (120 - round(1 / (1 + pow(10, (($R1 - $R2) / 400))) * 120));
$R['R3'] = $R1 + $E;
$R['R4'] = $R2 - $E;
}
}
}
$R['S1'] = $S1;
$R['S2'] = $S2;
$R['R1'] = $R1;
$R['R2'] = $R2;
$R['P1'] = ((($R['R3'] - $R['R1']) > 0)?"+" . ($R['R3'] - $R['R1']) : ($R['R3'] - $R['R1']));
$R['P2'] = ((($R['R4'] - $R['R2']) > 0)?"+" . ($R['R4'] - $R['R2']) : ($R['R4'] - $R['R2']));
return $R;
}
}
?>
我正在尝试将其应用到我的食品评级网站。
这是我理解的
这是PHP的实现相同。你能帮我理解4个变量以及我该如何使用它?
答案 0 :(得分:5)
这里的GitHub是我发现的最好的ELO评级系统的php类:https://github.com/Chovanec/elo-rating
<强> USAGE:强>
// player A elo = 1000
// player B elo = 2000
// player A lost
// player B win
$raging = new Rating(1000, 2000, 0, 1);
// player A elo = 1000
// player B elo = 2000
// player A draw
// player B draw
$raging = new Rating(1000, 2000, .5, .5);
答案 1 :(得分:1)
1.S1应该是第一道菜的当前得分,S2是第二道菜的比较
2.R1是当前菜肴的排名,R2是第二菜的当前排名
2.如果不公平,这个系统将不会用于全球游戏
3.你可能会使用数据库来保存分数,所以我们可以说它应该是这样的
if($elo_calcualtor->rating(1,2,1,2)['p1'] < 0){$current_dish_score = 0;}
最后 你应该从10开始评级,所以它不会低于0,最有可能不会高于20
希望这会有所帮助