def run(team_a, team_b, fast=False, dont_log=False, hidden=False, number_turns=100, path_piece_def=xdg_data_path('images/piece-default.png'), xml_file=xdg_data_path('layouts/main-layout.xml'), get_stats=False, cant_draw=False): """ Runs a game using the system expert teams given. It calls to libguadalete, generating the game and parsing the file. """ lib = libguadalete.LibGuadalete(team_a[0], team_b[0], number_turns) try: out_file, winner = lib.run_game() except LibFileError as exc: raise GuadaFileError(exc.msg) if not fast: name_team_a = filenames.extract_name_expert_system(team_a[0]) name_team_b = filenames.extract_name_expert_system(team_b[0]) _load_game_from_file(out_file, (name_team_a, team_a[1]), (name_team_b, team_b[1]), path_piece_def, xml_file, hidden, cant_draw=cant_draw) if cant_draw: winner = _handle_draw(out_file) res = winner if get_stats: res = (winner, stats.get_game_file_stats(out_file)) if dont_log or get_stats: os.remove(out_file) return res
def run(team_a, team_b, fast=False, dont_log=False, hidden=False, number_turns=100, path_piece_def=xdg_data_path('images/piece-default.png'), xml_file=xdg_data_path('layouts/main-layout.xml'), get_stats=False, cant_draw=False, logNameReference=None): """ Runs a game using the system expert teams given. It calls to libguadalete, generating the game and parsing the file. """ # Preparamos el motor con los equipos y el número de turnos lib = libguadalete.LibGuadalete(team_a[0], team_b[0], number_turns) try: # Procesamos el juego, obteniendo el fichero de log y el ganador out_file, winner = lib.run_game() except LibFileError as exc: logging.error("ERROR: %s", exc.msg) raise GuadaFileError(exc.msg) # fast indica si queremos ver solo el resultado (fast = True) o la partida # completa if not fast: # Aquí es donde se llama a la función que gestiona el dibujado del juego _load_game_from_file(out_file, team_a, team_b, path_piece_def, xml_file, hidden, cant_draw=cant_draw) reason = "normal" # Si no puede haber empate if cant_draw: # Solucionar el empate entire_game, winner = file_parser.parse_file(out_file) winner, reason = _handle_draw(entire_game, winner) # Preparamos la variable de retorno res = (winner, reason) if get_stats: res = (winner, stats.get_game_file_stats(out_file)) if logNameReference != None: logNameReference[0] = out_file if dont_log: os.remove(out_file) return res
def run(team_a, team_b, fast=False, dont_log=False, hidden=False, number_turns=100, path_piece_def=xdg_data_path('images/piece-default.png'), xml_file=xdg_data_path('layouts/main-layout.xml'), get_stats=False, cant_draw=False, logNameReference = None): """ Runs a game using the system expert teams given. It calls to libguadalete, generating the game and parsing the file. """ # Preparamos el motor con los equipos y el número de turnos lib = libguadalete.LibGuadalete(team_a[0], team_b[0], number_turns) try: # Procesamos el juego, obteniendo el fichero de log y el ganador out_file, winner = lib.run_game() except LibFileError as exc: logging.error("ERROR: %s", exc.msg) raise GuadaFileError(exc.msg) # fast indica si queremos ver solo el resultado (fast = True) o la partida # completa if not fast: # Aquí es donde se llama a la función que gestiona el dibujado del juego _load_game_from_file(out_file, team_a, team_b, path_piece_def, xml_file, hidden, cant_draw=cant_draw) reason = "normal" # Si no puede haber empate if cant_draw: # Solucionar el empate entire_game, winner = file_parser.parse_file(out_file) winner,reason = _handle_draw(entire_game, winner) # Preparamos la variable de retorno res = (winner, reason) if get_stats: res = (winner, stats.get_game_file_stats(out_file)) if logNameReference != None: logNameReference[0] = out_file if dont_log: os.remove(out_file) return res