More work on verifying tournament round generation

This commit is contained in:
Dan Buch
2012-03-10 22:08:22 -05:00
parent e1f1aa6038
commit 5cf5a8035d
2 changed files with 34 additions and 21 deletions

View File

@@ -2,7 +2,6 @@ class MashTournament < ActiveRecord::Base
belongs_to :requester
has_many :mashes
has_many :rounds, :class_name => 'MashTournamentRound'
#after_create :create_rounds
#after_save :fill_in_next_round
def next_unplayed_mash
@@ -19,20 +18,21 @@ class MashTournament < ActiveRecord::Base
)
end
def create_rounds
n_contenders = Map.count
def valid_number_of_contenders?(n_contenders)
[8, 16, 32, 64, 128].include?(n_contenders)
end
#ap "Original n_contenders = #{n_contenders}"
while n_contenders % 4 != 0
n_contenders -= 1
def create_rounds(n_contenders)
if not valid_number_of_contenders?(n_contenders)
raise StandardError.new(
"The number of contenders must be 8, 16, 32, 64, or 128! " +
"Got '#{n_contenders}'"
)
end
#ap "Resulting n_contenders divisible by 4 = #{n_contenders}"
round = 1
while n_contenders > 1
#ap "Generating round #{round}, n_contenders = #{n_contenders}"
create_round(round, n_contenders)
n_contenders = n_contenders / 2
round += 1