コード例 #1
0
    def __init__(self, teams, num_turns, back_round=False, log_folder=None):
        self.teams = teams
        self.translator = contest.generate_key_names(teams)
        self.keys = []
        self.num_turns = num_turns
        self.log_folder = log_folder

        for t in self.translator:
            self.keys.append(t)

        self.matchs = pairing.make_pairings(self.keys, back_round)

        self.rounds = []

        for jorn in self.matchs:
            self.rounds.append(
                round.Round(jorn, self.translator, self.num_turns))

        self.puntuations_by_round = []
        self.puntuations = {}
        for key in self.keys:
            self.puntuations[key] = 0

        self.number_of_rounds = len(self.rounds)
        self.current_round = 0
        self.league_completed = False
コード例 #2
0
ファイル: league.py プロジェクト: pablorecio/resistencia-1812
    def __init__(self, teams, num_turns, back_round=False):
        self.teams = teams
        self.translator = contest.generate_key_names(teams)
        self.keys = []
        self.num_turns = num_turns

        for t in self.translator:
            self.keys.append(t)

        self.matchs = pairing.make_pairings(self.keys, back_round)

        self.rounds = []
        base_path = configure.load_configuration()['games_path'] + '/'
        self.tournament_file_name = base_path + filenames.generate_filename('league')
        print self.tournament_file_name
        
        for jorn in self.matchs:
            self.rounds.append(round.Round(jorn, self.translator,
                                           self.tournament_file_name,
                                           self.num_turns))

        self.puntuations_by_round = []
        self.puntuations = {}
        for key in self.keys:
            self.puntuations[key] = 0

        self.number_of_rounds = len(self.rounds)
        self.actual_round = 0
        self.league_completed = False
コード例 #3
0
    def __init__(self, teams, num_turns, pairings_done=False):
        self.matchs = []
        self.teams = []
        self.round_winners = []
        self.num_turns = num_turns
        if pairings_done:
            self.matchs.append(teams)
            self.teams = _extract_teams_from_pairing(self.matchs)
        else:
            self.teams = teams

        self.translator = contest.generate_key_names(self.teams)
        self.keys = []
        
        for t in self.translator:
            self.keys.append(t)

        if not pairings_done:
            self.matchs.append(_auto_pairings(self.keys))

        self.round_number = 0
        self.rounds = []
        
        base_path = configure.load_configuration()['games_path'] + '/'
        self.tournament_file_name = base_path + filenames.generate_filename('tournament')
        
        self.rounds.append(round.Round(self.matchs[self.round_number],
                                       self.translator,
                                       self.tournament_file_name,
                                       self.num_turns))

        self.number_of_rounds = int(math.ceil(math.log(len(self.teams),2)))
        self.tournament_completed = False
コード例 #4
0
ファイル: league.py プロジェクト: rompehielos013013013/gsiege
    def __init__(self, teams, num_turns, back_round=False, log_folder = None):
        self.teams = teams
        self.translator = contest.generate_key_names(teams)
        self.keys = []
        self.num_turns = num_turns
        self.log_folder = log_folder

        for t in self.translator:
            self.keys.append(t)

        self.matchs = pairing.make_pairings(self.keys, back_round)

        self.rounds = []

        for jorn in self.matchs:
            self.rounds.append(round.Round(jorn, self.translator,
                                           self.num_turns))

        self.puntuations_by_round = []
        self.puntuations = {}
        for key in self.keys:
            self.puntuations[key] = 0

        self.number_of_rounds = len(self.rounds)
        self.current_round = 0
        self.league_completed = False
コード例 #5
0
ファイル: main.py プロジェクト: pablorecio/resistencia-1812
def _get_teams_next_round(teams, classifications):
    translator = contest.generate_key_names(teams)

    teams_next_round = []
    n = len(teams) / 2

    for i in range(n):
        teams_next_round.append(translator[classifications[i]])

    return teams_next_round
コード例 #6
0
def _get_teams_next_round(teams, classifications):
    translator = contest.generate_key_names(teams)

    teams_next_round = []
    n = len(teams) / 2

    for i in range(n):
        teams_next_round.append(translator[classifications[i]])

    return teams_next_round
コード例 #7
0
    def __init__(self, teams, num_turns, pairings_done=False, log_folder = None):
            
        self.matchs = []
        self.teams = []
        self.round_winners = []
        self.round_reasons = []
        self.num_turns = num_turns

        self.log_folder = log_folder

        if pairings_done:
            self.matchs.append(teams)
            self.teams = _extract_teams_from_pairing(self.matchs)
        else:
            self.teams = teams

        self.translator = contest.generate_key_names(self.teams)
        self.keys = []

        for t in self.translator:
            self.keys.append(t)

        
        random.shuffle(self.keys)

        if not pairings_done:
            self.matchs.append(_auto_pairings(self.keys))

        self.current_round = 0
        self.rounds = []

        self.rounds.append(round.Round(self.matchs[self.current_round],
                                       self.translator,
                                       self.num_turns))

        self.number_of_rounds = int(math.log(len(self.matchs[0]), 2)) + 1
        
        logging.info("Torneo creado")
        logging.info("%s partidos en la primera ronda", str(len(self.matchs[0])))
        logging.info("%s rondas totales", str(self.number_of_rounds))
コード例 #8
0
ファイル: main.py プロジェクト: rompehielos013013013/gsiege
def _init_game(game_type, teams, fast, num_turns, back_round = False, log_base_folder = None):

    logging.info(">>>> INIT GAME")

    if log_base_folder == None:
        log_base_folder = configure.load_configuration()['games_path'] + '/'


    # Generamos el nombre del fichero de log según el tipo de juego
    log_base_name = filenames.generate_filename(game_type, noExtension = True)
    log_folder_name = log_base_folder + log_base_name
    log_file_name = log_folder_name + "/" + game_type + ".txt"

    logging.info("Fichero de log: %s", log_file_name)
    logging.info("Carpeta de log: %s", log_folder_name)

    os.mkdir(log_folder_name)
    
    # Lanzamos el tipo de juego apropiado
    if game_type == 'cup':
        game = tournament.Tournament(teams, num_turns, log_folder = log_folder_name)
    else:
        game = league.League(teams, num_turns, back_round, log_folder = log_folder_name)

    band = False

    # Contenedor para clasificaciones
    classifications = {}

    results = None

    # Cada elemento tendrá una tupla de 3: ganadas, empatadas y perdidas
    estadisticas = {"aux_ghost_team": {"ganadas":0, "empatadas":0, "perdidas":0}}

    for equipo in contest.generate_key_names(teams).keys():
        estadisticas[equipo] = {"ganadas":0, "empatadas":0, "perdidas":0};

    # Mientras no se haya completado el juego
    while not game.completed() and not band and not controlPartida.flagCancelarCampeonato:

        logging.info("---- START OF THE ROUND")

        if results != None:

            # Cargamos el diálogo de resultados
            R = round_results.roundResults(classifications, results,
                                           game.get_prev_round_number() + 1,
                                           game.get_number_of_rounds(),
                                           show_classifications = (game_type != 'cup'),
                                           stats = estadisticas,
                                           show_top_teams = True,
                                           next_matches = game.matchs[game.get_round_number()])

        # Mostramos el diálogo de resultados
            button_pressed = R.result_dialog.run()
        
            while gtk.events_pending():
                gtk.main_iteration(False)
            
            if button_pressed == -4 or button_pressed == 0:
                band = True
                continue


        # Guardamos el número de la ronda
        roundNumber = game.get_round_number()

        if roundNumber == 0:
            show_round_matches(game)

        # Por defecto que la barra de progreso no exista
        progress_bar = None

        # Si no mostramos el progreso del juego, que salga la barra
        if fast:
            progress_bar = pbs.ProgressBarDialog(None, _('Running the contest'))
            progress_bar_dialog = progress_bar.progress_bar_dialog
            progress_bar.set_num_elements(game.get_round(roundNumber).number_games)
            progress_bar_dialog.show()

            while gtk.events_pending():
                gtk.main_iteration(False)
    
        # Jugamos esta ronda
        game.play_round(progress_bar, fast)

        if controlPartida.flagCancelarCampeonato:
            return
        
        # Guardamos en r la ronda actual, con sus resultados y tal
        r = game.get_round(roundNumber)
        
        # Resultados de la ronda
        results = r.get_round_results()

        # Actualizamos el fichero del log
        update_log_round(log_file_name, results, roundNumber)

        for partido in results:
            if partido[1] == 1:
                estadisticas[partido[0][0]]["ganadas"] += 1
                estadisticas[partido[0][1]]["perdidas"] += 1
            elif partido[1] == -1:
                estadisticas[partido[0][1]]["ganadas"] += 1
                estadisticas[partido[0][0]]["perdidas"] += 1                    
            else:
                estadisticas[partido[0][0]]["empatadas"] += 1
                estadisticas[partido[0][1]]["empatadas"] += 1

        if game_type == 'cup':
            pass
        else:
            # "Puntuations" es una palabra que no existe
            classifications = game.get_actual_puntuations()

        # Ocultamos la barra de progreso (que ya habrá acabado)
        if fast:
            progress_bar_dialog.hide()

        logging.info("---- END OF THE ROUND")

    if not band:
        # Mostramos los resultados FINALES
        R = round_results.roundResults(classifications, results,
                                       game.get_prev_round_number() + 1,
                                       game.get_number_of_rounds(),
                                       show_classifications = (game_type != 'cup'),
                                       show_top_teams = True,
                                       stats = estadisticas)

        # Mostramos el diálogo de resultados
        button_pressed = R.result_dialog.run()
        
        while gtk.events_pending():
            gtk.main_iteration(False)
            
    if not band and not controlPartida.flagCancelarCampeonato:
        if game_type == 'cup':
            update_log_ending_tournament(log_file_name, estadisticas)
            dibujoClasificacion = dibujo_clasificacion.DibujoClasificacion(game)
        else:        
            update_log_ending_league(log_file_name, classifications)
        
    logging.info(">>>> END INIT GAME")
    return (band, classifications)
コード例 #9
0
def _init_game(game_type,
               teams,
               fast,
               num_turns,
               back_round=False,
               log_base_folder=None):

    logging.info(">>>> INIT GAME")

    if log_base_folder == None:
        log_base_folder = configure.load_configuration()['games_path'] + '/'

    # Generamos el nombre del fichero de log según el tipo de juego
    log_base_name = filenames.generate_filename(game_type, noExtension=True)
    log_folder_name = log_base_folder + log_base_name
    log_file_name = log_folder_name + "/" + game_type + ".txt"

    logging.info("Fichero de log: %s", log_file_name)
    logging.info("Carpeta de log: %s", log_folder_name)

    os.mkdir(log_folder_name)

    # Lanzamos el tipo de juego apropiado
    if game_type == 'cup':
        game = tournament.Tournament(teams,
                                     num_turns,
                                     log_folder=log_folder_name)
    else:
        game = league.League(teams,
                             num_turns,
                             back_round,
                             log_folder=log_folder_name)

    band = False

    # Contenedor para clasificaciones
    classifications = {}

    results = None

    # Cada elemento tendrá una tupla de 3: ganadas, empatadas y perdidas
    estadisticas = {
        "aux_ghost_team": {
            "ganadas": 0,
            "empatadas": 0,
            "perdidas": 0
        }
    }

    for equipo in contest.generate_key_names(teams).keys():
        estadisticas[equipo] = {
            "ganadas": 0,
            "empatadas": 0,
            "perdidas": 0
        }

    # Mientras no se haya completado el juego
    while not game.completed(
    ) and not band and not controlPartida.flagCancelarCampeonato:

        logging.info("---- START OF THE ROUND")

        if results != None:

            # Cargamos el diálogo de resultados
            R = round_results.roundResults(
                classifications,
                results,
                game.get_prev_round_number() + 1,
                game.get_number_of_rounds(),
                show_classifications=(game_type != 'cup'),
                stats=estadisticas,
                show_top_teams=True,
                next_matches=game.matchs[game.get_round_number()])

            # Mostramos el diálogo de resultados
            button_pressed = R.result_dialog.run()

            while gtk.events_pending():
                gtk.main_iteration(False)

            if button_pressed == -4 or button_pressed == 0:
                band = True
                continue

        # Guardamos el número de la ronda
        roundNumber = game.get_round_number()

        if roundNumber == 0:
            show_round_matches(game)

        # Por defecto que la barra de progreso no exista
        progress_bar = None

        # Si no mostramos el progreso del juego, que salga la barra
        if fast:
            progress_bar = pbs.ProgressBarDialog(None,
                                                 _('Running the contest'))
            progress_bar_dialog = progress_bar.progress_bar_dialog
            progress_bar.set_num_elements(
                game.get_round(roundNumber).number_games)
            progress_bar_dialog.show()

            while gtk.events_pending():
                gtk.main_iteration(False)

        # Jugamos esta ronda
        game.play_round(progress_bar, fast)

        if controlPartida.flagCancelarCampeonato:
            return

        # Guardamos en r la ronda actual, con sus resultados y tal
        r = game.get_round(roundNumber)

        # Resultados de la ronda
        results = r.get_round_results()

        # Actualizamos el fichero del log
        update_log_round(log_file_name, results, roundNumber)

        for partido in results:
            if partido[1] == 1:
                estadisticas[partido[0][0]]["ganadas"] += 1
                estadisticas[partido[0][1]]["perdidas"] += 1
            elif partido[1] == -1:
                estadisticas[partido[0][1]]["ganadas"] += 1
                estadisticas[partido[0][0]]["perdidas"] += 1
            else:
                estadisticas[partido[0][0]]["empatadas"] += 1
                estadisticas[partido[0][1]]["empatadas"] += 1

        if game_type == 'cup':
            pass
        else:
            # "Puntuations" es una palabra que no existe
            classifications = game.get_actual_puntuations()

        # Ocultamos la barra de progreso (que ya habrá acabado)
        if fast:
            progress_bar_dialog.hide()

        logging.info("---- END OF THE ROUND")

    if not band:
        # Mostramos los resultados FINALES
        R = round_results.roundResults(
            classifications,
            results,
            game.get_prev_round_number() + 1,
            game.get_number_of_rounds(),
            show_classifications=(game_type != 'cup'),
            show_top_teams=True,
            stats=estadisticas)

        # Mostramos el diálogo de resultados
        button_pressed = R.result_dialog.run()

        while gtk.events_pending():
            gtk.main_iteration(False)

    if not band and not controlPartida.flagCancelarCampeonato:
        if game_type == 'cup':
            update_log_ending_tournament(log_file_name, estadisticas)
            dibujoClasificacion = dibujo_clasificacion.DibujoClasificacion(
                game)
        else:
            update_log_ending_league(log_file_name, classifications)

    logging.info(">>>> END INIT GAME")
    return (band, classifications)