Jump to content

PHP ELO Calculator


shmeeg

Recommended Posts

There's one that I've found...but I'm just struggling applying it to what I'm doing.

 

The idea is to have x number of teams, all starting with 1000 Ranking points. If team A plays team B and wins 1-0, team A should increase by 30 points, and team B should decrease by 30 points? (I think.. :D)

Then to rank the teams based on their points.

 

The main problem is, I'd like to use a form to edit the teams. I've got as far as a drop down menu to choose the teams, and then Home goals and Away goals. It will already define what is a win/draw/loss.

 

The Calculator code is:

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.