diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/pages_controller.rb | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 8801654..e3838d2 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,8 +1,35 @@ class PagesController < ApplicationController def index @players = Player.all + end - group_size = Player.count - @groups = Player.order(Arel.sql("RANDOM()")).each_slice + def teampicker + @groups = maketeams end + + private + def random + Player.where("strikes < 4").order(Arel.sql("RANDOM()")) + end + + def maketeams + r = random.to_a + + case Player.count { |p| p.active? } + when 5 + [r.shift(3), r.shift(2)] + when 6 + r.each_slice(3) + when 9 + r.each_slice(3) + when 10 + [r.shift(4), r.shift(3), r.shift(3)] + when 13 + [r.shift(4), r.shift(3), r.shift(3), r.shift(3)] + when 14 + [r.shift(4), r.shift(4), r.shift(3), r.shift(3)] + else + r.each_slice(4) + end + end end |