def _bye_if_odd(self, round, ranking): """ If ranking player count is odd, pops a random player from a group of players with the lowest score and who didn't receive a bye yet, and gives them a bye. Returns odd-length ranking. """ if odd(ranking): bye_candidates = [x for x in ranking if not x['player'].competitor.received_bye] if not bye_candidates: # everyone received a bye -- it's probably messed up # TODO: logging return [] bye_candidates.sort(key=lambda x: x['points']) lowest_points = bye_candidates[0]['points'] lp_group = [x for x in bye_candidates if x['points'] == lowest_points] bye_receiver = pop_random(lp_group) ranking.pop(ranking.index(bye_receiver)) competitor = bye_receiver['player'].competitor competitor.received_bye = True competitor.extra_points = 3 competitor.extra_buchholz = round.index * 3 + 1 competitor.save() return ranking
def rmg(): while True: maps = list(all_maps) while len(maps) > 0: yield pop_random(maps)
def make_pairs_random(self, round, ranking): ranking = self._bye_if_odd(round, ranking) while len(ranking) > 1: yield pop_random(ranking), pop_random(ranking)