diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 22:20:28 -0400 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-04-06 22:20:28 -0400 |
commit | bf798e57a760b68c3c7460789cef6389141c067d (patch) | |
tree | 16cd7400b7f289b4aa6ec90e253c4d30d7a1a08c /app/models/tournament.rb | |
parent | 91fee659eadaf6bcc4d063fd5645950da1250896 (diff) | |
parent | 628173fce3de8f5d3e31109b3aa7c964fdab38ca (diff) |
Merge branch 'master' of http://github.com/LukeShu/leaguer
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r-- | app/models/tournament.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 0b55cb6..fdcdba2 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -78,19 +78,20 @@ class Tournament < ActiveRecord::Base for i in 1..num_matches self.matches.create(name: "Match #{i}", status: 0) end - match_num = 0 + match_num = num_matches-1 team_num = 0 #for each grouping of min_players_per_team - self.players.each_slice(min_players_per_team) do |players| - #create a new team in the current match - self.matches[match_num].teams.push(Team.create(users: players)) + players.each_slice(min_players_per_team) do |players| + #if the match is full, move to the next match, otherwise move to the next team - if (team_num != 0 and team_num % max_teams_per_match == 0) - match_num += 1 + if (team_num == min_teams_per_match) + match_num -= 1 team_num = 0 else team_num += 1 end + #create a new team in the current match + self.matches[match_num].teams.push(Team.create(users: players)) end end end |