summaryrefslogtreecommitdiff
path: root/lib/scoring
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scoring')
-rw-r--r--lib/scoring/ScoringAlgorithm.rb6
-rw-r--r--lib/scoring/fibonacci_peer_with_blowout.rb21
-rw-r--r--lib/scoring/marginal_peer.rb15
-rw-r--r--lib/scoring/winner_takes_all.rb20
4 files changed, 62 insertions, 0 deletions
diff --git a/lib/scoring/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb
new file mode 100644
index 0000000..f2afa6f
--- /dev/null
+++ b/lib/scoring/ScoringAlgorithm.rb
@@ -0,0 +1,6 @@
+module Scoring
+ class ScoringAlgorithm
+ def self.score(match, interface)
+ end
+ end
+end
diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb
new file mode 100644
index 0000000..8043fb7
--- /dev/null
+++ b/lib/scoring/fibonacci_peer_with_blowout.rb
@@ -0,0 +1,21 @@
+module Scoring
+ module FibonacciPeerWithBlowout
+ def stats_needed
+ return [:votes]
+ end
+
+ def score(match, interface)
+ scores = {}
+ match.players.each do |player|
+ scores[player.user_name] = score_user(interface.get_statistic(match, player, :votes), match.win?(player), match.blowout)
+ end
+ scores
+ end
+
+ private
+ def 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..13e1796
--- /dev/null
+++ b/lib/scoring/marginal_peer.rb
@@ -0,0 +1,15 @@
+module Scoring
+ module MarginalPeer
+ def stats_needed
+ return [:rating]
+ end
+
+ def 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..517dfd6
--- /dev/null
+++ b/lib/scoring/winner_takes_all.rb
@@ -0,0 +1,20 @@
+module Scoring
+ module WinnerTakesAll
+ def stats_needed
+ return []
+ end
+
+ def score(match, interface)
+ scores = {}
+ match.players.each do |player|
+ scores[player.user_name] = score_user(match.win?(player))
+ end
+ scores
+ end
+
+ private
+ def score_user(win)
+ win.nil? ? 0.5 : win ? 1 : 0
+ end
+ end
+end