|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// ------------------------------------------------------------------------- // |
|
4
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
6
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
7
|
|
|
// (at your option) any later version. // |
|
8
|
|
|
// // |
|
9
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
10
|
|
|
// of supporting developers from this source code or any supporting // |
|
11
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
12
|
|
|
// original comment or credit authors. // |
|
13
|
|
|
// // |
|
14
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
15
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
16
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
17
|
|
|
// GNU General Public License for more details. // |
|
18
|
|
|
// // |
|
19
|
|
|
// You should have received a copy of the GNU General Public License // |
|
20
|
|
|
// along with this program; if not, write to the Free Software // |
|
21
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
22
|
|
|
// ------------------------------------------------------------------------ // |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Ratings functions specific to Linear rating system. |
|
26
|
|
|
* |
|
27
|
|
|
* @param mixed $white_rating |
|
28
|
|
|
* @param mixed $white_games |
|
29
|
|
|
* @param mixed $black_rating |
|
30
|
|
|
* @param mixed $black_games |
|
31
|
|
|
* @param mixed $pgn_result |
|
32
|
|
|
* @subpackage ratings |
|
33
|
|
|
* @package chess |
|
34
|
|
|
*/ |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Update the players' ratings for an individual game, using the Linear rating system. |
|
38
|
|
|
* |
|
39
|
|
|
* @param int $white_rating White's current rating |
|
40
|
|
|
* @param int $white_games Number of rated games that white has played |
|
41
|
|
|
* @param int $black_rating Black's current rating |
|
42
|
|
|
* @param int $black_games Number of rated games that black has played |
|
43
|
|
|
* @param string $pgn_result Game result: '1-0' (white won), '0-1' (black won) or '1/2-1/2' (draw) |
|
44
|
|
|
* @return array Array with two elements: |
|
45
|
|
|
* - $white_rating_new - white's new rating |
|
46
|
|
|
* - $black_rating_new - black's new rating |
|
47
|
|
|
*/ |
|
48
|
|
|
function chess_ratings_adj_linear($white_rating, $white_games, $black_rating, $black_games, $pgn_result) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
// compute score: +1 for win, 0 for draw, -1 for loss |
|
51
|
|
|
|
|
52
|
|
|
switch ($pgn_result) { |
|
53
|
|
|
case '1-0': |
|
54
|
|
|
$S = 1; |
|
55
|
|
|
break; |
|
56
|
|
|
case '1/2-1/2': |
|
57
|
|
|
default: // should not occur |
|
58
|
|
|
$S = 0; |
|
59
|
|
|
break; |
|
60
|
|
|
case '0-1': |
|
61
|
|
|
$S = -1; |
|
62
|
|
|
break; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return [$white_rating + $S * 10, $black_rating - $S * 10]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the number of provisional games used in the Linear rating system. |
|
70
|
|
|
* |
|
71
|
|
|
* @return int Number of provisional games |
|
72
|
|
|
*/ |
|
73
|
|
|
function chess_ratings_num_provisional_games_linear() |
|
74
|
|
|
{ |
|
75
|
|
|
return 2; |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.