From 8abfaf4ce71dff7294424a7cb37efe4db5e0d581 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Mon, 28 Apr 2014 01:49:11 -0400 Subject: Made Round Robin Work (but it makes too many rounds for 1v1s right now) --- app/models/team.rb | 2 ++ lib/scheduling/round_robin.rb | 4 ++-- lib/seeding/early_bird_seeding.rb | 6 +++--- lib/seeding/random_seeding.rb | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/team.rb b/app/models/team.rb index 77136e7..828d168 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,4 +1,6 @@ class Team < ActiveRecord::Base has_and_belongs_to_many :matches has_and_belongs_to_many :users + + alias_attribute :players, :users end diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb index f2e4144..a9defae 100644 --- a/lib/scheduling/round_robin.rb +++ b/lib/scheduling/round_robin.rb @@ -12,7 +12,7 @@ module Scheduling @matches_per_round = @num_teams * tournament.min_teams_per_match # => initialize data and status members - @team_pairs ||= {} + @team_pairs ||= Array.new if @team_pairs.empty? @matches_finished = 0 end @@ -25,7 +25,7 @@ module Scheduling # => seed the first time if @team_pairs.empty? tournament_stage.seeding.seed(tournament_stage) - tournament_stage.matches.each {|match| match.teams.each {|team| @team_pairs += team}} + tournament_stage.matches.each {|match| match.teams.each {|team| @team_pairs.push team}} else # => Reorder the list of teams top = @team_pairs.shift diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb index 5c289ed..bf7b3c2 100644 --- a/lib/seeding/early_bird_seeding.rb +++ b/lib/seeding/early_bird_seeding.rb @@ -1,12 +1,12 @@ module Seeding module EarlyBirdSeeding def self.seed(tournament_stage) - matches = tournament.current_stage.matches + matches = tournament_stage.matches match = matches.first match_num = 0 teams = 0 - tournament.players.each_slice(tournament.min_players_per_team) do |slice| - if teams < tournament.min_teams_per_match + tournament_stage.tournament.players.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 diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb index 36e06d6..ccdba11 100644 --- a/lib/seeding/random_seeding.rb +++ b/lib/seeding/random_seeding.rb @@ -1,12 +1,12 @@ module Seeding module RandomSeeding def self.seed(tournament_stage) - matches = tournament.current_stage.matches + matches = tournament_stage.matches match = matches.first match_num = 0 teams = 0 - tournament.players.shuffle.each_slice(tournament.min_players_per_team) do |slice| - if teams < tournament.min_teams_per_match + 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 -- cgit v1.2.3