mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
Added 8 man brackets for double elimination
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class DoubleEliminationGenerateLoserNames
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def assign_loser_names
|
||||
@tournament.weights.each do |weight|
|
||||
SixteenManDoubleEliminationGenerateLoserNames.new(weight).assign_loser_names_for_weight if weight.wrestlers.size >= 9 and weight.wrestlers.size <= 16
|
||||
EightManDoubleEliminationGenerateLoserNames.new(weight).assign_loser_names_for_weight if weight.wrestlers.size >= 4 and weight.wrestlers.size <= 8
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
class DoubleEliminationMatchGeneration
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def generate_matches
|
||||
@tournament.weights.each do |weight|
|
||||
SixteenManDoubleEliminationMatchGeneration.new(weight).generate_matches_for_weight if weight.wrestlers.size >= 9 and weight.wrestlers.size <= 16
|
||||
EightManDoubleEliminationMatchGeneration.new(weight).generate_matches_for_weight if weight.wrestlers.size >= 4 and weight.wrestlers.size <= 8
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
class EightManDoubleEliminationGenerateLoserNames
|
||||
def initialize( weight )
|
||||
@weight = weight
|
||||
end
|
||||
|
||||
def assign_loser_names_for_weight
|
||||
matches_by_weight = nil
|
||||
matches_by_weight = @weight.matches
|
||||
conso_round_2(matches_by_weight)
|
||||
conso_round_4(matches_by_weight)
|
||||
fifth_sixth(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
matches_by_weight = @weight.matches.reload
|
||||
advance_bye_matches_championship(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
end
|
||||
|
||||
def conso_round_2(matches)
|
||||
matches.select{|m| m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match|
|
||||
if match.bracket_position_number == 1
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 2
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 3 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 4 and m.round == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def conso_round_4(matches)
|
||||
matches.select{|m| m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}.each do |match|
|
||||
if match.bracket_position_number == 1
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.bracket_position == "Semis"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 2
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.bracket_position == "Semis"}.first.bout_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fifth_sixth(matches)
|
||||
matches.select{|m| m.bracket_position == "5/6"}.sort_by{|m| m.bracket_position_number}.each do |match|
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position == "Conso Semis"}.second.bout_number}"
|
||||
end
|
||||
end
|
||||
|
||||
def advance_bye_matches_championship(matches)
|
||||
matches.select{|m| m.round == 1 and m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match|
|
||||
if match.w1 == nil or match.w2 == nil
|
||||
match.finished = 1
|
||||
match.win_type = "BYE"
|
||||
if match.w1 != nil
|
||||
match.winner_id = match.w1
|
||||
match.loser2_name = "BYE"
|
||||
match.save
|
||||
match.advance_wrestlers
|
||||
elsif match.w2 != nil
|
||||
match.winner_id = match.w2
|
||||
match.loser1_name = "BYE"
|
||||
match.save
|
||||
match.advance_wrestlers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_matches(matches)
|
||||
matches.each do |m|
|
||||
m.save!
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
class EightManDoubleEliminationMatchGeneration
|
||||
def initialize( weight )
|
||||
@weight = weight
|
||||
end
|
||||
|
||||
def generate_matches_for_weight
|
||||
round_one(@weight)
|
||||
round_two(@weight)
|
||||
round_three(@weight)
|
||||
round_four(@weight)
|
||||
end
|
||||
|
||||
def round_one(weight)
|
||||
create_matchup_from_seed(1,8,"Quarter",1,1,weight)
|
||||
create_matchup_from_seed(4,5,"Quarter",2,1,weight)
|
||||
create_matchup_from_seed(3,6,"Quarter",3,1,weight)
|
||||
create_matchup_from_seed(2,7,"Quarter",4,1,weight)
|
||||
end
|
||||
|
||||
def round_two(weight)
|
||||
create_matchup(nil,nil,"Semis",1,2,weight)
|
||||
create_matchup(nil,nil,"Semis",2,2,weight)
|
||||
create_matchup(nil,nil,"Conso Quarter",1,2,weight)
|
||||
create_matchup(nil,nil,"Conso Quarter",2,2,weight)
|
||||
end
|
||||
|
||||
def round_three(weight)
|
||||
create_matchup(nil,nil,"Conso Semis",1,3,weight)
|
||||
create_matchup(nil,nil,"Conso Semis",2,3,weight)
|
||||
end
|
||||
|
||||
def round_four(weight)
|
||||
create_matchup(nil,nil,"1/2",1,4,weight)
|
||||
create_matchup(nil,nil,"3/4",1,4,weight)
|
||||
create_matchup(nil,nil,"5/6",1,4,weight)
|
||||
end
|
||||
|
||||
def wrestler_with_seed(seed,weight)
|
||||
wrestler = Wrestler.where("weight_id = ? and bracket_line = ?", weight.id, seed).first
|
||||
if wrestler
|
||||
return wrestler.id
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def create_matchup_from_seed(w1_seed, w2_seed, bracket_position, bracket_position_number,round,weight)
|
||||
# if wrestler_with_seed(w1_seed,weight) and wrestler_with_seed(w2_seed,weight)
|
||||
create_matchup(wrestler_with_seed(w1_seed,weight),wrestler_with_seed(w2_seed,weight), bracket_position, bracket_position_number,round,weight)
|
||||
# end
|
||||
end
|
||||
|
||||
def create_matchup(w1, w2, bracket_position, bracket_position_number,round,weight)
|
||||
@weight.tournament.matches.create(
|
||||
w1: w1,
|
||||
w2: w2,
|
||||
weight_id: weight.id,
|
||||
round: round,
|
||||
bracket_position: bracket_position,
|
||||
bracket_position_number: bracket_position_number
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -34,11 +34,11 @@ class GenerateTournamentMatches
|
||||
standardStartingActions
|
||||
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket"
|
||||
ModifiedSixteenManMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type == "Modified 16 Man Double Elimination"
|
||||
SixteenManDoubleEliminationMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type == "Double Elimination 1-6"
|
||||
DoubleEliminationMatchGeneration.new(@tournament).generate_matches if @tournament.tournament_type == "Double Elimination 1-6"
|
||||
postMatchCreationActions
|
||||
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
|
||||
ModifiedSixteenManGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type == "Modified 16 Man Double Elimination"
|
||||
SixteenManDoubleEliminationGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type == "Double Elimination 1-6"
|
||||
DoubleEliminationGenerateLoserNames.new(@tournament).assign_loser_names if @tournament.tournament_type == "Double Elimination 1-6"
|
||||
end
|
||||
|
||||
def standardStartingActions
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
class SixteenManDoubleEliminationGenerateLoserNames
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
def initialize( weight )
|
||||
@weight = weight
|
||||
end
|
||||
|
||||
def assign_loser_names
|
||||
def assign_loser_names_for_weight
|
||||
matches_by_weight = nil
|
||||
@tournament.weights.each do |w|
|
||||
matches_by_weight = @tournament.matches.where(weight_id: w.id)
|
||||
conso_round_2(matches_by_weight)
|
||||
conso_round_3(matches_by_weight)
|
||||
conso_round_5(matches_by_weight)
|
||||
fifth_sixth(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
matches_by_weight = @tournament.matches.where(weight_id: w.id).reload
|
||||
advance_bye_matches_championship(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
end
|
||||
matches_by_weight = @weight.matches
|
||||
conso_round_2(matches_by_weight)
|
||||
conso_round_3(matches_by_weight)
|
||||
conso_round_5(matches_by_weight)
|
||||
fifth_sixth(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
matches_by_weight = @weight.matches.reload
|
||||
advance_bye_matches_championship(matches_by_weight)
|
||||
save_matches(matches_by_weight)
|
||||
end
|
||||
|
||||
def conso_round_2(matches)
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
class SixteenManDoubleEliminationMatchGeneration
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
def initialize( weight )
|
||||
@weight = weight
|
||||
end
|
||||
|
||||
def generate_matches
|
||||
@tournament.weights.each do |weight|
|
||||
generate_matches_for_weight(weight)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_matches_for_weight(weight)
|
||||
round_one(weight)
|
||||
round_two(weight)
|
||||
round_three(weight)
|
||||
round_four(weight)
|
||||
round_five(weight)
|
||||
round_six(weight)
|
||||
def generate_matches_for_weight
|
||||
round_one(@weight)
|
||||
round_two(@weight)
|
||||
round_three(@weight)
|
||||
round_four(@weight)
|
||||
round_five(@weight)
|
||||
round_six(@weight)
|
||||
end
|
||||
|
||||
def round_one(weight)
|
||||
@@ -81,7 +75,7 @@ class SixteenManDoubleEliminationMatchGeneration
|
||||
end
|
||||
|
||||
def create_matchup(w1, w2, bracket_position, bracket_position_number,round,weight)
|
||||
@tournament.matches.create(
|
||||
@weight.tournament.matches.create(
|
||||
w1: w1,
|
||||
w2: w2,
|
||||
weight_id: weight.id,
|
||||
|
||||
@@ -92,7 +92,7 @@ li:first-child,li:last-child {
|
||||
</td>
|
||||
<% elsif @tournament.tournament_type == "Double Elimination 1-6" %>
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<%= render 'sixteen_man_double_elimination_bracket' %>
|
||||
<%= render 'double_elimination_bracket' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<% if @weight.wrestlers.size <= 16 and @weight.wrestlers.size >= 9 %>
|
||||
<%= render 'sixteen_man_double_elimination_bracket' %>
|
||||
<% elsif @weight.wrestlers.size >= 4 and @weight.wrestlers.size <= 8 %>
|
||||
<%= render 'eight_man_double_elimination_bracket' %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,109 @@
|
||||
<h4>Championship Bracket</h4>
|
||||
<main id="bracket">
|
||||
<ul class="round round-1">
|
||||
<% @matches.select{|m|m.bracket_position == "Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
<li></li>
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-2">
|
||||
<% @matches.select{|m|m.bracket_position == "Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
<li></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-3">
|
||||
<% @matches.select{|m|m.bracket_position == "1/2"}.each do |match| %>
|
||||
<li> </li>
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
<li></li>
|
||||
|
||||
</ul>
|
||||
<ul class="round round-4">
|
||||
<li> </li>
|
||||
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
|
||||
1st
|
||||
<li></li>
|
||||
|
||||
</ul>
|
||||
<% end %>
|
||||
</main>
|
||||
<h4>Consolation Bracket</h4>
|
||||
<main id="bracket">
|
||||
<ul class="round round-1">
|
||||
<% @matches.select{|m|m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
<li> </li>
|
||||
|
||||
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-2">
|
||||
<% @matches.select{|m|m.bracket_position == "Conso Semis"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
<li> </li>
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-3">
|
||||
<% @matches.select{|m|m.bracket_position == "3/4"}.each do |match| %>
|
||||
<li> </li>
|
||||
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
|
||||
<li> </li>
|
||||
|
||||
</ul>
|
||||
<ul class="round round-4">
|
||||
<li> </li>
|
||||
|
||||
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
|
||||
3rd
|
||||
|
||||
<li> </li>
|
||||
|
||||
</ul>
|
||||
<% end %>
|
||||
</main>
|
||||
<h4>5/6 place match</h4>
|
||||
<main id="bracket">
|
||||
<ul class="round round-1">
|
||||
<% @matches.select{|m|m.bracket_position == "5/6"}.each do |match| %>
|
||||
<li> </li>
|
||||
|
||||
<li class="game game-top "><%= match.w1_bracket_name %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name %><span></span></li>
|
||||
|
||||
<li> </li>
|
||||
|
||||
</ul>
|
||||
<ul class="round round-2">
|
||||
<li> </li>
|
||||
|
||||
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
|
||||
5th
|
||||
|
||||
<li> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
</main>
|
||||
@@ -120,7 +120,7 @@
|
||||
</main>
|
||||
<h4>5/6 place match</h4>
|
||||
<main id="bracket">
|
||||
<ul class="round round-3">
|
||||
<ul class="round round-1">
|
||||
<% @matches.select{|m|m.bracket_position == "5/6"}.each do |match| %>
|
||||
<li> </li>
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
<li> </li>
|
||||
|
||||
</ul>
|
||||
<ul class="round round-4">
|
||||
<ul class="round round-2">
|
||||
<li> </li>
|
||||
|
||||
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<% @weight = weight %>
|
||||
<%= render 'bracket_partial' %>
|
||||
</td>
|
||||
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" %>
|
||||
<% elsif @tournament.tournament_type == "Modified 16 Man Double Elimination" or @tournament.tournament_type == "Double Elimination 1-6" %>
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<!-- Need to define what the tournaments#bracket controller defines -->
|
||||
<% @matches = weight.matches %>
|
||||
|
||||
Reference in New Issue
Block a user