Skip to content

Instantly share code, notes, and snippets.

@melvinzhang
Last active January 4, 2016 18:59
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 melvinzhang/8664214 to your computer and use it in GitHub Desktop.
Save melvinzhang/8664214 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# read from stdin lines in the following format:
# <player0 name> <player1 name> <winner>
# where <winner> is 0 if player0 wins and 1 if player1 wins
# https://github.com/goshrine/whole_history_rating
require 'whole_history_rating'
# w = 0 for static ratings aka bayeselo
@whr = WholeHistoryRating::Base.new(:w2 => 0)
# WholeHistoryRating::Base#create_game arguments: black player name, white player name, winner, day number, handicap
# Handicap should generally be less than 500 elo
ARGF.each do |line|
tokens = line.split(' ')
winner =
if (tokens[2] == "0")
"B"
else (tokens[2] == "1")
"W"
end
@whr.create_game(tokens[0], tokens[1], winner, 0, 0)
end
# Iterate the WHR algorithm towards convergence with more players/games, more iterations are needed.
@whr.iterate(1000)
players = @whr.players.values.select {|p| p.days.count > 0}
players.sort_by { |p| p.days.last.gamma }.each_with_index do |p,idx|
if p.days.count > 0
puts "#{p.name}\t#{p.days[0].gamma}\t#{p.days[0].uncertainty}"
end
end
X Y 0
X Y 1
X Y 1
Y Z 0
Y Z 1
Y Z 1
Z X 0
Z X 1
Z X 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment