1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 21:24:25 +00:00

Added 8 man brackets for double elimination

This commit is contained in:
2020-01-24 07:57:51 -05:00
parent 58afc8a485
commit 21b023f195
12 changed files with 303 additions and 36 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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,