# Php elo class, please rate.

• 06-11-2013, 07:26 AM
dreaz
Hey! I made this class the calc elo rating and i whould love so get some feed back, what i can do better and stuff.
Im using it for a copy of facemash. master.aml.dk
Code:
PHP Code:

``` <?php     /********************************             © Andreas Myrup             2013 @ Medieskolerne     ********************************/       /******************************************         Desc:             Class for calculating elo ratings     ******************************************/     class elo{         /* Rating = The two rating of the players */         public \$ratingA;         public \$ratingB;         /* The change that player A/B win (between 0-1, 1=100% ) */         protected \$chanceA;         protected \$chanceB;         /* The new ratings! */         protected \$newRatingA;         protected \$newRatingB;         /*************************************             Desc:                 Assasgin RatingA and RatingB         *************************************/         public function __construct(\$Ra,\$Rb)         {             \$this->ratingA = \$Ra;             \$this->ratingB = \$Rb;         }         /*********************************             Desc:                 Elo chance.                 The change that a or b will win                 exampel:                     ChanceA = 0.75                     ChanceB = 0.25                     A have a 75% change of winning                     B have a 25% change of loseing             Fromel:                 1/(1+10^(ratingA - ratingB)/400)             @Parm:                 \$Ra = Rating A                 \$Ra = Rating B         *********************************/         public function chance()         {             \$resultA = 1/(1+pow(10,(\$this->ratingA-\$this->ratingB)/400));             \$this->chanceA = \$resultA;             \$resultB = 1/(1+pow(10,(\$this->ratingB-\$this->ratingA)/400));             \$this->chanceB = \$resultB;         }         /*****************************************             Desc:                 The new ratings!             Formel:                 New rating = Or+K(Wl-Ec)                 Or = Old rating                 K = K-factor(depents on the players current rating)                 Wl = Win/lose, 1=Win, 0=Lose                 Ec = Expected change of winning (in this class \$changeA and \$changeB)             @Parms:                 \$Wa = Win/lose, 1/0                 \$Wb = Win/lose, 1/0             Return:                 Array                     0 = new rating A                     1 = new rating B         *****************************************/         public function rating(\$Wa,\$Wb)         {             if(\$this->ratingA <= 2100){                 \$this->newRatingA = \$this->ratingA + 32*(\$Wa - \$this->chanceA);             }elseif(\$this->ratingA > 2100 && \$Ra < 2400){                 \$this->newRatingA = \$this->ratingA + 24*(\$Wa - \$this->chanceA);             }elseif(\$this->ratingA >= 2400){                 \$this->newRatingA = \$this->ratingA + 16*(\$Wa - \$this->chanceA);             }             if(\$this->ratingB <= 2100){                 \$this->newRatingB = \$this->ratingB + 32*(\$Wb - \$this->chanceB);             }elseif(\$this->ratingB > 2100 && \$this->ratingB < 2400){                 \$this->newRatingB = \$this->ratingB + 24*(\$Wb - \$this->chanceB);             }elseif(\$this->ratingB >= 2400){                 \$this->newRatingB = \$this->ratingB + 1*(\$Wb - \$this->chanceB);             }             \$result = array(                 0 => round(\$this->newRatingA,2),                 1 => round(\$this->newRatingB,2)             );             return \$result;         }     } ```

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.09233 seconds
• Memory Usage 2,417KB
• Queries Executed 11 (?)
Template Usage (20):
• (1)bbcode_php_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates