Games_Chess
[ class tree: Games_Chess ] [ index: Games_Chess ] [ all elements ]

Source for file Player.php

Documentation is available at Player.php

  1. <?php
  2. class Games_Chess_Player
  3. {
  4.     var $name;
  5.     var $games = array();
  6.     var $ICCrating;
  7.     function Games_Chess_Player($name$gamesPlayed)
  8.     {
  9.         $this->name $name;
  10.         foreach ($gamesPlayed as $game{
  11.             $this->addGame($game);
  12.         }
  13.     }
  14.  
  15.     /**
  16.      * @param Games_Chess_Result 
  17.      * @param white|blackwhich side this player played
  18.      * @link http://www.chessclub.com/help/ratings
  19.      */
  20.     function _calculateICCRating($game$played)
  21.     {
  22.         if (!isset($this->ICCRating)) {
  23.             $this->ICCRating = 1600;
  24.         }
  25.         $self $this->ICCRating;
  26.         $opponent $game->{$played == 'white' 'black' 'white'};
  27.         if ($opponent['count'< 20{
  28.             // opponent is provisional
  29.             $K = 32 * (1 + $opponent['count']/ 21;
  30.             $extra = 1/5 * (1600 - $self);
  31.         else {
  32.             $K = 32;
  33.             $extra = 0;
  34.         }
  35.         if ($this->gamesPlayed(< 20{
  36.             // provisional
  37.             $rating $opponent['rating'(400 * $game->result);
  38.             $unaverage count($this->games$this->ICCRating;
  39.             $this->ICCRating = ($unaverage $rating(count($this->games+ 1$extra;
  40.             return;
  41.         else {
  42.             $rating $opponent['rating'];
  43.             $this->ICCRating = $self +
  44.                 $K (
  45.                     $game->result -
  46.                     1 / (
  47.                             1 + pow(10($rating $self/ 400)
  48.                         )
  49.                 );
  50.         }
  51.     }
  52.  
  53.     function addGame($game)
  54.     {
  55.         if ($game->white['name'$this->name{
  56.             $this->_calculateICCRating($game'white');
  57.             $this->games['W'$game;
  58.         elseif ($game->black['name'$this->name{
  59.             $this->_calculateICCRating($game'black');
  60.             $this->games['B'$game;
  61.         }
  62.     }
  63. }
  64. ?>

Documentation generated on Mon, 11 Mar 2019 14:28:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.