summaryrefslogtreecommitdiff
path: root/lib/scoring
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scoring')
-rw-r--r--lib/scoring/README.md15
-rw-r--r--lib/scoring/fibonacci_peer_with_blowout.rb28
-rw-r--r--lib/scoring/marginal_peer.rb15
-rw-r--r--lib/scoring/winner_takes_all.rb20
4 files changed, 78 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..f592540
--- /dev/null
+++ b/lib/scoring/fibonacci_peer_with_blowout.rb
@@ -0,0 +1,28 @@
+module Scoring
+ module FibonacciPeerWithBlowout
+ def self.stats_needed
+ return [:votes, :win, :blowout]
+ end
+
+ def self.score(match)
+ scores = {}
+ match.players.each do |player|
+ stats = Statistics.where(user: player, match: match)
+
+ votes = stats.where(name: :votes ).first
+ win = stats.where(name: :win ).first
+ blowout = stats.where(name: :blowout).first
+
+ scores[player] = self.score_user(votes, win, 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