def progress_next_rounds( self, tournament, players, serialized_rounds, nb_rounds, ): """Run the following rounds.""" while nb_rounds > 0: rounds = tournament.rounds round = self.get_next_round(tournament, rounds, players) serialized_round = Round.serialized(round) serialized_rounds.append(serialized_round) tournament.update_round(serialized_rounds) tournament.update_players(players) if nb_rounds > 1: command = self.update(players, tournament) if command == "main menu": return "main menu" players = sorted( sorted( players, key=lambda player: player.rank, ), key=lambda player: player.points, reverse=True, ) nb_rounds = 4 - len(rounds) for player in players: score = player.add_final_score(player.points, player.score) Player.update_score(player, score) View.display_final_score(tournament, players)
def progress_first_round( self, tournament, players, serialized_rounds, ): """Run the first round.""" rounds = tournament.rounds round = self.get_first_round(rounds, players) serialized_round = Round.serialized(round) serialized_rounds.append(serialized_round) tournament.update_round(serialized_rounds) tournament.update_players(players) return self.update(players, tournament)
def get_command(self): "Choose a uncompleted tournament in the database." tournament = None while not tournament: name = Input.for_string("Name of an UNcompleted tournament ? ") tournament = Tournament.get(name) if not tournament: print("The value entered doesn't match any tournament !\n") rounds = tournament.rounds serialized_rounds = [] for round in rounds: serialized_round = Round.serialized(round) serialized_rounds.append(serialized_round) players = tournament.players nb_rounds = 4 - len(rounds) super().progress_next_rounds( tournament, players, serialized_rounds, nb_rounds, ) return "main menu"
def get_command(self): "Choose a uncompleted tournament in the database." tournament = self.tournament if not tournament: name = Input.for_string("Name of an UNcompleted tournament ? ") tournament = Tournament.get(name) if not tournament: return "" rounds = tournament.rounds serialized_rounds = [] for round in rounds: serialized_round = Round.serialized(round) serialized_rounds.append(serialized_round) players = tournament.players nb_rounds = 4 - len(rounds) super().progress_next_rounds( tournament, players, serialized_rounds, nb_rounds, ) return "main menu"