summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrewMurrell <amurrel@purdue.edu>2014-04-28 01:49:11 -0400
committerAndrewMurrell <amurrel@purdue.edu>2014-04-28 01:49:11 -0400
commit8abfaf4ce71dff7294424a7cb37efe4db5e0d581 (patch)
treec6ec47564ffa72c1acd5d577900e1ee1228f06d2
parent85c74dac1f82dc1869a2875a9354be0b4b3361ac (diff)
Made Round Robin Work (but it makes too many rounds for 1v1s right now)
-rw-r--r--app/models/team.rb2
-rw-r--r--lib/scheduling/round_robin.rb4
-rw-r--r--lib/seeding/early_bird_seeding.rb6
-rw-r--r--lib/seeding/random_seeding.rb6
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