Class: Glicko2::Player
- Inherits:
-
Object
- Object
- Glicko2::Player
- Defined in:
- lib/glicko2/player.rb
Overview
Calculates a new Glicko2 ranking based on a seed object and game outcomes.
The example from the Glicko2 paper, where a player wins against the first opponent, but then looses against the next two:
Rating = Struct.new(:rating, :rating_deviation, :volatility)
player_seed = Rating.new(1500, 200, 0.06)
opponent1_seed = Rating.new(1400, 30, 0.06)
opponent2_seed = Rating.new(1550, 100, 0.06)
opponent3_seed = Rating.new(1700, 300, 0.06)
player = Glicko2::Player.from_obj(player_seed)
opponent1 = Glicko2::Player.from_obj(opponent1_seed)
opponent2 = Glicko2::Player.from_obj(opponent2_seed)
opponent3 = Glicko2::Player.from_obj(opponent3_seed)
new_player = player.generate_next([opponent1, opponent2, opponent3],
[1, 0, 0])
new_player.update_obj
puts player_seed
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
Class Method Summary collapse
-
.from_obj(obj, config = nil) ⇒ Player
Create a Player from a seed object, converting from Glicko ratings to Glicko2.
Instance Method Summary collapse
-
#generate_next(others, scores) ⇒ Player
Create new Player with updated values.
-
#initialize(rating, obj = nil) ⇒ Player
constructor
A new instance of Player.
- #mean ⇒ Object
- #standard_deviation ⇒ Object (also: #sd)
- #to_s ⇒ Object
-
#update_obj ⇒ Object
Update seed object with this player’s values.
- #volatility ⇒ Object
Constructor Details
#initialize(rating, obj = nil) ⇒ Player
Returns a new instance of Player.
43 44 45 46 |
# File 'lib/glicko2/player.rb', line 43 def initialize(, obj=nil) @rating = @obj = obj end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
26 27 28 |
# File 'lib/glicko2/player.rb', line 26 def obj @obj end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating.
26 27 28 |
# File 'lib/glicko2/player.rb', line 26 def @rating end |
Class Method Details
.from_obj(obj, config = nil) ⇒ Player
Create a Glicko2::Player from a seed object, converting from Glicko ratings to Glicko2.
33 34 35 36 37 |
# File 'lib/glicko2/player.rb', line 33 def self.from_obj(obj, config=nil) = Rating.(obj., obj., obj.volatility, config) new(, obj) end |
Instance Method Details
#generate_next(others, scores) ⇒ Player
Create new Glicko2::Player with updated values.
This method will not modify any objects that are passed into it.
56 57 58 59 60 61 62 63 |
# File 'lib/glicko2/player.rb', line 56 def generate_next(others, scores) if others.compact.length < 1 generate_next_without_games else others = others.compact.map{ |other| other. } generate_next_with_games(others, scores) end end |
#mean ⇒ Object
73 74 75 |
# File 'lib/glicko2/player.rb', line 73 def mean .mean end |
#standard_deviation ⇒ Object Also known as: sd
77 78 79 |
# File 'lib/glicko2/player.rb', line 77 def standard_deviation .standard_deviation end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/glicko2/player.rb', line 86 def to_s "#<Player rating=#{}, obj=#{obj}>" end |
#update_obj ⇒ Object
Update seed object with this player’s values
66 67 68 69 70 71 |
# File 'lib/glicko2/player.rb', line 66 def update_obj = . @obj. = .mean @obj. = .standard_deviation @obj.volatility = volatility end |
#volatility ⇒ Object
82 83 84 |
# File 'lib/glicko2/player.rb', line 82 def volatility .volatility end |