#!/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; } } sub setCalc2True{ @Cr = @Tr; } sub setCalc2Init{ local($i); for($i=0;$i<$MaxPlayers;$i++){ $Cr[$i] = 1500; } } sub updateRatings{ local($p1, $p2, $w1) = @_; local($r1, $r2); ($r1) = newRating($Cr[$p1], $Cr[$p2], $w1); ($r2) = newRating($Cr[$p2], $Cr[$p1], 1 - $w1); $Cr[$p1] = $r1; $Cr[$p2] = $r2; } sub newRating{ local($mr, $or, $iwon) = @_; local($rdiff, $wp, $k, $nr); $rdiff = ($or - $mr)/400; $wp = 1.0/(1.0 + 10.0**$rdiff); $k = 32; $nr = int($mr + $k*($iwon - $wp) + 0.5); return $nr; }