class EloDemo::Tournment

Constants

NAMES

Attributes

players[R]

Public Class Methods

new() click to toggle source
# File lib/elo_demo.rb, line 20
def initialize
  srand(666)

  @players = []
  10.times do |i|
    @players << Player.new(name: NAMES[i])
  end
end

Public Instance Methods

mark_win(p1, p2) click to toggle source
# File lib/elo_demo.rb, line 44
def mark_win(p1, p2)
  p1.games_played += 1
  p2.games_played += 1
  p1.wins += 1
  p2.loses += 1
  p1.elo_player.wins_from(p2.elo_player)
end
print_elo_ranking() click to toggle source
print_line(p, index) click to toggle source
print_naive_ranking() click to toggle source
print_ranking() click to toggle source
run!() click to toggle source
# File lib/elo_demo.rb, line 29
def run!
  1000.times do
    player_0 = @players[rand(1..players.size) - 1]
    player_1 = @players[rand(1..players.size) - 1]
    game = [player_0, player_1]
    winner = game[rand(0..1)]

    if player_0.name == winner.name
      mark_win(player_0, player_1)
    else
      mark_win(player_1, player_0)
    end
  end
end
sorted_by_elo() click to toggle source
# File lib/elo_demo.rb, line 79
def sorted_by_elo
  players.sort_by { |p| p.elo_player.rating }.reverse
end
sorted_by_naive() click to toggle source
# File lib/elo_demo.rb, line 75
def sorted_by_naive
  players.sort_by { |p| p.wins - p.loses }.reverse
end