#!/usr/bin/perl # Make a pool of random players with known true ratings between 1000 to 2000 # Set the calculated ratings to be the same as the true ratings # Play games between randomly selected players with the outcome # determined by the true ratings # Calculate the system error require "func.pl"; runTests(); sub makePlayers{ local($i); for($i=0;$i<$MaxPlayers;$i++){ $Tr[$i] = int(rand(1000)) + 1000; $Or[$i] = $Tr[$i]; $Wp[$i] = 0.5; } } sub setCalc2True{ @Cr = @Tr; @Cor = @Or; @Cwp = @Wp; } sub setCalc2Init{ local($i); for($i=0;$i<$MaxPlayers;$i++){ $Cr[$i] = 1500; $Cor[$i] = 1500; $Cwp[$i] = 0.5; } } sub updateRatings{ local($p1, $p2, $w1) = @_; local($r1, $r2, $or1, $or2, $wp1, $wp2); ($r1, $or1, $wp1) = newRating($Cr[$p1], $Cr[$p2], $w1, $Cor[$p1], $Cwp[$p1]); ($r2, $or2, $wp2) = newRating($Cr[$p2], $Cr[$p1], 1 - $w1, $Cor[$p2], $Cwp[$p2]); $Cr[$p1] = $r1; $Cr[$p2] = $r2; $Cor[$p1] = $or1; $Cor[$p2] = $or2; $Cwp[$p1] = $wp1; $Cwp[$p2] = $wp2; } sub newRating{ local($mr, $or, $iwon, $aor, $mwp) = @_; local($rdiff, $k, $nr); local($cf, $nor, $nwp); $rdiff = ($or - $mr)/400; $wp = 1.0/(1.0 + 10.0**$rdiff); $cf = $wp - 0.5; $cf = 1 - 4*$cf*$cf; $nor = (25*$aor + $cf*$or)/(25+$cf); $nwp = (25*$mwp + $cf*$iwon)/(25+$cf); # if ($nwp < 0.01){ $nwp = 0.01; } # if ($nwp > 0.99){ $nwp = 0.99; } #print " $nwp = (15*$wp + $cf*$iwon)/(15+$cf); \n"; #print "$nwp $wp $cf\n"; $k = 1.0/$nwp - 1.0; $nr = $nor - 400*log($k)/log(10); return ($nr, $nor, $nwp); }