Exemplo n.º 1
0
 def load_tournaments(self):
     """Load tournament from database
         - Get tournaments info from database
         - Create tournaments instances.
     """
     tournaments: list[dict] = self.database.get_all_tournaments()
     for tournament in tournaments:
         # We only create a new instance if we don't already have it
         if tournament['id'] not in (
                 tournament.id
                 for tournament in Tournament.TOURNAMENT_LIST):
             # create tournament object with attributs
             tournament_obj = Tournament()
             tournament_dict = {
                 'id': tournament['id'],
                 'tournament_name': tournament['tournament_name'],
                 'location': tournament['location'],
                 'start_date': tournament['start_date'],
                 'end_date': tournament['end_date'],
                 'tour_number': tournament['tour_number'],
                 'time_controller': tournament['time_controller'],
                 'number_of_players': tournament['number_of_players'],
                 'description': tournament['description']
             }
             tournament_obj.add_tournament(tournament_dict)
             # load round for this tournament
             self.load_rounds(tournament_obj)
             # bind player with this tournament
             tournament_player = []
             for player_id in tournament['players_list']:
                 tournament_player.append(
                     Player.get_player_by_id(player_id))
             tournament_obj.bind_multiple_players(tournament_player)
         else:
             pass
Exemplo n.º 2
0
    def create_tournament(self):
        """Create tournament instance with user informations."""
        tournament_infos = self.tournois_view.get_tournament_info()
        tournament_infos['id'] = str(uuid1())
        tournois_obj = Tournament()
        tournois_obj.add_tournament(tournament_infos)

        self.add_multiple_players(int(tournois_obj.number_of_players), tournois_obj)

        self.generate_first_round(tournois_obj)
Exemplo n.º 3
0
    def new(self):
        c = main.MainController()
        name = c.input_with_options('Tournament name : ')
        place = c.input_with_options('Tournament place : ')

        date_regex = re.compile(r'^(0[1-9]|[1-2][0-9]|3[0-1])/'
                                r'(0[1-9]|1[0-2])/[0-9]{4}$')
        date_start = c.input_with_options('Tournament start date : ',
                                          date_regex,
                                          'Date format should be: dd/mm/yyyy',
                                          loop=True)
        date_end_regex = re.compile(r'^(0[1-9]|[1-2][0-9]|3[0-1])/'
                                    r'(0[1-9]|1[0-2])/[0-9]{4}$|^$')
        date_end = c.input_with_options(
            'End date ? (Empty if it\'s a 1-day tournament) : ',
            date_end_regex,
            'Date format should be: dd/mm/yyyy',
            loop=True)
        date = date_start
        if date_end != "":
            date += ' to ' + date_end

        round_number = c.input_with_options('Number of rounds : ',
                                            re.compile('^[0-9]+$'),
                                            'Please enter a positive number',
                                            loop=True)

        description = c.input_with_options('description : ')

        time_control_list = ['Bullet', 'Blitz', 'Rapid']
        text = 'Time control [{}] : \n'
        for i in range(len(time_control_list)):
            text += '    ' + str(i + 1) + ') ' + time_control_list[i] + '\n'
        time_control = c.input_with_options(text,
                                            re.compile(r'^[1-3]+$|^$'),
                                            'Please enter 1, 2 or 3',
                                            loop=True)
        if time_control in ['1', '2', '3']:
            time_control = time_control_list[int(time_control) - 1]

        tournament = Tournament(name, place, date, time_control, description,
                                round_number)

        Tournament.add_tournament(tournament)
        return tournament
Exemplo n.º 4
0
    def DEMO_import_auto_tournament(self):
        """Create random info for a tournament
        """
        tournament_infos = {'tournament_name': f"tournament_name {random.randint(0, 1000)}",
                            'location': "Strasbourg",
                            'tour_number': '4',
                            'start_date': (
                                f'''{random.randint(10, 20)}/{random.randint(10, 12)}/'''
                                f'''{random.randint(1990, 2000)}'''
                                ),
                            'time_controller': random.randint(1, 3),
                            'number_of_players': '8',
                            'description': 'Description du tournois',
                            'id': str(uuid1())}
        tournament_infos['end_date'] = tournament_infos['start_date']
        tournament_obj = Tournament()
        tournament_obj.add_tournament(tournament_infos)
        self.add_multiple_players(int(tournament_obj.number_of_players), tournament_obj)

        self.generate_first_round(tournament_obj)