Class: Elo::Player
Overview
A player. You need at least two play a Game.
Instance Method Summary collapse
-
#games ⇒ Object
A list of games played by the player.
-
#games_played ⇒ Object
The number of games played is needed for calculating the K-factor.
- #inspect ⇒ Object
-
#k_factor ⇒ Object
Calculates the K-factor for the player.
-
#loses_from(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
-
#plays_draw(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
-
#pro? ⇒ Boolean
FIDE regulations specify that once you reach a pro status (see
pro_rating?), you are considered a pro for life. -
#pro_rating? ⇒ Boolean
Is the player considered a pro, because his/her rating crossed the threshold configured? This is needed for calculating the K-factor.
-
#rating ⇒ Object
The rating you provided, or the default rating from configuration.
-
#save ⇒ Object
in a database or something like that.
-
#starter? ⇒ Boolean
Is the player just starting? Provide the boundry for the amount of games played in the configuration.
-
#versus(other_player, options = {}) ⇒ Object
Start a game with another player.
-
#wins_from(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
Methods included from Helper
Instance Method Details
#games ⇒ Object
A list of games played by the player.
19 20 21 |
# File 'lib/elo/player.rb', line 19 def games @games ||= [] end |
#games_played ⇒ Object
The number of games played is needed for calculating the K-factor.
14 15 16 |
# File 'lib/elo/player.rb', line 14 def games_played @games_played ||= games.size end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/elo/player.rb', line 93 def inspect "player" end |
#k_factor ⇒ Object
Calculates the K-factor for the player. Elo allows you specify custom Rules (see Elo::Configuration).
You can set it manually, if you wish:
Elo::Player.new(:k_factor => 10)
This stops this player from using the K-factor rules.
61 62 63 64 65 66 67 |
# File 'lib/elo/player.rb', line 61 def k_factor return @k_factor if @k_factor Elo.config.applied_k_factors.each do |rule| return rule[:factor] if instance_eval(&rule[:rule]) end Elo.config.default_k_factor end |
#loses_from(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
89 90 91 |
# File 'lib/elo/player.rb', line 89 def loses_from(other_player, = {}) versus(other_player, ).lose end |
#plays_draw(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
83 84 85 |
# File 'lib/elo/player.rb', line 83 def plays_draw(other_player, = {}) versus(other_player, ).draw end |
#pro? ⇒ Boolean
FIDE regulations specify that once you reach a pro status (see pro_rating?), you are considered a pro for life.
You might need to specify it manually, when depending on external persistence of players.
Elo::Player.new(:pro => true)
43 44 45 |
# File 'lib/elo/player.rb', line 43 def pro? !!@pro end |
#pro_rating? ⇒ Boolean
Is the player considered a pro, because his/her rating crossed the threshold configured? This is needed for calculating the K-factor.
25 26 27 |
# File 'lib/elo/player.rb', line 25 def >= Elo.config. end |
#rating ⇒ Object
The rating you provided, or the default rating from configuration
9 10 11 |
# File 'lib/elo/player.rb', line 9 def ||= Elo.config. end |
#save ⇒ Object
in a database or something like that. This method will be called when a result is known.
50 51 |
# File 'lib/elo/player.rb', line 50 def save end |
#starter? ⇒ Boolean
Is the player just starting? Provide the boundry for the amount of games played in the configuration. This is needed for calculating the K-factor.
32 33 34 |
# File 'lib/elo/player.rb', line 32 def starter? games_played < Elo.config.starter_boundry end |
#versus(other_player, options = {}) ⇒ Object
Start a game with another player. At this point, no result is known and nothing really happens.
71 72 73 |
# File 'lib/elo/player.rb', line 71 def versus(other_player, = {}) Game.new(.merge(:one => self, :two => other_player)).calculate end |
#wins_from(other_player, options = {}) ⇒ Object
Start a game with another player and set the score immediately.
77 78 79 |
# File 'lib/elo/player.rb', line 77 def wins_from(other_player, = {}) versus(other_player, ).win end |