summaryrefslogtreecommitdiff
path: root/lib/seeding/random_seeding.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/seeding/random_seeding.rb')
-rw-r--r--lib/seeding/random_seeding.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb
new file mode 100644
index 0000000..ccdba11
--- /dev/null
+++ b/lib/seeding/random_seeding.rb
@@ -0,0 +1,20 @@
+module Seeding
+ module RandomSeeding
+ def self.seed(tournament_stage)
+ matches = tournament_stage.matches
+ match = matches.first
+ match_num = 0
+ teams = 0
+ tournament_stage.tournament.players.shuffle.each_slice(tournament_stage.tournament.min_players_per_team) do |slice|
+ if teams < tournament_stage.tournament.min_teams_per_match
+ match.teams.push Team.create(players: slice)
+ teams += 1
+ else
+ match_num += 1
+ match = matches[match_num]
+ teams = 0
+ end
+ end
+ end
+ end
+end