当前位置: 首页>>代码示例>>Python>>正文


Python Match.winner_next方法代码示例

本文整理汇总了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()
开发者ID:LanConnect,项目名称:LanConnect,代码行数:66,代码来源:brackets.py


注:本文中的models.Match.winner_next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。