diff options
Diffstat (limited to 'lib/scoring')
-rw-r--r-- | lib/scoring/README.md | 15 | ||||
-rw-r--r-- | lib/scoring/fibonacci_peer_with_blowout.rb | 22 | ||||
-rw-r--r-- | lib/scoring/marginal_peer.rb | 15 | ||||
-rw-r--r-- | lib/scoring/winner_takes_all.rb | 20 |
4 files changed, 72 insertions, 0 deletions
diff --git a/lib/scoring/README.md b/lib/scoring/README.md new file mode 100644 index 0000000..dce71d0 --- /dev/null +++ b/lib/scoring/README.md @@ -0,0 +1,15 @@ +Scoring interface +================= + +Files in this directory should be _modules_ implementing the following +interface: + + - `stats_needed(Match) => Array[]=Symbol` + + Returns which statistics need to be collected for this scoring + algorithm. + + - `score(Match) => Hash[User]=Integer` + + User scores for this match, assuming statistics have been + collected. diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb new file mode 100644 index 0000000..21ffab1 --- /dev/null +++ b/lib/scoring/fibonacci_peer_with_blowout.rb @@ -0,0 +1,22 @@ +module Scoring + module FibonacciPeerWithBlowout + def self.stats_needed + return [:votes] + end + + def self.score(match) + scores = {} + match.players.each do |player| + scores[player] = self.score_user(match.statistics.where(user: player, name: :votes).first, match.win?(player), match.blowout) + end + scores + end + + protected + + def self.score_user(votes, win, blowout) + fibonacci = Hash.new { |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] } + fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7) + end + end +end diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb new file mode 100644 index 0000000..aa05f5e --- /dev/null +++ b/lib/scoring/marginal_peer.rb @@ -0,0 +1,15 @@ +module Scoring + module MarginalPeer + def self.stats_needed + return [:rating] + end + + def self.score(match, interface) + scores = {} + match.players.each do |player| + scores[player.user_name] = interface.get_statistic(match, player, :rating) + end + scores + end + end +end diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb new file mode 100644 index 0000000..57ddae6 --- /dev/null +++ b/lib/scoring/winner_takes_all.rb @@ -0,0 +1,20 @@ +module Scoring + module WinnerTakesAll + def self.stats_needed + return ["win"] + end + + def self.score(match, interface) + scores = {} + match.players.each do |player| + scores[player.user_name] = score_user(player.statistics.where(:match => match, :name => "win").value) + end + scores + end + + private + def self.score_user(win) + win.nil? ? 0.5 : win ? 1 : 0 + end + end +end |