summaryrefslogtreecommitdiff
path: root/lib/scoring/fibonacci_peer_with_blowout.rb
blob: f592540297ed22fdc547d637fc733c4d36b59bc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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