summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrewMurrell <amurrel@purdue.edu>2014-04-22 01:46:13 -0400
committerAndrewMurrell <amurrel@purdue.edu>2014-04-22 01:46:13 -0400
commitaa8437947b28dda73bcfaf3caccb738e5e2f48b3 (patch)
tree8d1a4994bb3fab9b4e89712ab43b416cdfeef3ed /lib
parentd3bee0f1ce0c5dc3fa741338bc6d9914e9e92787 (diff)
Made Scoring Algorithm files use the statistics interface and accept matches for a more general approach.
Diffstat (limited to 'lib')
-rw-r--r--lib/scoring_algorithms/FibonacciPeerWithBlowout.rb16
-rw-r--r--lib/scoring_algorithms/MarginalPeer.rb15
-rw-r--r--lib/scoring_algorithms/Recommended.rb8
-rw-r--r--lib/scoring_algorithms/ScoringAlgorithm.rb8
-rw-r--r--lib/scoring_algorithms/ScoringAlgorithms.rb28
-rw-r--r--lib/scoring_algorithms/WinnerTakesAll.rb16
6 files changed, 55 insertions, 36 deletions
diff --git a/lib/scoring_algorithms/FibonacciPeerWithBlowout.rb b/lib/scoring_algorithms/FibonacciPeerWithBlowout.rb
new file mode 100644
index 0000000..19ac9a7
--- /dev/null
+++ b/lib/scoring_algorithms/FibonacciPeerWithBlowout.rb
@@ -0,0 +1,16 @@
+require 'ScoringAlgorithm'
+
+class FibonacciPeerWithBlowout < ScoringAlgorithm
+
+ def self.score(match, interface)
+ match.players.each do |player|
+ scores[player.user_name] = scoreUser(interface.getStatistic(match, player, :votes), match.win?(player), match.blowout)
+ end
+ scores
+ end
+
+ def self.scoreUser(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 \ No newline at end of file
diff --git a/lib/scoring_algorithms/MarginalPeer.rb b/lib/scoring_algorithms/MarginalPeer.rb
new file mode 100644
index 0000000..0e1cfa8
--- /dev/null
+++ b/lib/scoring_algorithms/MarginalPeer.rb
@@ -0,0 +1,15 @@
+require 'ScoringAlgorithm'
+
+class MarginalPeer < ScoringAlgorithm
+
+ def self.score(match, interface)
+ match.players.each do |player|
+ scores[player.user_name] = scoreUser(interface.getStatistic(match, player, rating))
+ end
+ scores
+ end
+
+ def self.score(rating)
+ rating
+ end
+end \ No newline at end of file
diff --git a/lib/scoring_algorithms/Recommended.rb b/lib/scoring_algorithms/Recommended.rb
deleted file mode 100644
index 8033bd2..0000000
--- a/lib/scoring_algorithms/Recommended.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class Recommended
- def self.score(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
-
-#puts Recommended.score(4, true, false)
diff --git a/lib/scoring_algorithms/ScoringAlgorithm.rb b/lib/scoring_algorithms/ScoringAlgorithm.rb
new file mode 100644
index 0000000..6277da8
--- /dev/null
+++ b/lib/scoring_algorithms/ScoringAlgorithm.rb
@@ -0,0 +1,8 @@
+module Leaguer
+ module Scoring
+ class ScoringAlgorithm
+ def self.score(match, interface)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/scoring_algorithms/ScoringAlgorithms.rb b/lib/scoring_algorithms/ScoringAlgorithms.rb
deleted file mode 100644
index 7f8ec12..0000000
--- a/lib/scoring_algorithms/ScoringAlgorithms.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-class ScoringAlgorithm
- def self.score(*args)
- end
-end
-
-class FibonacciPeerWithBlowout < ScoringAlgorithm
- def self.score(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
-
-class WinnerTakesAll < ScoringAlgorithm
- def self.score(win)
- win.nil? ? 0.5 : win ? 1 : 0
- end
-end
-
-class MarginalPeer < ScoringAlgorithm
- def self.score(rating)
- rating
- end
-end
-
-
-#puts Recommended.score(4, true, false)
-#puts WinnerTakesAll.score(nil)
-#puts WinnerTakesAll.score(true)
diff --git a/lib/scoring_algorithms/WinnerTakesAll.rb b/lib/scoring_algorithms/WinnerTakesAll.rb
new file mode 100644
index 0000000..ad2471b
--- /dev/null
+++ b/lib/scoring_algorithms/WinnerTakesAll.rb
@@ -0,0 +1,16 @@
+require 'ScoringAlgorithm'
+
+class WinnerTakesAll < ScoringAlgorithm
+
+ def self.score(match, interface)
+ match.players.each do |player|
+ scores[player.user_name] = scoreUser(match.win?(player))
+ end
+ scores
+ end
+
+
+ def self.score(win)
+ win.nil? ? 0.5 : win ? 1 : 0
+ end
+end \ No newline at end of file