PHP Facemash ELO 评级类别/功能

发布于 2024-10-31 03:56:50 字数 1999 浏览 7 评论 0原文

我从 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;
    }
} 
?>

我正在尝试将其应用到我的食品评级网站。

这是我的理解

  1. 要从系统开始,我们需要为所有菜肴分配一个基本分数。
  2. 我们有 4 个变量 S1、S2、R1、R2(S= 分数,R= 排名)
  3. 当在两道菜之间进行评分时,如果我按第一道菜。 S1 和 S2 是什么?会是1-0吗?
  4. 如果我在 10k 次战斗后添加另一道菜会怎样?因为我将为它分配一个基本分数,这样会更好吗?
  5. 我怎样才能阻止菜的分数不低于 0。

这是相同的 PHP 实现。你能帮我理解这 4 个变量以及我应该如何使用它吗?

I got the following ELO class from PHPClasses website.

<?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;
    }
} 
?>

I am trying to apply this to my food rating site.

Here is what i understand

  1. To start off with the system we need to assign a base score for all the dishes.
  2. We have 4 variables S1, S2, R1, R2 (S= score, R = rank)
  3. When rating between two dishes if i press the first dish. what will be the the S1 and S2 ? will it be 1-0 ?
  4. What if i add another dish after 10k battles ? since i will be assigning a base score for it will it fair better ?
  5. How can i stop a score of a Dish not to go below 0.

Here is PHP implementation of the same. Can you help me understand the 4 variables and how should i use it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自控 2024-11-07 03:56:50

GitHub 上是我发现的 ELO 评级系统的最佳 php 类: https://github.com /Chovanec/elo- rating

用法:

// 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);

here on GitHub is the best php class for ELO rating system i've ever found: 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);
久隐师 2024-11-07 03:56:50

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

希望这会有所帮助

1.S1 should be the current score of the first dish and S2 for the second dish you are comparing with

2.R1 is the rank of the current dish and R2 is the current rank of the second dish

2.if its not fair this system wouldn't be used in global games

3.you probably are going to use a database to save scores so lets say it should be like this

if($elo_calcualtor->rating(1,2,1,2)['p1'] < 0){$current_dish_score = 0;}

finally
you should make the rating starts from ten, so it won't go below 0 and most likely won't go higher than 20

hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文