Skip to content

Instantly share code, notes, and snippets.

@r-moeritz
Created July 22, 2014 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-moeritz/a0ceae1933d8a4f1adf2 to your computer and use it in GitHub Desktop.
Save r-moeritz/a0ceae1933d8a4f1adf2 to your computer and use it in GitHub Desktop.
TrueSkill examples
var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var trueskill = require('com.izaakschroeder.trueskill').create(1000);
console.log('mu: %d, sigma: %d, beta: %d, tau: %d',
trueskill.mu.toFixed(3),
trueskill.sigma.toFixed(3),
trueskill.beta.toFixed(3),
trueskill.tau.toFixed(3));
var p1 = { name: 'Justin',
rating: trueskill.createRating()
};
var p2 = { name: 'James',
rating: trueskill.createRating()
};
var p3 = { name: 'Garth',
rating: trueskill.createRating()
};
function playMatch(players, results) {
var teams = players.map(function(player) { return [player.rating] });
newRatings = trueskill.update(teams, results);
players.forEach(function (player, i) {
player.rating = newRatings[i][0];
});
}
console.log('Initial ratings: %s: (%d %d), %s: (%d %d), %s: (%d %d)',
p1.name, p1.rating.mu.toFixed(3), p1.rating.sigma.toFixed(3),
p2.name, p2.rating.mu.toFixed(3), p2.rating.sigma.toFixed(3),
p3.name, p3.rating.mu.toFixed(3), p3.rating.sigma.toFixed(3));
// Justin vs. James - W:9, D:9, L:2
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [1,0]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [1,0]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,1]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,0]);
playMatch([p1, p2], [0,1]);
// Justin vs. Garth - W:4, D:12, L:4
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [1,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,1]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [1,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,1]);
playMatch([p1, p3], [1,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,1]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [1,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,0]);
playMatch([p1, p3], [0,1]);
// James vs. Garth - W:3, D:7, L:10
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [0,1]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [0,1]);
playMatch([p2, p3], [0,1]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [1,0]);
playMatch([p2, p3], [0,0]);
playMatch([p2, p3], [0,0]);
console.log('Final ratings: %s: (%d %d), %s: (%d %d), %s: (%d %d)',
p1.name, p1.rating.mu.toFixed(3), p1.rating.sigma.toFixed(3),
p2.name, p2.rating.mu.toFixed(3), p2.rating.sigma.toFixed(3),
p3.name, p3.rating.mu.toFixed(3), p3.rating.sigma.toFixed(3));
readline.question("Press any key to exit...",
function (_) { readline.close(); });
#! python
import trueskill
from trueskill import Rating, rate_1vs1
mu = 1000
sigma = mu/3
beta = sigma/2
tau = sigma/100
print('mu: %.3f, sigma: %.3f, beta: %.3f, tau: %.3f' %
(mu, sigma, beta, tau))
trueskill.setup(mu, sigma, beta, tau)
justin,james,garth = Rating(), Rating(), Rating()
print('Initial ratings: Justin: (%.3f %.3f), James: (%.3f %.3f), Garth: (%.3f %.3f)'
% (justin.mu, justin.sigma, james.mu, james.sigma, garth.mu, garth.sigma))
# Justin vs. James - W:9, D:9, L:2
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james, drawn=True)
james,justin = rate_1vs1(james, justin)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
james,justin = rate_1vs1(james, justin)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james, drawn=True)
justin,james = rate_1vs1(justin, james)
# Justin vs. Garth - W:4, D:12, L:4
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth, drawn=True)
garth,justin = rate_1vs1(garth, justin)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth)
justin,garth = rate_1vs1(justin, garth, drawn=True)
garth,justin = rate_1vs1(garth, justin)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth)
garth,justin = rate_1vs1(garth, justin)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth)
justin,garth = rate_1vs1(justin, garth, drawn=True)
garth,justin = rate_1vs1(garth, justin)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth, drawn=True)
justin,garth = rate_1vs1(justin, garth)
# James vs. Garth - W:3, D:7, L:10
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
james,garth = rate_1vs1(james, garth, drawn=True)
james,garth = rate_1vs1(james, garth)
james,garth = rate_1vs1(james, garth, drawn=True)
garth,james = rate_1vs1(garth,james)
garth,james = rate_1vs1(garth,james)
james,garth = rate_1vs1(james, garth)
james,garth = rate_1vs1(james, garth)
james,garth = rate_1vs1(james, garth, drawn=True)
james,garth = rate_1vs1(james, garth, drawn=True)
james,garth = rate_1vs1(james, garth, drawn=True)
garth,james = rate_1vs1(garth,james)
james,garth = rate_1vs1(james, garth, drawn=True)
james,garth = rate_1vs1(james, garth, drawn=True)
print('Final ratings: Justin: (%.3f %.3f), James: (%.3f %.3f), Garth: (%.3f %.3f)'
% (justin.mu, justin.sigma, james.mu, james.sigma, garth.mu, garth.sigma))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment