/* ***** VERIFY SESSION ***** */ include "check_session.php"; if ( $username == "" ) header( "location:index.php" ); include "misc.php"; include "rating.php"; $min_req = 5; function rankcmp( $a, $b ) { /* at least five games to be in the rankings */ if ( $a[1] < $min_req ) return 1; else if ( $b[1] < $min_req ) return -1; if ( $a[5] == $b[5] ) { if ( $a[1] == $b[1] ) return 0; /* TODO: go on with wins/draws/losses */ else if ( $a[1] < $b[1] ) return 1; else return -1; } else { if ( $a[5] < $b[5] ) return 1; else return -1; } } /* grab stats from user file */ $userlist = file( $res_users ); $rankings = array(); $i = 0; foreach ( $userlist as $entry ) { $data = explode( ":", $entry ); $game_count = $data[1]+$data[2]+$data[3]; if ( count($data) < 5 ) { /* assume average strength of 1200 and use initial ELO formula */ $rating = 1200; if ( $game_count > 0 ) $rating += 700 * (($data[1]+0.5*$data[2])/$game_count - 0.5) * $game_count/($game_count+2); } else $rating = $data[4]; $rankings[$i++] = array( $data[0], $game_count, $data[1], $data[2], $data[3], $rating, $data[5], $data[6] ); } uasort($rankings,rankcmp); ?>
|
User Rankings
(You must have finished at least =$min_req?> games to show up.) |