Skip to content
Browse files

notes

  • Loading branch information...
1 parent 9652aed commit 8dde8bc052b523491fc3a18dd624939623cd8790 @agilion committed Feb 11, 2012
Showing with 4 additions and 7 deletions.
  1. +1 −0 models/game.rb
  2. +2 −6 models/player.rb
  3. +1 −1 test/models/player_test.rb
View
1 models/game.rb
@@ -9,6 +9,7 @@ def finalize!
self.loser = find_the_loser
self.completed = true
self.completed_at = Time.now
+ # Player.rank_players!
save
end
View
8 models/player.rb
@@ -15,12 +15,7 @@ def accept_challenge!(game)
end
def calculate_rank!
- # Python implementation of Gravity Algorithm
- # http://amix.dk/blog/post/19574
- # (wins.count - 1) / pow((wins.last.completed_at.hour + 2), GRAVITY) if wins.any?
- #
- # (10 - 1) / ((12 - 2)**1.8)
- #
+ # Based on a Python implementation of Gravity Algorithm used to rank "Hotness" of Hacker News Articles. http://amix.dk/blog/post/19574
player_rank = if wins.empty?
0.0
else
@@ -29,6 +24,7 @@ def calculate_rank!
update_attribute(:rank, player_rank)
end
+ # Rerank all players (trigger when a new game has been finalized)
def self.rank_players!
Player.all.each do |player|
player.calculate_rank!
View
2 test/models/player_test.rb
@@ -45,7 +45,7 @@ def test_calculate_player_rank
Game.create(:challenger => @player_b, :challengee => @player_a, :challenger_score => 21, :challengee_score => 20, :winner => @player_b, :loser => @player_b, :completed_at => Time.now)
end
- # TODO Add more games and more players to really test the expected ranks between various players
+ # TODO Add more games and more players to really test the expected ranks between various players with multiple wins/losses!
Player.rank_players!
@player_a = Player.find_by_full_name("Sean Behan")

0 comments on commit 8dde8bc

Please sign in to comment.
Something went wrong with that request. Please try again.