1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-24 06:52:35 +00:00

Generated bouts and rounds. Need to fix rounds for odd numbered pools.

This commit is contained in:
2015-02-03 10:41:49 -05:00
parent 7ea80b2997
commit 0244d15a8b
8 changed files with 62 additions and 24 deletions

View File

@@ -3,14 +3,22 @@ class Tournament < ActiveRecord::Base
has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy
attr_accessor :upcomingMatches
def upcomingMatches
@matches = Match.where(tournament_id: self.id)
@matches.sort_by{|x|[x.boutNumber]}
# @matches.sort_by{|x|[x.round,x.weight.max]}
end
def generateMatches
destroyAllMatches
self.weights.each do |weight|
puts weight.inspect
weight.generatePool
end
assignRound
assignBouts
end
def destroyAllMatches
@@ -22,31 +30,33 @@ class Tournament < ActiveRecord::Base
def assignRound
@matches = Match.where(tournament_id: self.id)
@matches.sort_by{|x|[x.id]}
@matches.each do |match|
@round = 1
@w1 = Wrestler.find(match.r_id)
@w2 = Wrestler.find(match.g_id)
checkRound(@w1,@w2,@round)
while checkRound(@w1,@w2,@round) == false
@round = @round + 1
until wrestlingThisRound(@w1,@w2,@round) == false do
@round += 1
end
match.round = @round
match.save
end
end
def checkRound(w1,w2,round)
def assignBouts
@bouts = Bout.new
@bouts.assignBouts(self.id)
end
def wrestlingThisRound(w1,w2,round)
if w1.isWrestlingThisRound(round) == true or
w2.isWrestlingThisRound(round) == true
puts "They wrestle this round"
return false
else
puts "They do not wrestle this round"
return true
else
return false
end
end
end
#@weights.sort_by{|x|[x.max]}