More work on verifying tournament round generation
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user