diff options
author | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-27 20:47:42 -0400 |
---|---|---|
committer | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-27 20:47:42 -0400 |
commit | 4d47e5e7b5d838173dd3ab68c293c03e03811392 (patch) | |
tree | 594659a4fbc6cbc1afd188f94f8196e203cabe31 /lib | |
parent | df1cda1faab97f4c424efdcf8b6822f98b73adb8 (diff) | |
parent | 9d0be853cef35412c0bfe92c80502fd9da7947f1 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pairing/PairingAlgorithm.rb | 6 | ||||
-rw-r--r-- | lib/playing/.keep | 0 | ||||
-rw-r--r-- | lib/sampling/README.md | 15 | ||||
-rw-r--r-- | lib/scheduling/README.md | 19 | ||||
-rw-r--r-- | lib/scheduling/round_robin.rb | 81 | ||||
-rw-r--r-- | lib/scoring/README.md | 7 | ||||
-rw-r--r-- | lib/seeding/README.md | 12 | ||||
-rw-r--r-- | lib/seeding/early_bird_seeding.rb | 6 | ||||
-rw-r--r-- | lib/seeding/fair_ranked_seeding.rb | 16 | ||||
-rw-r--r-- | lib/seeding/random_seeding.rb | 6 |
10 files changed, 93 insertions, 75 deletions
diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb deleted file mode 100644 index 81e4df6..0000000 --- a/lib/pairing/PairingAlgorithm.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Pairing - class PairingAlgorithm - def self.pair(matches, players) - end - end -end diff --git a/lib/playing/.keep b/lib/playing/.keep deleted file mode 100644 index e69de29..0000000 --- a/lib/playing/.keep +++ /dev/null diff --git a/lib/sampling/README.md b/lib/sampling/README.md index 28c603e..731f1d1 100644 --- a/lib/sampling/README.md +++ b/lib/sampling/README.md @@ -1,28 +1,41 @@ -Files in this directory should be modules implementing the following +Sampling interface +================== + +Files in this directory should be _modules_ implementing the following interface: - `works_with?(Game) => Boolean` + Returns whether or not this sampling method works with the specified game. - `uses_remote?() => Boolean` + Return whether or not this sampling method requires remote IDs for users. - `set_remote_name(User, Game, String)` + Set the remote ID for a user for the specified game. It is safe to assume that this sampling method `works_with?` that game. - `get_remote_name(Object)` + When given an object from `RemoteUsername#value`, give back a human-readable/editable name to display. - `sampling_start(Match)` + Fetch the statistics for a match. + - `sampling_done?(Match) => Boolean` + Returns whether or not statistics have been completely collected yet. - `render_user_interaction(Match, User) => String` + Returns HTML to render on a page. + - `handle_user_interaction(Match, User, Hash params)` + Handles params from the form generated by `#user_interaction_render`. diff --git a/lib/scheduling/README.md b/lib/scheduling/README.md index 173b7be..8b21164 100644 --- a/lib/scheduling/README.md +++ b/lib/scheduling/README.md @@ -1,13 +1,22 @@ -Files in this directory should implement the following interface: +Scheduling interface +==================== + +Files in this directory should be _classes_ implementing the following +interface: - `initialize(tournament_stage)` - construct new Scheduling object from tournament_stage + + Construct new Scheduling object from tournament_stage. - `create_matches` - creates all the matches of the current round + + Creates all the matches of the current round. - `finish_match(match)` - progresses the match through the schedule + + Progresses the match through the schedule. - `graph` - returns a string representation of an svg image of the current stage
\ No newline at end of file + + Returns a string representation of an svg image of the current + stage. diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb index 7a9e257..0cbddc1 100644 --- a/lib/scheduling/round_robin.rb +++ b/lib/scheduling/round_robin.rb @@ -7,38 +7,53 @@ module Scheduling end def create_matches - num_teams = (tournament.players.count/tournament.min_players_per_team).floor - num_matches = Float(num_teams/2)*(num_teams-1) - for i in 1..num_matches + # => find the number of matches and teams to create + @num_teams = (tournament.players.count/tournament.min_players_per_team).floor + @matches_per_round = num_teams * tournament.min_teams_per_match + + # => initialize data and status members + @team_pairs ||= {} + if @team_pairs.empty? + @matches_finished = 0 + end + + # => Create new matches + @matches_per_round.each do |match| tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0) end + + # => seed the first time + if @team_pairs.empty? + tournament_stage.seeding.seed_matches(tournament_stage) + tournament_stage.matches.each {|match| match.teams.each {|team| @team_pairs += team}} + else + # => Reorder the list of teams + top = @team_pairs.shift + @team_pairs.push @team_pairs.shift + @team_pairs.unshift top + + # => Add the teams to the matches + match = tournament_stage.matches[@matches_finished-1] + matches = 1 + (0..@team_pairs.count-1).each do |i| + match.teams += @team_pairs[i] + if @team_pairs.count.%(tournament.min_teams_per_match).zero? + match = tournament_stage.matches[@matches_finished-1 + matches] + matches += 1 + end + end + + end end def finish_match(match) - #declare winner of match, and store that somehow - rotate - return "totes worked\n" + @matches_finished += 1 end def graph(current_user) end private - - def create_round_array - #round robin should look like this. - #NOTE: I DO NOT KNOW IF THIS IS HOW TO PROPERLY POPULATE THE ROUND ROBIN ARRAY WITH TEAMS - @team_pairs = Array.new(num_matches) - for i in 0..@match.teams.size - @team_pairs.push(@match.teams[i]) - #if there is an odd number of teams, add a dummy for byes - if @match.teams.size % 2 != 0 && i == @match.teams.size-1 - dummy = Team.create - @team_pairs.push(dummy) - end - end - end - def tournament_stage @tournament_stage end @@ -46,29 +61,5 @@ module Scheduling def tournament tournament_stage.tournament end - - def rotate - #this is called when a round has completed - - #remove first team - hold = @team_pairs.shift - #rotate by 1 element - @team_pairs.rotate! - #place first team the front of the array - @team_pairs.unshift(hold) - end - - def mother_fuckin_winner - scores = {} - @teams_pairs.each do |team| - scores[team] = team.matches. - where(:tournament_stage => tournament_stage). - collect{|match|match.winner==team} - end - weiner = scores.index(scores.max) - scores[weiner] - end - - end end diff --git a/lib/scoring/README.md b/lib/scoring/README.md index 95dd5e0..5beb0a2 100644 --- a/lib/scoring/README.md +++ b/lib/scoring/README.md @@ -1,10 +1,15 @@ -Files in this directory should be modules implementing the following +Scoring interface +================= + +Files in this directory should be _modules_ implementing the following interface: - `stats_needed() => Array[i]=Symbol` + Returns which statistics need to be collected for this scoring algorithm. - `score(match) => Hash[User]=Integer` + User scores for this match, assuming statistics have been collected. diff --git a/lib/seeding/README.md b/lib/seeding/README.md index 67fc19b..d323b6d 100644 --- a/lib/seeding/README.md +++ b/lib/seeding/README.md @@ -1,4 +1,10 @@ -Files in this directory should implement the following interface: +Seeding interface +================= -- seed_matches(tournament) - take the matches of a tournament and the players in a tournament, assign players to teams, and teams to matches (all must exist)
\ No newline at end of file +Files in this directory should be _modules_ implement the following +interface: + + - `seed(TournamentStage)` + + Take a tournament stage, assign players to teams and teams to + matches (matches must exist). diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb index 30e15fc..488a1a2 100644 --- a/lib/seeding/early_bird_seeding.rb +++ b/lib/seeding/early_bird_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class EarlyBirdSeeding - def seed_matches(tournament) + module EarlyBirdSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -17,4 +17,4 @@ module Seeding end end end -end
\ No newline at end of file +end diff --git a/lib/seeding/fair_ranked_seeding.rb b/lib/seeding/fair_ranked_seeding.rb index 4eb8c26..f56d648 100644 --- a/lib/seeding/fair_ranked_seeding.rb +++ b/lib/seeding/fair_ranked_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class FairRankedSeeding - def seed_matches(tournament) + module FairRankedSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -19,17 +19,17 @@ module Seeding end private - def best_first(tournament) + def self.best_first(tournament) tournament.players.sort {|a, b| better(a, b, tournament) } end - def better(player1, player2, tournament) - ps1 = previousScore(player1, tournament) - ps2 = previousScore(player2, tournament) + def self.better(player1, player2, tournament) + ps1 = previous_score(player1, tournament) + ps2 = previous_score(player2, tournament) ps1 <=> ps2 end - def previousScore(player, tournament) + def self.previous_score(player, tournament) score = tournament.statistics.getStatistic(player.matches.last, player, :score) if score.nil? return 0 @@ -37,4 +37,4 @@ module Seeding score end end -end
\ No newline at end of file +end diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb index ec39e61..723d70e 100644 --- a/lib/seeding/random_seeding.rb +++ b/lib/seeding/random_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class RandomSeeding - def seed_matches(tournament) + module RandomSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -17,4 +17,4 @@ module Seeding end end end -end
\ No newline at end of file +end |