Beispiel #1
0
def _load_game_from_file(src_file,
                         team_a,
                         team_b,
                         path_piece_def,
                         xml_file,
                         hidden=False,
                         cant_draw=False):

    entire_game, winner = file_parser.parse_file(src_file)
    if cant_draw:
        winner, kk = _handle_draw(entire_game, winner)

    music = False
    if configure.load_configuration()['music_active'] == '1':
        music = True

    if type(team_a[0]) == str:
        name_team_a = team_a[0]
        name_team_b = team_b[0]
    else:
        name_team_a = filenames.extract_name_expert_system(team_a[0])
        name_team_b = filenames.extract_name_expert_system(team_b[0])

    c_team_a = (name_team_a, team_a[1])
    c_team_b = (name_team_b, team_b[1])

    P = pintarPartida.PintarPartida(src_file, c_team_a, c_team_b, music,
                                    hidden, cant_draw)
    P.run()

    show_dialog_result((team_a[0], team_b[0]), winner)
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 _load_game_from_file(src_file, team_a, team_b, path_piece_def, xml_file,
                         hidden=False, cant_draw=False):
                         

    entire_game, winner = file_parser.parse_file(src_file)
    if cant_draw:
        winner,kk = _handle_draw(entire_game, winner)

    music = False
    if configure.load_configuration()['music_active'] == '1':
        music = True

    if type(team_a[0]) == str:
        name_team_a = team_a[0]
        name_team_b = team_b[0]
    else:
        name_team_a = filenames.extract_name_expert_system(team_a[0])
        name_team_b = filenames.extract_name_expert_system(team_b[0]) 

    c_team_a = (name_team_a, team_a[1])
    c_team_b = (name_team_b, team_b[1])

    P = pintarPartida.PintarPartida(src_file, c_team_a, c_team_b, music, hidden, cant_draw)
    P.run()

    show_dialog_result((team_a[0], team_b[0]), winner)
    def on_btn_apply_clicked(self, widget, data=None):
        correct = True
        if len(self.rules_main_team) == 0:
            self.error_es.run()
            correct = False
        if len(self.formation_main_team) == 0:
            self.error_team.run()
            correct = False

        if correct:
            main_team = (self.rules_main_team, self.formation_main_team)

            if self.all_teams:
                self.teams = selection.get_installed_teams()

            self.progress_bar.set_num_elements(self.num_rounds * len(self.teams))
            t = tests.TestSuite(main_team, _clean_dictionary(self.teams),
                                self.num_rounds, self.num_turns)
            self.progress_bar_dialog.show()
            while gtk.events_pending():
                gtk.main_iteration(False)
            t.run_test_suite(self.progress_bar)
            team = filenames.extract_name_expert_system(main_team)

            test = tests_result.testResult(t.get_test_stats(), team)
            self.progress_bar_dialog.hide()
            test.test_result.run()
            self.tests_dialog.destroy()
Beispiel #5
0
def generate_key_names(teams):
    d = {}

    for team in teams:
        name = filenames.extract_name_expert_system(team)
        d[name] = team

    return d
Beispiel #6
0
def generate_key_names(teams):
    d = {}

    for team in teams:
        name = filenames.extract_name_expert_system(team)
        d[name] = team

    return d
 def load_board(self):
     try:
         winner = guada_board.run(((self.es_team_a,self.team_team_a),
                                   xdg.get_data_path('images/piece-orange.png')),
                                  ((self.es_team_b,self.team_team_b),
                                   xdg.get_data_path('images/piece-violete.png')),
                                  self.fast_game, self.dont_save_game,
                                  self.hidde_values, str(int(self.num_turns)))
     except guada_board.GuadaFileError as e:
         raise guada_board.GuadaFileError(e.msg)
         
     if self.fast_game:
         teamA = (self.es_team_a, self.team_team_a)
         teamB = (self.es_team_b, self.team_team_b)
         name_teamA = filenames.extract_name_expert_system(teamA)
         name_teamB = filenames.extract_name_expert_system(teamB)
         n = notify_result.notifyResult((name_teamA, name_teamB), winner)
         
         n.dlg_result.run()
Beispiel #8
0
def _generate_key_names(teams):
    """
    Extract and generate the key names of the teams
    """
    _dic = {}

    for team in teams:
        name = filenames.extract_name_expert_system(team)
        _dic[name] = team

    return _dic
Beispiel #9
0
def _generate_key_names(teams):
    """
    Extract and generate the key names of the teams
    """
    _dic = {}

    for team in teams:
        name = filenames.extract_name_expert_system(team)
        _dic[name] = team

    return _dic
    def insert_element_list(self):
        s, rules_file_name = os.path.split(self.rules_selected_file)
        s, formation_file_name = os.path.split(self.formation_selected_file)
        self.files[rules_file_name] = self.rules_selected_file
        self.files[formation_file_name] = self.formation_selected_file

        name = filenames.extract_name_expert_system((rules_file_name,
                                                     formation_file_name))

        self.teams[name] = (rules_file_name, formation_file_name)

        self.list_store.append((name, rules_file_name, formation_file_name))
    def insert_element_list(self):
        s, rules_file_name = os.path.split(self.rules_selected_file)
        s, formation_file_name = os.path.split(self.formation_selected_file)
        self.files[rules_file_name] = self.rules_selected_file
        self.files[formation_file_name] = self.formation_selected_file

        name = filenames.extract_name_expert_system((rules_file_name,
                                                     formation_file_name))

        if not self.teams.has_key(name):
            self.teams[name] = (self.rules_selected_file, self.formation_selected_file)

            self.list_store.append((name, rules_file_name, formation_file_name))
            if len(self.teams) == 2:
                self.start_button.set_sensitive(True)
Beispiel #12
0
    def insert_element_list(self):
        s, rules_file_name = os.path.split(self.rules_selected_file)
        s, formation_file_name = os.path.split(self.formation_selected_file)
        self.files[rules_file_name] = self.rules_selected_file
        self.files[formation_file_name] = self.formation_selected_file

        name = filenames.extract_name_expert_system(
            (rules_file_name, formation_file_name))

        if not self.teams.has_key(name):
            self.teams[name] = (self.rules_selected_file,
                                self.formation_selected_file)

            self.list_store.append((name, rules_file_name, formation_file_name,
                                    leer_comentario(self.rules_selected_file,
                                                    wrap=False)))
            if len(self.teams) == 2:
                self.start_button.set_sensitive(True)
def init_human_game(player_formation, computer_team, player_as,
                    number_turns, dont_save=False):
    """
    Intialize the clips environment
    """
    
    
    player_num = 0
    team_a = None
    team_b = None
    name_team_a = ''
    name_team_b = ''

    team_a_piece = xdg.get_data_path('images/piece-orange.png')
    team_b_piece = xdg.get_data_path('images/piece-violete.png')
    default_piece = xdg.get_data_path('images/piece-default.png')

    formacion_temporal_player = None
    formacion_temporal_pc = None

    formacion_temporal_player = parsear_fichero_formacion(player_formation)
    player_formation = formacion_temporal_player
    formacion_temporal_pc = parsear_fichero_formacion(computer_team[1])

    computer_team = (computer_team[0], formacion_temporal_pc)

    if player_as == 'A':
        player_num = 1
        team_a = player_formation
        team_b = computer_team
        name_team_a = filenames.extract_simple_name_es((None, team_a))
        name_team_b = filenames.extract_name_expert_system(team_b)
    else:
        player_num = -1
        team_b = player_formation
        team_a = computer_team
        name_team_b = filenames.extract_simple_name_es((None, team_b))
        name_team_a = filenames.extract_name_expert_system(team_a)

    
    

    aux_team_a = (name_team_a, team_a_piece)
    aux_team_b = (name_team_b, team_b_piece)

    clips.Eval('(reset)')
    clips.Eval('(clear)')

    clips.EngineConfig.Strategy = clips.RANDOM_STRATEGY

    random.seed()
    clips.Eval("(seed %d)" % random.randint(0, 9999))

    funciones.LoadFunctions(clips)
    f1.init_world(clips, number_turns)

    try:
        f1.LoadFunctions(clips)
    except Exception:
        print clips.ErrorStream.Read()
        exit(-1)
    
    mover.LoadFunctions(clips)
    texto.LoadFunctions(clips)
    traducirF.LoadFunctions(clips)
    traducirM.LoadFunctions(clips)

    
    
    if player_num == 1:
        int_team = mirroring.interactive_formation(team_a)
        temp_team = mirroring.mirroring_team(team_b[1])

        try:
            clips.Load(int_team)
        except clips.ClipsError:
            os.remove(int_team)
            raise FileError(_('Error parsing the file ') + team_a)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_b[1])

        os.remove(int_team)
        os.remove(temp_team)

        fB.LoadFunctions(clips)
        temp_rules = mirroring.mirroring_rules(team_b[0])
        try:
            clips.Load(temp_rules)
        except clips.ClipsError:
            os.remove(temp_rules)
            raise FileError(_('Error parsing the file ') + team_b[0])
        os.remove(temp_rules)
    else:
        try:
            clips.Load(team_a[1])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[1])

        int_team = mirroring.interactive_formation(team_b)
        temp_team = mirroring.mirroring_team(int_team)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_a[1])
        os.remove(temp_team)

        fA.LoadFunctions(clips)
        try:
            clips.Load(team_a[0])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[0])

    interaccion.LoadFunctions(clips, player_as)

    
    interaccion.interaction_object = r_intact.HumanInteraction(
        aux_team_a, aux_team_b, default_piece, player_num, number_turns)

    
    clips.Reset()  # restart the environment

    
    clips.Run()  # start the simulation

    
    interaccion.interaction_object.finish()

    
    _stream = clips.StdoutStream.Read()  # print the output

    # print _stream
    # print interaccion.interaction_object.define_winner()

    if not dont_save:
        _rename_output_file(_generate_file_name(name_team_a, name_team_b))
        
    if os.path.isfile("resultado.txt"):
        os.remove('resultado.txt')

    
    os.remove(formacion_temporal_pc)
    os.remove(formacion_temporal_player)
    
    clips.Eval('(reset)')
    clips.Eval('(clear)')
Beispiel #14
0
 def insert_element_list(self):
     y = self.rules_selected_file
     z = self.formation_selected_file
     x = filenames.extract_name_expert_system((y, z))
     self.list_store.append((x, y, z))
def init_human_game(player_formation,
                    computer_team,
                    player_as,
                    number_turns,
                    dont_save=False):
    """
    Intialize the clips environment
    """

    player_num = 0
    team_a = None
    team_b = None
    name_team_a = ''
    name_team_b = ''

    team_a_piece = xdg.get_data_path('images/piece-orange.png')
    team_b_piece = xdg.get_data_path('images/piece-violete.png')
    default_piece = xdg.get_data_path('images/piece-default.png')

    formacion_temporal_player = None
    formacion_temporal_pc = None

    formacion_temporal_player = parsear_fichero_formacion(player_formation)
    player_formation = formacion_temporal_player
    formacion_temporal_pc = parsear_fichero_formacion(computer_team[1])

    computer_team = (computer_team[0], formacion_temporal_pc)

    if player_as == 'A':
        player_num = 1
        team_a = player_formation
        team_b = computer_team
        name_team_a = filenames.extract_simple_name_es((None, team_a))
        name_team_b = filenames.extract_name_expert_system(team_b)
    else:
        player_num = -1
        team_b = player_formation
        team_a = computer_team
        name_team_b = filenames.extract_simple_name_es((None, team_b))
        name_team_a = filenames.extract_name_expert_system(team_a)

    aux_team_a = (name_team_a, team_a_piece)
    aux_team_b = (name_team_b, team_b_piece)

    clips.Eval('(reset)')
    clips.Eval('(clear)')

    clips.EngineConfig.Strategy = clips.RANDOM_STRATEGY

    random.seed()
    clips.Eval("(seed %d)" % random.randint(0, 9999))

    funciones.LoadFunctions(clips)
    f1.init_world(clips, number_turns)

    try:
        f1.LoadFunctions(clips)
    except Exception:
        print clips.ErrorStream.Read()
        exit(-1)

    mover.LoadFunctions(clips)
    texto.LoadFunctions(clips)
    traducirF.LoadFunctions(clips)
    traducirM.LoadFunctions(clips)

    if player_num == 1:
        int_team = mirroring.interactive_formation(team_a)
        temp_team = mirroring.mirroring_team(team_b[1])

        try:
            clips.Load(int_team)
        except clips.ClipsError:
            os.remove(int_team)
            raise FileError(_('Error parsing the file ') + team_a)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_b[1])

        os.remove(int_team)
        os.remove(temp_team)

        fB.LoadFunctions(clips)
        temp_rules = mirroring.mirroring_rules(team_b[0])
        try:
            clips.Load(temp_rules)
        except clips.ClipsError:
            os.remove(temp_rules)
            raise FileError(_('Error parsing the file ') + team_b[0])
        os.remove(temp_rules)
    else:
        try:
            clips.Load(team_a[1])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[1])

        int_team = mirroring.interactive_formation(team_b)
        temp_team = mirroring.mirroring_team(int_team)

        try:
            clips.Load(temp_team)
        except clips.ClipsError:
            os.remove(temp_team)
            raise FileError(_('Error parsing the file ') + team_a[1])
        os.remove(temp_team)

        fA.LoadFunctions(clips)
        try:
            clips.Load(team_a[0])
        except clips.ClipsError:
            raise FileError(_('Error parsing the file ') + team_a[0])

    interaccion.LoadFunctions(clips, player_as)

    interaccion.interaction_object = r_intact.HumanInteraction(
        aux_team_a, aux_team_b, default_piece, player_num, number_turns)

    clips.Reset()  # restart the environment

    clips.Run()  # start the simulation

    interaccion.interaction_object.finish()

    _stream = clips.StdoutStream.Read()  # print the output

    # print _stream
    # print interaccion.interaction_object.define_winner()

    if not dont_save:
        _rename_output_file(_generate_file_name(name_team_a, name_team_b))

    if os.path.isfile("resultado.txt"):
        os.remove('resultado.txt')

    os.remove(formacion_temporal_pc)
    os.remove(formacion_temporal_player)

    clips.Eval('(reset)')
    clips.Eval('(clear)')
 def insert_element_list(self):
     y = self.rules_selected_file
     z = self.formation_selected_file
     x = filenames.extract_name_expert_system((y,z))
     self.list_store.append((x, y, z))