diff options
-rw-r--r-- | lib/scoring/README.md | 10 | ||||
-rw-r--r-- | lib/scoring/ScoringAlgorithm.rb | 6 | ||||
-rw-r--r-- | lib/scoring/fibonacci_peer_with_blowout.rb | 11 |
3 files changed, 16 insertions, 11 deletions
diff --git a/lib/scoring/README.md b/lib/scoring/README.md new file mode 100644 index 0000000..95dd5e0 --- /dev/null +++ b/lib/scoring/README.md @@ -0,0 +1,10 @@ +Files in this directory should be modules implementing the following +interface: + + - `stats_needed() => Array[i]=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/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb deleted file mode 100644 index f2afa6f..0000000 --- a/lib/scoring/ScoringAlgorithm.rb +++ /dev/null @@ -1,6 +0,0 @@ -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 index 8043fb7..21ffab1 100644 --- a/lib/scoring/fibonacci_peer_with_blowout.rb +++ b/lib/scoring/fibonacci_peer_with_blowout.rb @@ -1,19 +1,20 @@ module Scoring module FibonacciPeerWithBlowout - def stats_needed + def self.stats_needed return [:votes] end - def score(match, interface) + def self.score(match) scores = {} match.players.each do |player| - scores[player.user_name] = score_user(interface.get_statistic(match, player, :votes), match.win?(player), match.blowout) + scores[player] = self.score_user(match.statistics.where(user: player, name: :votes).first, match.win?(player), match.blowout) end scores end - private - def score_user(votes, win, blowout) + 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 |