From 5084f01e0ea7ba7c378982099fdbf9880857f091 Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 21:52:32 -0400 Subject: matches are given teams correctly --- app/models/tournament.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 859518c..72c3ac8 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -34,16 +34,17 @@ class Tournament < ActiveRecord::Base 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 > max_teams_per_match) + 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 -- cgit v1.2.3