summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-27 02:46:23 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-27 02:46:23 -0400
commit125d861972b9fcd99147d67b0e8fe4102f96190e (patch)
tree86b6d8d665a4e62592fe63836de9b19d4121f262 /lib
parentb7ef3c9078f40e5c23f53c59b7741883c3bc2fb7 (diff)
parent5301997c80401e0fa5d106dd4dbcd330b4708cfb (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'lib')
-rw-r--r--lib/sampling/double_blind.rb (renamed from lib/sampling/double_bind.rb)0
-rw-r--r--lib/seeding/README.md2
-rw-r--r--lib/seeding/early_bird_seeding.rb20
-rw-r--r--lib/seeding/fair_ranked_seeding.rb40
-rw-r--r--lib/seeding/random_seeding.rb20
5 files changed, 81 insertions, 1 deletions
diff --git a/lib/sampling/double_bind.rb b/lib/sampling/double_blind.rb
index 4a5201c..4a5201c 100644
--- a/lib/sampling/double_bind.rb
+++ b/lib/sampling/double_blind.rb
diff --git a/lib/seeding/README.md b/lib/seeding/README.md
index 0afbb94..67fc19b 100644
--- a/lib/seeding/README.md
+++ b/lib/seeding/README.md
@@ -1,4 +1,4 @@
Files in this directory should implement the following interface:
- seed_matches(tournament)
- take the matches of a tournament and the players in a tournament, assign players to teams, and teams to matches
+ 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
diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb
new file mode 100644
index 0000000..30e15fc
--- /dev/null
+++ b/lib/seeding/early_bird_seeding.rb
@@ -0,0 +1,20 @@
+module Seeding
+ class EarlyBirdSeeding
+ def seed_matches(tournament)
+ matches = tournament.current_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
+ match.teams[teams].players += slice
+ teams += 1
+ else
+ match_num += 1
+ match = matches[match_num]
+ teams = 0
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/seeding/fair_ranked_seeding.rb b/lib/seeding/fair_ranked_seeding.rb
new file mode 100644
index 0000000..4eb8c26
--- /dev/null
+++ b/lib/seeding/fair_ranked_seeding.rb
@@ -0,0 +1,40 @@
+module Seeding
+ class FairRankedSeeding
+ def seed_matches(tournament)
+ matches = tournament.current_stage.matches
+ match = matches.first
+ match_num = 0
+ players_used = 0
+ best_first(tournament).each_slice(tournament.min_teams_per_match) do |slice|
+ (0..tournament.min_teams_per_match-1).each do |index|
+ match.teams[index].players += slice[index]
+ end
+ players_used += 1
+ if players_used == tournament.min_players_per_team
+ match_num += 1
+ match = matches[match_num]
+ players_used = 0
+ end
+ end
+ end
+
+ private
+ def 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)
+ ps1 <=> ps2
+ end
+
+ def previousScore(player, tournament)
+ score = tournament.statistics.getStatistic(player.matches.last, player, :score)
+ if score.nil?
+ return 0
+ end
+ score
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb
new file mode 100644
index 0000000..ec39e61
--- /dev/null
+++ b/lib/seeding/random_seeding.rb
@@ -0,0 +1,20 @@
+module Seeding
+ class RandomSeeding
+ def seed_matches(tournament)
+ matches = tournament.current_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
+ match.teams[teams].players += slice
+ teams += 1
+ else
+ match_num += 1
+ match = matches[match_num]
+ teams = 0
+ end
+ end
+ end
+ end
+end \ No newline at end of file