本文整理汇总了Python中models.Match.winner_next方法的典型用法代码示例。如果您正苦于以下问题:Python Match.winner_next方法的具体用法?Python Match.winner_next怎么用?Python Match.winner_next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.winner_next方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_se
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import winner_next [as 别名]
def generate_se(tournament):
tournament = Tournament.objects.select_related().get(pk=tournament.pk)
tournament.matches.all().delete()
entrants_per_match = tournament.entrants_per_match
num_players = tournament.entrants.count()
if tournament.bracket_type != 'se':
raise ValueError('needs tournament with single elimination style')
if num_players < entrants_per_match:
raise ValueError('needs at least 2 or more entrants.')
if tournament.seed_type == 'r':
entrants = list(tournament.entrants.all().order_by('?')) # force queryset evaluation
else:
raise NotImplementedError('only random is implemented')
num_rounds = int(math.ceil(math.log(num_players, entrants_per_match)))
byes = entrants_per_match**num_rounds - num_players
#wrap this in a transaction
### Generate Bracket ###
final_match = Match(tournament_game=tournament)
final_match.save()
tournament.root_match = final_match
print "created root object"
rounds = [[final_match]]
#iterate backward through rounds
for round in xrange(1, num_rounds):
print "level %i" % round
prev_level = rounds[round-1]
this_round = []
for match in prev_level:
for slot in xrange(entrants_per_match):
m = Match(tournament_game=tournament)
m.winner_next = match
m.save()
print "slot %i" % slot
this_round.append(m)
rounds.append(this_round)
#seed first round
half = int(math.ceil(entrants_per_match/2))
for match in rounds[num_rounds-1]:
if byes > half: # set up first round byes
for slot in xrange(entrants_per_match-half):
seed_match(tournament, match, entrants)
byes -= half
else: # clean up remaining byes
for slot in xrange(entrants_per_match-byes):
seed_match(tournament, match, entrants)
byes = 0
print "seeded: %s" % match
#put code for double elim here
#prune any rounds with too few people to start
for match in rounds[num_rounds-1]:
if match.entrants.count() == 1:
print "prune: %s" % match
for e in match.entrants.all():
match.winner_next.entrants.add(e)
match.delete()