PHP Facemash ELO Rating Class / Function

I got the next ELO class on the 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 on my food ranking site.

Here is what i understand

  • To start with the system, we need to assign a base score for all dishes.
  • We have 4 variables S1, S2, R1, R2 (S = score, R = rank)
  • When evaluating between two dishes, if I click the first dish. What will be S1 and S2? will it be 1-0?
  • What if I add another dish after the 10k battles? since I will assign a basic assessment, will it be better?
  • How can I stop the rating of a dish so as not to fall below 0.

This is where the PHP implementation runs. Can you help me understand 4 variables and how to use them?

+6
source share
2 answers

here on GitHub is the best php class for the ELO rating system I've ever found: https://github.com/Chovanec/elo-rating

APPLICATION:

 // 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); 
+5
source

1.S1 should be the current score of the first course and S2 for the second course that you compare with

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

2. If it is not fair, this system will not be used in global games.

3. Perhaps you are going to use the database to save points, so let's say that it should be so.

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

finally, you must make a rating starting at ten, so it will not fall below 0 and most likely will not be higher than 20

hope this helps

+1
source

Source: https://habr.com/ru/post/885597/


All Articles