Beispiel #1
0
    def play_match(self, fast=False, cant_draw=False, log_folder = None):
        logging.info("*************************************")
        logging.info("** JUGANDO PARTIDO")
        teamA_key = self.round[self.next_game][0][0]
        teamB_key = self.round[self.next_game][0][1]
        teamA = None
        teamB = None
        
        result = 0
        reason = "normal"
        if (not teamA_key == 'aux_ghost_team') and (not teamB_key == 'aux_ghost_team'):
            logging.info("- Partido normal")
            
            teamA = (self.translator[teamA_key], _pieceA)
            teamB = (self.translator[teamB_key], _pieceB)
            
            try:
                log_container = [""]
                result, reason = guada_board.run(teamA, teamB, fast=fast,
                                         hidden=False,
                                         number_turns=self.num_turns,
                                         cant_draw=cant_draw, logNameReference = log_container)
                if log_folder != None:
                    os.rename(log_container[0],
                              log_folder + "/" + os.path.basename(log_container[0]))
            except:
                logging.info("ERROR!")
                
            
        else:
            logging.info("- Partido contra equipo fantasma")
            if teamA_key == 'aux_ghost_team':
                result = -1
            else: #teamB_key == 'aux_ghost_team':
                result = 1

        logging.info("** PARTIDO FINALIZADO:")
        logging.info("Resultado del juego '" + teamA_key + "' vs '"+ teamB_key + "' was:")

        if result == 0:
            logging.info('Empate')
        elif result == 1:
            logging.info(teamA_key + ' ganó')
        elif result == -1:
            logging.info(teamB_key + ' ganó')

        logging.info("")

        self.round[self.next_game] = (self.round[self.next_game][0], True, result, reason)
        
        #self.round[self.next_game][1] = True
        #self.round[self.next_game][2] = result

        self.next_game = self.next_game + 1
        self.completed = (self.next_game == self.number_games)

        return (self.round[self.next_game-1][0], self.round[self.next_game-1][2], self.round[self.next_game-1][3])
    def load_board(self):
        controlPartida.restaurarCampeonato()

        ambosEquipos = [(self.es_team_a, self.team_team_a), (self.es_team_b, self.team_team_b)]
        
        for equipo in ambosEquipos:
            if (not filenames.comprobar_nombre_reglas(equipo[0]) or 
                not filenames.comprobar_nombre_formacion(equipo[1])):

                return

            logging.info("Probando equipo: %s", equipo)
            try:
                probar_equipo(equipo)
            except Exception as e:
                #progress_bar_dialog.hide()
                logging.error("Algo ha fallado")
                logging.error(e)
                notificacion = notify_result.SimpleNotify(_("The rules file <b>\"%s\"</b> has errors. This quick game will be cancelled.\n\nCheck \"<i>log_gsiege</i>\" log file for details.") % equipo[0])
                notificacion.dlg_result.run()
                #progress_bar_dialog.show()

                return
            logging.info("Equipo probado")

        try:
            winner,kk = 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)
        
        # Se ha seleccionado mostrar sólo los resultados
        if self.fast_game:
            teamA = (self.es_team_a, self.team_team_a)
            teamB = (self.es_team_b, self.team_team_b)

            n = notify_result.notifyResult((teamA, teamB), winner)
            
            n.dlg_result.run()
 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 #4
0
    def play_match(self, fast=False, cant_draw=False):
        teamA_key = self.round[self.next_game][0][0]
        teamB_key = self.round[self.next_game][0][1]
        teamA = None
        teamB = None
        
        result = 0
        if (not teamA_key == 'aux_ghost_team') and (not teamB_key == 'aux_ghost_team'):
            teamA = (self.translator[teamA_key], _pieceA)
            teamB = (self.translator[teamB_key], _pieceB)
            result = guada_board.run(teamA, teamB, fast=fast,
                                     hidden=True,
                                     number_turns=self.num_turns,
                                     cant_draw=cant_draw)
            
        else:
            if teamA_key == 'aux_ghost_team':
                result = -1
            else: #teamB_key == 'aux_ghost_team':
                result = 1

        print "The result of the game '" + teamA_key + "' - '"+ teamB_key + "' was:"
        if result == 0:
            print 'Draw'
        elif result == 1:
            print teamA_key + ' won'
        elif result == -1:
            print teamB_key + ' won'

        self.round[self.next_game] = (self.round[self.next_game][0], True, result)
        
        #self.round[self.next_game][1] = True
        #self.round[self.next_game][2] = result

        self.next_game = self.next_game + 1
        self.completed = (self.next_game == self.number_games)

        return (self.round[self.next_game-1][0], self.round[self.next_game-1][2])
    def play_match(self, fast=None, cant_draw=None):
        """
        Run a simulation of the next game on the round
        """
        teams_keys = {}
        teams_keys['a'] = self.round[self.next_game][0][0]
        teams_keys['b'] = self.round[self.next_game][0][1]

        team_a = (self.translator[teams_keys['a']],)
        team_b = (self.translator[teams_keys['b']],)

        result, stats = guada_board.run(team_a, team_b, fast=True,
                                        get_stats=True,
                                        number_turns=self.num_turns,
                                        dont_log=True)

        stats_writer = csv.writer(open(self.log_file, 'a'), delimiter=',')#,
                                  #quotechar='|', quoting=csv.QUOTE_MINIMAL)
        key_result = ''
        player_stats = stats[self.player_team]
        number_of_turns = 0

        key = ''
        team = ''
        if self.player_team == 0:
            key = teams_keys['b']
            team = 'A'
            if result == 1:
                number_of_turns = player_stats['turns_winning']
                key_result = 'A'
            elif result == -1:
                number_of_turns = player_stats['turns_losing']
                key_result = 'B'
            else:
                key_result = 'D'
        else:
            key = teams_keys['a']
            team = 'B'
            if result == -1:
                number_of_turns = player_stats['turns_winning']
                key_result = 'A'
            elif result == 1:
                number_of_turns = player_stats['turns_losing']
                key_result = 'B'
            else:
                key_result = 'D'
        write_results = [key, team, key_result, number_of_turns,
                         player_stats['num_pieces'],
                         player_stats['val_pieces'],
                         player_stats['max_death']]
        print write_results

        stats_writer.writerow(write_results)
                             
        self.round[self.next_game] = (self.round[self.next_game][0],
                                      True, result)

        self.next_game = self.next_game + 1
        self.completed = (self.next_game == self.number_games)

        self._merge_stats(stats[self.player_team])

        return (self.round[self.next_game-1][0],
                self.round[self.next_game-1][2])