mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added logic for 16 man dobule elminination match generation.
This commit is contained in:
@@ -29,7 +29,7 @@ class Tournament < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def tournament_types
|
||||
["Pool to bracket","Modified 16 Man Double Elimination"]
|
||||
["Pool to bracket","Modified 16 Man Double Elimination","Double Elimination 1-6"]
|
||||
end
|
||||
|
||||
def create_pre_defined_weights(value)
|
||||
|
||||
@@ -14,7 +14,8 @@ class AdvanceWrestler
|
||||
|
||||
def advance_raw
|
||||
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
|
||||
DoubleEliminationAdvance.new(@wrestler).bracket_advancement if @tournament.tournament_type == "Modified 16 Man Double Elimination"
|
||||
DoubleEliminationAdvance.new(@wrestler).bracket_advancement if @tournament.tournament_type == "Modified 16 Man Double Elimination" or
|
||||
@tournament.tournament_type == "Double Elimination 1-6"
|
||||
end
|
||||
|
||||
def pool_to_bracket_advancement
|
||||
|
||||
@@ -34,9 +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"
|
||||
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"
|
||||
end
|
||||
|
||||
def standardStartingActions
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
class SixteenManDoubleEliminationGenerateLoserNames
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
def assign_loser_names
|
||||
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
|
||||
end
|
||||
|
||||
def conso_round_2(matches)
|
||||
matches.select{|m| m.round == 2 and m.bracket_position == "Conso"}.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 == "Bracket"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.round == 1 and m.bracket_position == "Bracket"}.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 == "Bracket"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 4 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 3
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 5 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 6 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 4
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 7 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}"
|
||||
match.loser2_name = "Loser of #{matches.select{|m| m.bracket_position_number == 8 and m.round == 1 and m.bracket_position == "Bracket"}.first.bout_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def conso_round_3(matches)
|
||||
matches.select{|m| m.round == 3 and m.bracket_position == "Conso"}.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 == 4 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.bracket_position == "Quarter"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 3
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 2 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
elsif match.bracket_position_number == 4
|
||||
match.loser1_name = "Loser of #{matches.select{|m| m.bracket_position_number == 1 and m.bracket_position == "Quarter"}.first.bout_number}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def conso_round_5(matches)
|
||||
matches.select{|m| m.round == 5 and 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 == "Bracket"}.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,93 @@
|
||||
class SixteenManDoubleEliminationMatchGeneration
|
||||
def initialize( tournament )
|
||||
@tournament = tournament
|
||||
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)
|
||||
end
|
||||
|
||||
def round_one(weight)
|
||||
create_matchup_from_seed(1,16, "Bracket", 1, 1,weight)
|
||||
create_matchup_from_seed(8,9, "Bracket", 2, 1,weight)
|
||||
create_matchup_from_seed(5,12, "Bracket", 3, 1,weight)
|
||||
create_matchup_from_seed(4,14, "Bracket", 4, 1,weight)
|
||||
create_matchup_from_seed(3,13, "Bracket", 5, 1,weight)
|
||||
create_matchup_from_seed(6,11, "Bracket", 6, 1,weight)
|
||||
create_matchup_from_seed(7,10, "Bracket", 7, 1,weight)
|
||||
create_matchup_from_seed(2,15, "Bracket", 8, 1,weight)
|
||||
end
|
||||
|
||||
def round_two(weight)
|
||||
create_matchup(nil,nil,"Quarter",1,2,weight)
|
||||
create_matchup(nil,nil,"Quarter",2,2,weight)
|
||||
create_matchup(nil,nil,"Quarter",3,2,weight)
|
||||
create_matchup(nil,nil,"Quarter",4,2,weight)
|
||||
create_matchup(nil,nil,"Conso",1,2,weight)
|
||||
create_matchup(nil,nil,"Conso",2,2,weight)
|
||||
create_matchup(nil,nil,"Conso",3,2,weight)
|
||||
create_matchup(nil,nil,"Conso",4,2,weight)
|
||||
end
|
||||
|
||||
def round_three(weight)
|
||||
create_matchup(nil,nil,"Conso",1,3,weight)
|
||||
create_matchup(nil,nil,"Conso",2,3,weight)
|
||||
create_matchup(nil,nil,"Conso",3,3,weight)
|
||||
create_matchup(nil,nil,"Conso",4,3,weight)
|
||||
end
|
||||
|
||||
def round_four(weight)
|
||||
create_matchup(nil,nil,"Semis",1,4,weight)
|
||||
create_matchup(nil,nil,"Semis",2,4,weight)
|
||||
create_matchup(nil,nil,"Conso Quarter",1,4,weight)
|
||||
create_matchup(nil,nil,"Conso Quarter",2,4,weight)
|
||||
end
|
||||
|
||||
def round_five(weight)
|
||||
create_matchup(nil,nil,"Conso Semis",1,5,weight)
|
||||
create_matchup(nil,nil,"Conso Semis",2,5,weight)
|
||||
end
|
||||
|
||||
def round_six(weight)
|
||||
create_matchup(nil,nil,"1/2",1,6,weight)
|
||||
create_matchup(nil,nil,"3/4",1,6,weight)
|
||||
create_matchup(nil,nil,"5/6",1,6,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)
|
||||
@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
|
||||
@@ -5,6 +5,7 @@ class SwapWrestlers
|
||||
def swap_wrestlers_bracket_lines(wrestler1_id,wrestler2_id)
|
||||
w1 = Wrestler.find(wrestler1_id)
|
||||
w2 = Wrestler.find(wrestler2_id)
|
||||
weight_matches = w1.weight.matches
|
||||
|
||||
#placeholder guy
|
||||
w3 = Wrestler.new
|
||||
@@ -12,34 +13,43 @@ class SwapWrestlers
|
||||
w3.original_seed = w1.original_seed
|
||||
w3.bracket_line = w1.bracket_line
|
||||
w3.pool = w1.pool
|
||||
swapWrestlerMatches(w1.all_matches,w1.id,w3.id)
|
||||
weight_matches = swapWrestlerMatches(weight_matches,w1.id,w3.id)
|
||||
|
||||
#Swap wrestler 1 and wrestler 2
|
||||
swapWrestlerMatches(w2.all_matches,w2.id,w1.id)
|
||||
weight_matches = swapWrestlerMatches(weight_matches,w2.id,w1.id)
|
||||
w1.bracket_line = w2.bracket_line
|
||||
w1.pool = w2.pool
|
||||
|
||||
|
||||
swapWrestlerMatches(w3.all_matches,w3.id,w2.id)
|
||||
weight_matches = swapWrestlerMatches(weight_matches,w3.id,w2.id)
|
||||
w2.bracket_line = w3.bracket_line
|
||||
w2.pool = w3.pool
|
||||
|
||||
|
||||
save_matches(weight_matches)
|
||||
w1.save
|
||||
w2.save
|
||||
end
|
||||
|
||||
def swapWrestlerMatches(matchesToSwap,w1_id,w2_id)
|
||||
matchesToSwap.each do |m|
|
||||
if m.bracket_position == "Pool"
|
||||
if m.w1 == w1_id
|
||||
m.w1 = w2_id
|
||||
m.save
|
||||
elsif m.w2 == w1_id
|
||||
m.w2 = w2_id
|
||||
m.save
|
||||
end
|
||||
def save_matches(matches)
|
||||
matches.each do |match|
|
||||
match.save
|
||||
end
|
||||
end
|
||||
|
||||
def swapWrestlerMatches(matchesToSwap,from_id,to_id)
|
||||
matchesToSwap.select{|m| m.w1 == from_id or m.w2 == from_id}.each do |m|
|
||||
# if m.bracket_position == "Pool" or (m.bracket_position == "Bracket" and m.round == 1)
|
||||
if m.w1 == from_id
|
||||
m.w1 = to_id
|
||||
elsif m.w2 == from_id
|
||||
m.w2 = to_id
|
||||
end
|
||||
if m.winner_id == from_id
|
||||
m.winner_id = to_id
|
||||
end
|
||||
# m.save
|
||||
# end
|
||||
end
|
||||
return matchesToSwap
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,6 +90,10 @@ li:first-child,li:last-child {
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<%= render 'modified_sixteen_man_double_elimination_bracket' %>
|
||||
</td>
|
||||
<% elsif @tournament.tournament_type == "Double Elimination 1-6" %>
|
||||
<td valign="top" style="padding: 10px;">
|
||||
<%= render 'sixteen_man_double_elimination_bracket' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -0,0 +1,143 @@
|
||||
<h4>Championship Bracket</h4>
|
||||
<main id="bracket">
|
||||
<ul class="round round-1">
|
||||
<% @matches.select{|m|m.bracket_position == "Bracket" and m.round == 1}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
<li class="game game-top "><%= match.w1_bracket_name_round_one %> <span></span></li>
|
||||
<li class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </li>
|
||||
<li class="game game-bottom "><%= match.w2_bracket_name_round_one %><span></span></li>
|
||||
<li> </li>
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-2">
|
||||
<% @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-3">
|
||||
<% @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-4">
|
||||
<% @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-5">
|
||||
<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" and m.round == 2}.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" and m.round == 3}.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>
|
||||
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul class="round round-3">
|
||||
<% @matches.select{|m|m.bracket_position == "Conso Quarter"}.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<li> </li>
|
||||
<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-4">
|
||||
<% @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-5">
|
||||
<% @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-6">
|
||||
<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-3">
|
||||
<% @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-4">
|
||||
<li> </li>
|
||||
|
||||
<li class="bracket-winner"> <%= match.bracket_winner_name %> <span></span></li>
|
||||
5th
|
||||
|
||||
<li> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
</main>
|
||||
Reference in New Issue
Block a user