コード例 #1
0
    def new_tournament(self):
        tournaments = Query()
        name = self.get_and_check_name()
        place = self.get_and_check_place()
        date = set_date()
        time_control = self.get_and_check_time_control()
        details = get_tournament_details()
        self.tournament = Tournament(name, place, date, time_control, details)
        self.tournament.status = "En cours"
        self.tournament.players = list()
        self.tournament_data.insert(tournament_serializer(self.tournament))
        tournament_get = self.tournament_data.get(
            (tournaments.name == self.tournament.name)
            & (tournaments.place == self.tournament.place))
        tournament_id = tournament_get.doc_id
        for i in range(1, 9):
            playerController = PlayerController()
            print_text(f"Joueur {i} : ")
            player = playerController.handle_players_choice()
            self.tournament.add_player(player)
            self.tournament_data.update(tournament_serializer(self.tournament),
                                        doc_ids=[tournament_id])
        self.run_first_round()
        self.tournament_data.update(tournament_serializer(self.tournament),
                                    doc_ids=[tournament_id])
        quit = self.get_and_check_continue_or_quit()
        if quit == "q":
            return
        else:
            pass
        for round_number in range(2, 5):
            self.run_round(round_number)
            self.tournament_data.update(tournament_serializer(self.tournament),
                                        doc_ids=[tournament_id])
            quit = self.get_and_check_continue_or_quit()
            if quit == "q":
                return
            else:
                pass
        self.tournament.status = "Terminé"
        self.tournament_data.update(tournament_serializer(self.tournament),
                                    doc_ids=[tournament_id])

        update_elo = self.check_update_player_elo()

        while True:
            if update_elo == "o":
                PlayerController.update_player_elo()
                update_elo = self.check_update_player_elo()
            else:
                return
コード例 #2
0
def is_tournament_already_exist(tournament_name_response):
    list_tournament = Tournament.get_tournament_name(
        TinyDB("db.json").table("tournament")
    )
    new_tournament_name = tournament_name_response
    if list_tournament == []:
        return True
    for tournament_name in list_tournament:
        if (
            Tournament.check_tournament_duplicate(new_tournament_name, tournament_name)
            is True
        ):
            print("  Tournament already exists")
        else:
            return True
コード例 #3
0
 def tournament_deserializer(object):
     tournament_list = []
     for tournament in object:
         this_tournament = Tournament(tournament["name"],
                                      tournament["place"],
                                      tournament["date"],
                                      tournament["tours"],
                                      DataHandler.player_deserializer(
                                          tournament["players"]),
                                      tournament["timing_style"],
                                      tournament["description"],
                                      tournament["round_number"])
         this_tournament.rounds = DataHandler.round_deserializer(
             tournament["rounds"])
         tournament_list.append(this_tournament)
     return tournament_list
コード例 #4
0
    def instanciation_tournament(self, tournament_table, tournament_name):
        """ Fonction qui instancie le tournoi à partir du .json """
        liste_tournament = tournament_table.search(
            where("Name") == tournament_name)
        data = liste_tournament[0]

        self.tournament_progress = Tournament(
            data["Name"],
            data["Place"],
            data["Date"],
            data["Numbers of rounds"],
            data["Rounds"],
            [],
            data["Players"],
            data["Type"],
            data["Description"],
        )
コード例 #5
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def get(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']

		tournament  = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament Not Found',404)

		return tournament_serialize(tournament)
コード例 #6
0
    def new_tournament_created(self, db):
        self.tournament_progress = Tournament(
            vt.get_tournament_name(),
            vt.get_tournament_place(),
            str(vt.get_tournament_date()),
            4,
            [],
            [],
            [],
            vt.get_tournament_time_control(),
            vt.get_tournament_description(),
        )

        tournament_table = db.table(f"{self.tournament_progress.name}")

        serialized_tournament = self.tournament_progress.serialize()
        tournament_table.insert(serialized_tournament)

        return tournament_table
コード例 #7
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def get(self, user_id):
		args = tournamentParser.parse_args()
		page = args['page']
		if page is None:
			page = 0

		profile = Profile.objects(user=user_id).first()
		tournaments = Tournament.objects(creator=profile).only('id','creator','isEnded','createTime','rounds','isFull')

		return tournament_search_serialize(tournaments[5*page:5*(page+1)])
コード例 #8
0
ファイル: menu.py プロジェクト: AlexandreDuthil/OC-P4
    def create_tournament(self):
        name = AskInfos.tournament_name()
        while not name.replace(" ", "").isalpha():
            print("Le nom du tournoi ne peut être composé que de lettres")
            name = AskInfos.tournament_name()

        place = AskInfos.tournament_place()
        while not place.replace(" ", "").isalpha():
            print("La ville ne peut être composé que de lettres")
            place = AskInfos.tournament_place()

        date_ok = False
        date = AskInfos.tournament_date()
        while not date_ok:
            try:
                strptime(date, '%d/%m/%Y')
                date_ok = True
            except ValueError:
                print("La date doit être au format JJ/MM/AAAA")
                date = AskInfos.tournament_date()

        player_number = AskInfos.tournament_player_number()
        while not player_number.isnumeric():
            print("Le nombre de joueur doit être un chiffre ou un ensemble"
                  "de chiffres")
            player_number = AskInfos.tournament_player_number()
        while not 2 <= int(player_number) <= 1000:
            print("Le nombre de joueur doit être compris entre 2 et 1000")
            player_number = AskInfos.tournament_player_number()

        timing_style = AskInfos.tournament_timing_style().capitalize()
        while timing_style != "Blitz" and timing_style != "Bullet" and \
                timing_style != "Coup rapide":
            print("Le contrôle du temps doit être Bullet, Blitz ou "
                  "Coup rapide")
            timing_style = AskInfos.tournament_timing_style().capitalize()

        description = AskInfos.tournament_description()

        round_number = AskInfos.tournament_round_number()
        while not 1 <= int(round_number) <= 20:
            print("Le nombre de round doit être compris entre 1 et 20")
            round_number = AskInfos.tournament_round_number()

        players_list = []
        x = 1
        tours = "rien"
        for i in range(int(player_number)):
            print("Joueur " + str(x))
            players_list.append(Menu.create_player())
            x += 1
        self.actual_tournament = Tournament(name, place, date, tours,
                                            players_list, timing_style,
                                            description, round_number)
        Menu.start(self)
コード例 #9
0
    def manage_tournament(self):
        """
        Allow to create tournament if not already exist and first and other rounds
        """
        if (
            Tournament.tournament_table_is_empty(self.tournament_table) is True
            or Tournament.status_tournament_is_finished(self.tournament_table) is True
        ):
            new_tournament = Tournament.create_tournament()
            serialized_tournament = vars(new_tournament)
            self.tournament_table.insert(serialized_tournament)
            self.add_players_to_tournament()
            self.choice_create_next_round()

        elif (
            Tournament.tournament_table_is_empty(self.tournament_table) is not True
            and self.round_table.all() == []
        ) or self.round_table.all()[-1]["status_round"] == "finished":
            self.choice_create_next_round()
        else:
            self.choice_end_round()
コード例 #10
0
def tournament_deserializer(reloaded_tournament):
    tournament = Tournament(reloaded_tournament["name"],
                            reloaded_tournament["place"],
                            reloaded_tournament["date"],
                            reloaded_tournament["time_control"],
                            reloaded_tournament["details"])
    tournament.status = reloaded_tournament["status"]
    tournament.players = list()
    tournament.rounds = list()

    for player in reloaded_tournament["players"]:
        player = player_deserializer(player)
        tournament.add_player(player)

    for round in reloaded_tournament["rounds"]:
        reload_round = round_deserializer(round)
        tournament.add_round(reload_round)

    return tournament
コード例 #11
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def post(self, user_id):
		args = tournamentParser.parse_args()
		tournamentName = args['tournamentName']
		isSchool = args['isSchool']
		school = args['school']
		descriptions = args['descriptions']
		entryFee = args['entryFee']
		size = args['size']
		try:
			rounds = request.json['rounds']
		except:
			raise InvalidUsage('Round information is not valid')
		teamSize = args['teamSize']
		#group_stage = args['group_stage']
		map = args['map']
		pick = args['pick']
		roundNumber = int(math.log(size,2))
		totalPrize = args['totalPrize']
		profile = Profile.objects(user=user_id).first()

		if roundNumber != math.log(size,2):
			return {'status' : 'error', 'message' : 'size not acceptable'}

		tournament = Tournament(tournamentName=tournamentName,isSchool=isSchool,descriptions=descriptions,entryFee=entryFee,size=size,school=school,creator=profile,totalPrize=totalPrize)

		for i in range(roundNumber):
			round = Round(roundName=str(Fraction(2*(i+1)/size))+' Final', startTime=rounds[i]['startTime'], bestOfN=rounds[i]['bestOfN'])
			round.save()
			tournament.rounds.append(round)
		for i in range(roundNumber-1):
			tournament.rounds[i].next = tournament.rounds[i+1]
		tournament.rounds[roundNumber-1].next = None


		try:
			tournament.save()
		except ValidationError,e:
			raise InvalidUsage(e.message)
コード例 #12
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def get(self, user_id):
		args = tournamentParser.parse_args()
		tournamentName = args['tournamentName']
		page = args['page']

		if tournamentName is None:
			tournamentName = ''
		if page is None:
			page = 0

		tournaments = Tournament.objects(tournamentName__icontains=tournamentName).only('id','creator','isEnded','createTime','rounds','isFull')

		tournaments = tournaments.filter(isEnded=False).order_by('-createTime')[10*page:10*(page+1)]

		return tournament_search_serialize(tournaments)
コード例 #13
0
 def propose_to_load_tour():
     '''propose the user to enter the name of the tournament he wants to load
     and loads the proper tournament from the db'''
     while True:
         tournament_table = db.table('tournaments')
         all_tournaments = tournament_table.all()
         tour_name = input('Tournament name: ')
         for tournament in all_tournaments:
             if tournament['name'] == tour_name:
                 user_answer = Tournament.load_tournament(tournament)
                 print('---------------------------------------')
                 print('Tournament loaded')
                 print('---------------------------------------')
                 return user_answer
             else:
                 print('-------------')
                 print('wrong entries')
    def test_02_create_tournament(self):
        """
        Method that tests creation of a tournament in 
        database
        """
        tournament_handler = TournamentHandler()

        tournament = Tournament('CSGO Major - One Vs One 2017',
                                datetime.datetime.now(),
                                datetime.datetime.now())

        tournament_handler.create_tournament(tournament)

        self.assertTrue(tournament_handler.get_tournament() is not None,
                        "The tournament were not created.")

        print "Created tournament: [" + tournament.name[0] + "]"

        print "-----------------------------------------"
コード例 #15
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def delete(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']
		if tournamentID is None:
			raise InvalidUsage('Provide tournament id please')

		profile = Profile.objects(user=user_id).first()

		tournament = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament not found',404)
		if tournament.creator != profile:
			raise InvalidUsage('Unauthorized',401)
		# More deletions need to be added
		rule = Rule.objects(tournament=tournament).first()
		if rule is not None:
			rule.delete()
		for round in tournament.rounds:
			round.delete()

		tournament.delete()
		return {'status':'success'}
コード例 #16
0
ファイル: tournamentAPI.py プロジェクト: bintao/cteemo
	def post(self, user_id):
		args = tournamentParser.parse_args()
		tournamentID = args['tournamentID']

		tournament = Tournament.objects(id=tournamentID).first()
		if tournament is None:
			raise InvalidUsage('Tournament not found',404)
		if tournament.isEnded is True or tournament.isFull is True:
			raise InvalidUsage('Tournament full or has ended',403)

		profile = Profile.objects(user=user_id).first()
		team = profile.LOLTeam
		if team is None or team.captain != profile:
			raise InvalidUsage('Only captain can join tournament',401)
		if team.inGame is True:
			raise InvalidUsage('One team can only join one tournament at the same time',403)
		# join the first round
		round = tournament.rounds[0]
		round.checkInNumber += 1
		if round.checkInNumber == tournament.size:
			tournament.isFull = True
		tournament.save()

		if len(round.readyTeam) is 0:
			round.update(add_to_set__readyTeam=team)
		else:
			opponent = round.readyTeam[0]
			round.update(pull__readyTeam=opponent)
			match = MatchHistory(tournament=tournament,tournamentName=tournament.tournamentName,round=round,teams=[opponent,team])
			match.save()
			team.update(add_to_set__matchHistory=match)
			opponent.update(add_to_set__matchHistory=match)
			round.update(add_to_set__matches=match)
		team.inGame = True
		team.save()

		return {'status' : 'success'}
コード例 #17
0
ファイル: controller.py プロジェクト: Nyankoye/Projet4
def create_tournament():
    """ Fonction Permetant de creer un tournoi"""
    data = view.create_tournament_view()
    tournament = Tournament(data['name'], data['place'], data['description'],
                            data['turn_number'])
    return tournament
コード例 #18
0
def is_valid_id_tournament(response):
    list_tournaments = Tournament.get_tournaments(TinyDB("db.json").table("tournament"))
    if response not in list_tournaments:
        print("  Invalid tournamanet Id")
    else:
        return True
コード例 #19
0
class TournamentControler:
    """ Classe qui lance et fait fonctionner le tournoi """
    def __init__(self):
        self.tournament_progress = ""

    def new_tournament_created(self, db):
        self.tournament_progress = Tournament(
            vt.get_tournament_name(),
            vt.get_tournament_place(),
            str(vt.get_tournament_date()),
            4,
            [],
            [],
            [],
            vt.get_tournament_time_control(),
            vt.get_tournament_description(),
        )

        tournament_table = db.table(f"{self.tournament_progress.name}")

        serialized_tournament = self.tournament_progress.serialize()
        tournament_table.insert(serialized_tournament)

        return tournament_table

    def init_players(self, tournament_table, actors_db):
        """ Fonction qui instancie les joueurs du tournoi """
        for i in range(8):
            input(f"\nEnter player{i+1} informations [ENTER]\n")
            name = vp.get_player_name()
            surname = vp.get_player_surname()
            birthday = vp.get_player_birthday()
            sexe = vp.get_player_sexe()
            elo = vp.get_player_elo()
            score = 0
            player = Player(name, surname, birthday, sexe, elo, score)
            self.tournament_progress.add_player(player)

            serialized_player = player.serialize()
            actor_table = actors_db.table(f"{name}")

            User = Query()
            actor_table.upsert(serialized_player, User.name == name)

            self.tournament_progress.serialized_players.append(
                serialized_player)

        self.tournament_progress.serialized_tournament = (
            self.tournament_progress.serialize())

        tournament_table.truncate()
        tournament_table.insert(self.tournament_progress.serialized_tournament)

    def print_all_players(self):
        """ Fonction qui imprime les joueurs d'un tournoi"""
        print(self.tournament_progress.players)

    def handle_score(self, match):
        """ Fonction qui calcule le score d'un match """
        score = vr.enter_score(match)
        while score != "1" and score != "2" and score != "3":
            score = vr.enter_score(match)

        if score == "1":
            return 1, 0
        elif score == "2":
            return 0, 1
        elif score == "3":
            return 0.5, 0.5

    def get_players(self):
        """ Fonction qui tri les players par elo et par score """
        players = []
        for player in self.tournament_progress.players:
            players.append(player)
        players.sort(key=lambda x: x.elo)
        players.sort(key=lambda x: x.score, reverse=True)

        return players

    def make_pairing(self, players, current_round):
        """ Algorithme qui crée les paires de match """
        i = 0
        while len(players) != 0:
            player1 = players[i]
            player1_index = i
            player2 = players[i + 1]
            player2_index = i + 1

            player2_id = player2.surname + player2.elo
            while player2_id in player1.opponents:
                try:
                    i += 1
                    player2 = players[i + 1]
                    player2_index = i + 1
                    player2_id = player2.surname + player2.elo

                except IndexError:
                    player2 = players[i]
                    player2_index = i
                    player2_id = player2.surname + player2
                    break

            current_round.add_match(player1, player2)

            del players[player2_index]
            del players[player1_index]

            i = 0

    def run_first_round(self, tournament_table, actors_db):
        """ Fonction qui fait tourner le premier round """
        round_name = "Round 1"
        round_date = str(vr.get_round_date())
        round_starttime = str(vr.get_round_starttime())
        round1 = Round(round_name, round_date, round_starttime)
        serialized_round1 = round1.serialize()

        self.tournament_progress.serialized_rounds.append(serialized_round1)
        self.tournament_progress.serialized_rounds = (
            self.tournament_progress.serialized_rounds)
        vt.print_info(
            f"{self.tournament_progress.name} begins !\n--------------------------------------\n"
        )
        vt.print_info(f"{round_name} launchment...")

        self.tournament_progress.players.sort(key=lambda x: x.elo)
        for i in range(4):
            round1.add_match(
                self.tournament_progress.players[i],
                self.tournament_progress.players[4 + i],
            )
        self.tournament_progress.add_round(round1)

        i = 0
        for match in self.tournament_progress.rounds[0].matchs:
            vt.print_info("\n...\n")
            vt.print_info(
                f"{match.player1.name} and {match.player2.name} play against each other !"
            )
            match.score1, match.score2 = self.handle_score(match)
            i += 1

            vr.print_match_result(match)

            serialized_match = match.serialize()
            round1.serialized_matchs.append(serialized_match)

            match.player1.add_opponent(match.player2)
            match.player2.add_opponent(match.player1)
            match.player1.add_score(match.score1)
            match.player2.add_score(match.score2)

            tournament_table.truncate()
            tournament_table.insert(
                self.tournament_progress.serialized_tournament)

        round1.endtime = str(vr.get_round_endtime())
        serialized_round1 = {
            "Round end-time": round1.endtime,
            "Round Matchs": round1.serialized_matchs,
        }
        self.tournament_progress.serialized_tournament = (
            self.tournament_progress.serialize())
        tournament_table.truncate()
        tournament_table.insert(self.tournament_progress.serialized_tournament)

        vt.print_info(f"End of the Round1 at {round1.endtime}.")
        vt.print_info("\n--------------------------------------\n")

    def run_rounds(self, tournament_table, actors_db, next_round_number=2):
        """ Fonction qui fait tourner les rounds suivants """
        for i in range(next_round_number, 5):
            players = self.get_players()
            round_name = f"Round {i}"
            round_date = vr.get_round_date()
            round_starttime = vr.get_round_starttime()
            round_endtime = " "
            next_round = Round(round_name, round_date, round_starttime,
                               round_endtime)
            self.tournament_progress.add_round(next_round)

            serialized_next_round = next_round.serialize()

            self.tournament_progress.serialized_rounds.append(
                serialized_next_round)
            self.tournament_progress.serialized_rounds = (
                self.tournament_progress.serialized_rounds)
            self.serialized_tournament = self.tournament_progress.serialize()

            vt.print_info(f"{round_name} launchment...")

            self.make_pairing(players, next_round)
            self.tournament_progress.serialized_players.clear()

            for match in self.tournament_progress.rounds[i - 1].matchs:
                vt.print_info("\n...\n")
                vt.print_info(
                    f"{match.player1.name} and {match.player2.name} play against each other !"
                )

                match.score1, match.score2 = self.handle_score(match)
                vr.print_match_result(match)

                serialized_match = match.serialize()
                next_round.serialized_matchs.append(serialized_match)

                match.player1.add_opponent(match.player2)
                match.player2.add_opponent(match.player1)
                match.player1.add_score(match.score1)
                match.player2.add_score(match.score2)

                serialized_player1 = match.player1.serialize()
                self.tournament_progress.serialized_players.append(
                    serialized_player1)

                serialized_player2 = match.player2.serialize()
                self.tournament_progress.serialized_players.append(
                    serialized_player2)

                self.tournament_progress.serialized_tournament = (
                    self.tournament_progress.serialize())
                tournament_table.update(
                    self.tournament_progress.serialized_tournament)

            next_round.endtime = vr.get_round_endtime()
            endtime = next_round.serialize_endtime()

            tournament_table.update(
                self.tournament_progress.serialized_tournament)
            vt.print_info(f"End of the {round_name} at {next_round.endtime}.")
            vt.print_info("\n--------------------------------------\n")
            i += 1

        self.tournament_progress.serialized_tournament = (
            self.tournament_progress.serialize())
        vt.print_info(
            f"{self.tournament_progress.name} is over !\n--------------------------------------\n"
        )
        vt.print_players_scores(self.tournament_progress.players)
        return tournament_table, actors_db

    def run_ungoing_tournament(self, db, tournament_name, actors_db):
        """ Fonction qui reprends un tournoi existant non terminé """
        tournament_table = db.table(f"{tournament_name}")

        self.instanciation_tournament(tournament_table, tournament_name)
        self.instanciation_players()
        self.instanciation_rounds()

        last_round_index = 0

        for i in range(len(self.tournament_progress.rounds) - 1):
            self.instanciation_matchs(i)
            last_round_index += 1

        r = len(self.tournament_progress.rounds)
        m = len(self.tournament_progress.rounds[last_round_index].matchs)

        if r == 0 and m < 3:
            self.run_first_round(tournament_table, actors_db)
        elif r == 1 and m < 3:
            self.run_rounds(tournament_table, actors_db, next_round_number=2)
        elif r == 2 and m < 3:
            self.run_rounds(tournament_table, actors_db, next_round_number=3)
        elif r == 3 and m < 3:
            self.run_rounds(tournament_table, actors_db, next_round_number=4)

    def instanciation_tournament(self, tournament_table, tournament_name):
        """ Fonction qui instancie le tournoi à partir du .json """
        liste_tournament = tournament_table.search(
            where("Name") == tournament_name)
        data = liste_tournament[0]

        self.tournament_progress = Tournament(
            data["Name"],
            data["Place"],
            data["Date"],
            data["Numbers of rounds"],
            data["Rounds"],
            [],
            data["Players"],
            data["Type"],
            data["Description"],
        )

    def instanciation_players(self):
        """ Fonction qui instancie les joueurs du tournoi à partir du .json """
        for serialized_player in self.tournament_progress.serialized_players:

            p = Player(
                serialized_player["Name"],
                serialized_player["Surname"],
                serialized_player["Birthday"],
                serialized_player["Sexe"],
                serialized_player["ELO"],
            )
            self.tournament_progress.add_player(p)

    def instanciation_rounds(self):
        """ Fonction qui instancie les rounds du tournoi à partir du .json """
        for serialized_round in self.tournament_progress.serialized_rounds:

            r = Round(
                serialized_round["Name"],
                serialized_round["Date"],
                serialized_round["Round start-time"],
                [],
            )

            self.tournament_progress.add_round(r)

    def instanciation_matchs(self, i):
        """ Fonction qui instancie les matchs du tournoi à partir du .json """
        round_table = self.tournament_progress.serialized_rounds[i]
        round_matchs = round_table["Round Matchs"]

        for s_match in round_matchs:
            print(s_match)
            m = Match(
                player1=s_match["Player1"],
                player2=s_match["Player2"],
                score1=s_match["Score1"],
                score2=s_match["Score2"],
            )

            self.tournament_progress.rounds[i].add_match(m.player1, m.player2)

    def run_new_tournament(self, db, actors_db):
        """ Fonction qui lance un nouveau tournoi """
        tournament_table = self.new_tournament_created(db)

        self.init_players(tournament_table, actors_db)
        self.run_first_round(tournament_table, actors_db)
        self.run_rounds(tournament_table, actors_db)
コード例 #20
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from model.tournament import Tournament


current_tournament = Tournament()
players = []
result_list = []
number_of_player = 8
コード例 #21
0
 def create_new_tournament():
     '''allows the use to create a new tournament'''
     tournament = Tournament(name=input('name: '),
                             place=input('place: '),
                             date=input('date: '))
     return tournament
コード例 #22
0
class TournamentController:
    def __init__(self):
        self.tournament = None
        self.db = TinyDB("tournament_data.json", indent=4)
        self.tournament_data = self.db.table("tournament_data")

    def new_tournament(self):
        tournaments = Query()
        name = self.get_and_check_name()
        place = self.get_and_check_place()
        date = set_date()
        time_control = self.get_and_check_time_control()
        details = get_tournament_details()
        self.tournament = Tournament(name, place, date, time_control, details)
        self.tournament.status = "En cours"
        self.tournament.players = list()
        self.tournament_data.insert(tournament_serializer(self.tournament))
        tournament_get = self.tournament_data.get(
            (tournaments.name == self.tournament.name)
            & (tournaments.place == self.tournament.place))
        tournament_id = tournament_get.doc_id
        for i in range(1, 9):
            playerController = PlayerController()
            print_text(f"Joueur {i} : ")
            player = playerController.handle_players_choice()
            self.tournament.add_player(player)
            self.tournament_data.update(tournament_serializer(self.tournament),
                                        doc_ids=[tournament_id])
        self.run_first_round()
        self.tournament_data.update(tournament_serializer(self.tournament),
                                    doc_ids=[tournament_id])
        quit = self.get_and_check_continue_or_quit()
        if quit == "q":
            return
        else:
            pass
        for round_number in range(2, 5):
            self.run_round(round_number)
            self.tournament_data.update(tournament_serializer(self.tournament),
                                        doc_ids=[tournament_id])
            quit = self.get_and_check_continue_or_quit()
            if quit == "q":
                return
            else:
                pass
        self.tournament.status = "Terminé"
        self.tournament_data.update(tournament_serializer(self.tournament),
                                    doc_ids=[tournament_id])

        update_elo = self.check_update_player_elo()

        while True:
            if update_elo == "o":
                PlayerController.update_player_elo()
                update_elo = self.check_update_player_elo()
            else:
                return

    def reload_tournament(self):
        self.db = TinyDB("tournament_data.json", indent=4)
        tournaments = Query()
        self.tournament_data = self.db.table("tournament_data")

        db_tournament = self.tournament_data.search(
            tournaments.status == "En cours")

        while is_query_empty(db_tournament):
            error_message("Aucun tournoi en cours")
            return

        print_current_tournaments()

        for db_tour in db_tournament:
            number_round_to_run = 4 - len(db_tour["rounds"])
            print_existing_tournaments(db_tour)
            print_number_round_to_run(number_round_to_run)

        choice = tournament_choice()

        reloaded_tournament = self.tournament_data.get(doc_id=choice)

        self.tournament = None
        self.tournament = tournament_deserializer(reloaded_tournament)
        self.tournament.date = set_date()

        nb_of_players = len(self.tournament.players)

        if nb_of_players < 8:
            for i in range(1, (9 - nb_of_players)):
                playerController = PlayerController()
                print_text(f"Joueur {i + nb_of_players} : ")
                player = playerController.handle_players_choice()
                self.tournament.add_player(player)
                self.tournament_data.update(tournament_serializer(
                    self.tournament),
                                            doc_ids=[choice])

        number_round_to_run = 4 - len(self.tournament.rounds)

        if number_round_to_run == 4:
            self.run_first_round()
            self.tournament_data.update(tournament_serializer(self.tournament),
                                        doc_ids=[choice])
            quit = self.get_and_check_continue_or_quit()
            if quit == "q":
                return
            else:
                pass
            for i in range(2, 5):
                self.run_round(i)
                self.tournament_data.update(tournament_serializer(
                    self.tournament),
                                            doc_ids=[choice])
                quit = self.get_and_check_continue_or_quit()
                if quit == "q":
                    return
                else:
                    pass
        else:
            for i in range(len(self.tournament.rounds) + 1, 5):
                self.run_round(i)
                self.tournament_data.update(tournament_serializer(
                    self.tournament),
                                            doc_ids=[choice])
                quit = self.get_and_check_continue_or_quit()
                if quit == "q":
                    return
                else:
                    pass
        self.tournament.status = "Terminé"
        self.tournament_data.update(tournament_serializer(self.tournament),
                                    doc_ids=[choice])

        update_elo = self.check_update_player_elo()

        while True:
            if update_elo == "o":
                PlayerController.update_player_elo()
                update_elo = self.check_update_player_elo()
            else:
                return

    def run_first_round(self):
        # algorithme pour créer les premiers rounds

        match_number = 1

        start_time = set_round_time()
        end_time = None
        round1 = Round("1", start_time, end_time)
        self.tournament.add_round(round1)

        player_for_round = self.get_players()
        print_player(player_for_round)

        for i in range(4):
            round1.add_match(player_for_round[i], player_for_round[i + 4])

        for match in round1.matches:
            match.player1.opponent.append(match.player2.elo)
            match.player2.opponent.append(match.player1.elo)

        for match in self.tournament.rounds[0].matches:
            print_text(f"\nROUND #1 - MATCH #{match_number}")
            print_match(match)
            match.score_player1, match.score_player2 = self.handle_score()
            print_text(f"\nRÉSULTAT DU MATCH #{match_number}")
            match_number += 1
            print_match_result(match)
            self.update_tournament_score(match)
        self.tournament.players.sort(key=lambda x: x.elo, reverse=True)
        self.tournament.players.sort(key=lambda x: x.score, reverse=True)
        print_final_score(self.tournament.players, round1.round_number)
        round1.end_time = set_round_time()

    def run_round(self, round_number):
        match_number = 1

        start_time = set_round_time()
        end_time = None
        round = Round(str(round_number), start_time, end_time)
        self.tournament.add_round(round)

        player_for_round = self.get_players()
        print_player(player_for_round)

        index_player = 0

        while len(player_for_round) != 0:
            player1 = player_for_round[index_player]
            player1_index = index_player
            player2 = player_for_round[index_player + 1]
            player2_index = index_player + 1

            while player2.elo in player1.opponent:
                index_player += 1
                player2 = player_for_round[index_player + 1]
                player2_index = index_player + 1
            round.add_match(player1, player2)
            del player_for_round[player1_index]
            del player_for_round[player2_index - 1]
            index_player = 0

        for match in round.matches:
            match.player1.opponent.append(match.player2.elo)
            match.player2.opponent.append(match.player1.elo)

        for i in range(1, 2):
            for match in self.tournament.rounds[round_number - 1].matches:
                print_text(f"\nROUND #{round_number} - MATCH #{match_number}")
                print_match(match)
                match.score_player1, match.score_player2 = self.handle_score()
                print_text(f"\nRÉSULTAT DU MATCH #{match_number}")
                match_number += 1
                print_match_result(match)
                self.update_tournament_score(match)
        self.tournament.players.sort(key=lambda x: x.elo, reverse=True)
        self.tournament.players.sort(key=lambda x: x.score, reverse=True)
        print_final_score(self.tournament.players, round.round_number)
        round.end_time = set_round_time()

    def get_players(self):
        player_for_round = list()
        for player in self.tournament.players:
            player_for_round.append(player)
        player_for_round.sort(key=lambda x: x.elo, reverse=True)
        player_for_round.sort(key=lambda x: x.score, reverse=True)
        return player_for_round

    def handle_score(self):
        score = enter_score()
        if (score == "1"):
            return 1, 0
        elif (score == "2"):
            return 0, 1
        else:
            return 0.5, 0.5

    def get_and_check_name(self):
        name = get_tournament_name()
        name = name.strip().capitalize()
        while not is_tournament_name_valid(name):
            error_message("Le format du nom est incorrect")
            name = get_tournament_name()
            name = name.strip().capitalize()
        return name

    def get_and_check_place(self):
        place = get_tournament_place()
        place = place.strip().capitalize()
        while not is_place_valid(place):
            error_message("Le format du lieu est incorrect")
            place = get_tournament_place()
            place = place.strip().capitalize()
        return place

    def get_and_check_time_control(self):
        time_control = get_tournament_time_control()
        time_control = time_control.lower()
        while is_time_control_valid(time_control):
            error_message("Le format du contrôle du temps est incorrect")
            time_control = get_tournament_time_control()
            time_control = time_control.lower()
        else:
            time_control = time_control_def(time_control)
        return time_control

    def get_and_check_continue_or_quit(self):
        quit = get_continue_or_quit()
        quit = quit.lower()

        while not is_continue_or_quit(quit):
            error_message("Aucune commande correspondante")
            quit = get_continue_or_quit()
            quit = quit.lower()
        return quit

    def update_tournament_score(self, match):
        match.player1.score += match.score_player1
        match.player2.score += match.score_player2

    def check_update_player_elo(self):
        update_elo = print_update_player_elo()
        update_elo = update_elo.lower()

        while not is_update_player_elo_valid(update_elo):
            error_message("Entrez uniquement " "O" " ou " "N" "")
            update_elo = print_update_player_elo()
            update_elo = update_elo.lower()
        return update_elo