Skip to content

Commit

Permalink
notes
Browse files Browse the repository at this point in the history
  • Loading branch information
agilion committed Feb 11, 2012
1 parent 9652aed commit 8dde8bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions models/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def finalize!
self.loser = find_the_loser
self.completed = true
self.completed_at = Time.now
# Player.rank_players!
save
end

Expand Down
8 changes: 2 additions & 6 deletions models/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion test/models/player_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8dde8bc

Please sign in to comment.