From 86992e85220e9a42ed498497ca733e39fb7266fc Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Thu, 24 Apr 2014 21:46:10 -0400 Subject: seeds and elimination small changes --- lib/scheduling/elimination.rb | 17 +++++++++-------- lib/scheduling/roundrobin.rb | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 lib/scheduling/roundrobin.rb (limited to 'lib/scheduling') diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index 0e93f7a..543df52 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -7,14 +7,6 @@ module Scheduling @tournament_stage = tournament_stage end - def tournament_stage - @tournament_stage - end - - def tournament - self.tournament_stage.tournament - end - def create_matches num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor num_matches = (Float(num_teams - tournament.min_teams_per_match)/(tournament.min_teams_per_match - 1)).ceil + 1 @@ -138,5 +130,14 @@ STRING return str end + private + + def tournament_stage + @tournament_stage + end + + def tournament + self.tournament_stage.tournament + end end end diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb new file mode 100644 index 0000000..e050c41 --- /dev/null +++ b/lib/scheduling/roundrobin.rb @@ -0,0 +1,24 @@ + +module Scheduling + class RoundRobin + include Rails.application.routes.url_helpers + + def initialize(tournament_stage) + @tournament_stage = tournament_stage + end + + def create_matches + num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor + num_matches = Float(num_teams/2)*(num_teams-1) + + end + + def match_finished(match) + + end + + def graph(current_user) + + end + end +end -- cgit v1.2.3-2-g168b From 426c916c62d5ff28742821e482f291c5cecc0f64 Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:36:52 -0400 Subject: Added the round robin algorithm. Its based on array rotations. The array needs to be properly populated (I'm not sure how to add the teams to the array) --- lib/scheduling/roundrobin.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/scheduling') diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index e050c41..a3a75c9 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -11,6 +11,23 @@ module Scheduling num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor num_matches = Float(num_teams/2)*(num_teams-1) + #round robin should look like this + @team_pairs = Array.new(num_matches) + #team_pairs needs populated with the team objects and im not sure how to do that + end + + #this is called when a round has completed + def rotate + + for i in 0..@team_pairs-2 + hold = @team_pairs.shift + @team_pairs.rotate! + @team_pairs.unshift(hold) + # for j in 0..4 + # puts "#{array[j]}, #{array[j+(array.size/2)-1]}" + # end + # puts "\n\n" + end end def match_finished(match) -- cgit v1.2.3-2-g168b From ef45245dda03b5bba3d66432ed814fdec1f51af3 Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:47:37 -0400 Subject: I think I properly populated the teams into the @teams_pair array. Its in roundRobin.rb. Someone may want to check to make sure I did it right. --- lib/scheduling/roundrobin.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/scheduling') diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index a3a75c9..ffac9b6 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -1,4 +1,3 @@ - module Scheduling class RoundRobin include Rails.application.routes.url_helpers @@ -13,6 +12,9 @@ module Scheduling #round robin should look like this @team_pairs = Array.new(num_matches) + for i in 0..@match.teams.size + @team_pairs.push(@match.teams[i] + end #team_pairs needs populated with the team objects and im not sure how to do that end -- cgit v1.2.3-2-g168b From 2aaaf29ae291edc34d0512ce9a812fc0de14f76b Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:48:29 -0400 Subject: fixed a dumb mistake --- lib/scheduling/roundrobin.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/scheduling') diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index ffac9b6..10af20e 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -20,16 +20,14 @@ module Scheduling #this is called when a round has completed def rotate - - for i in 0..@team_pairs-2 - hold = @team_pairs.shift - @team_pairs.rotate! - @team_pairs.unshift(hold) + hold = @team_pairs.shift + @team_pairs.rotate! + @team_pairs.unshift(hold) # for j in 0..4 # puts "#{array[j]}, #{array[j+(array.size/2)-1]}" # end # puts "\n\n" - end + end def match_finished(match) -- cgit v1.2.3-2-g168b