Esempio n. 1
0
def cache_size_hit_dict_test():
    log_name = create_new_file_name('.'.join(['cache_size_hit_dict_test', str(date.today()), 'data']))
    log = open(log_name, 'w')
    d = {}
    agents = {}
    regular = LoaDEAgent()
    opt = LoaDEAgent()
    
    regular.pre_pre_pre_setup((False, False), 0)
    opt.pre_pre_pre_setup((False, True), 10000)
    state = LinesOfActionState(8, 100000)
    
    for cache_time in range(1,10,2):
        hit = 0
        miss = 0
        
        agents[WHITE] = opt
        agents[BLACK] = regular
        
        GameRunner(state, agents, cache_time, 1).run()
        hit += opt.alphaBetaAnyTime.cache_hit
        miss += opt.alphaBetaAnyTime.cache_miss
                    
        d[cache_time] = (hit, miss, hit+miss, float(hit)/(hit+miss))
        
        print '(hit, miss): ', (hit, miss, hit+miss, float(hit)/(hit+miss))

    msg('cache_size_hit_dict = ' + str(d), log)  
    print 'cache_size_hit_dict_test done! see results in log'    
Esempio n. 2
0
 def run(self):
     '''
     Runs the game. Prints actions and states.
     
     @return: The game's winner.
     '''
     for player, agent in self.agents.items():
         start = clock()
         agent.setup(player, self.initial_state, self.turn_time_limit, self.setup_time_limit)
         setup_time = clock() - start
         if setup_time > self.setup_time_limit:
             raise Exception(str(player) + ' failed to set up in time.')
     
     state = self.initial_state
     while state.getWinner() is None:
         agent = self.agents[state.getCurrentPlayer()]
         start = clock()
         action = agent.move(state)
         turn_time = clock() - start
         if turn_time > self.turn_time_limit:
             print turn_time - self.turn_time_limit
             raise Exception(str(state.getCurrentPlayer()) + ' failed to return a move in time.')
         
         successors = state.getSuccessors()
         if action not in successors.keys():
             raise Exception(str(state.getCurrentPlayer()) + ' made an illegal move.')
         
         state = successors[action]
         
         msg([action])
         msg([state])
     
     return state.getWinner()
Esempio n. 3
0
def cache_size_dict_test():
    log_name = create_new_file_name('.'.join(['cache_size_dict_test', str(date.today()), 'data']))
    log = open(log_name, 'w')
    d = {}
    agents = {}
    regular = LoaDEAgent()
    opt = LoaDEAgent()
    
    regular.pre_pre_pre_setup((False, False), 0)
    
    
    for cache_size in [10, 30, 100, 300, 1000, 3000, 10000, 30000, 100000]:
        total = 0
        opt.pre_pre_pre_setup((False, True), cache_size)
        state = LinesOfActionState(8, 100000)
        
        agents[WHITE] = opt
        agents[BLACK] = regular
        
        winner = GameRunner(state, agents, 5, 1).run()
        if winner == WHITE:
            total += 1
        
        winner = GameRunner(state, agents, 5, 1).run()
        if winner == WHITE:
            total += 1
        
        agents[BLACK] = opt
        agents[WHITE] = regular
        
        winner = GameRunner(state, agents, 5, 1).run()
        if winner == BLACK:
            total += 1
        
        winner = GameRunner(state, agents, 5, 1).run()
        if winner == BLACK:
            total += 1
            
        d[cache_size] = total
        
        print 'total: ', total

    msg('cache_size_dict = ' + str(d), log)  
    print 'cache_size_dict_test done! see results in log'    
Esempio n. 4
0
def reordering__borad_size_dict_test():
    log_name = create_new_file_name('.'.join(['reordering__borad_size_dict_test', str(date.today()), 'data']))
    log = open(log_name, 'w')
    d = {}
    agents = {}
    regular = LoaDEAgent()
    opt = LoaDEAgent()
    
    regular.pre_pre_pre_setup((False, False), 0)
    opt.pre_pre_pre_setup((True, False), 0)
    
    for board_size in range(8,12):
        total = 0
        state = LinesOfActionState(board_size, 100000)
        
        agents[WHITE] = opt
        agents[BLACK] = regular
        
        winner = GameRunner(state, agents, 3, 1).run()
        if winner == WHITE:
            total += 1
        
        winner = GameRunner(state, agents, 3, 1).run()
        if winner == WHITE:
            total += 1
        
        agents[BLACK] = opt
        agents[WHITE] = regular
        
        winner = GameRunner(state, agents, 3, 1).run()
        if winner == BLACK:
            total += 1
        
        winner = GameRunner(state, agents, 3, 1).run()
        if winner == BLACK:
            total += 1
            
        d[board_size] = total
        
        print 'total: ', total

    msg('reordering__borad_size_dict = ' + str(d), log)  
    print 'reordering__borad_size_dict_test done! see results in log'    
Esempio n. 5
0
    def run(self):
        '''
        Runs the game. Prints actions and states.
        
        @return: The game's winner.
        '''
        for player, agent in self.agents.items():
            start = clock()
            agent.setup(player, self.initial_state, self.turn_time_limit,
                        self.setup_time_limit)
            setup_time = clock() - start
            if setup_time > self.setup_time_limit:
                raise Exception(str(player) + ' failed to set up in time.')

        state = self.initial_state
        while state.getWinner() is None:
            agent = self.agents[state.getCurrentPlayer()]
            start = clock()
            action = agent.move(state)
            turn_time = clock() - start
            if turn_time > self.turn_time_limit:
                print turn_time - self.turn_time_limit
                raise Exception(
                    str(state.getCurrentPlayer()) +
                    ' failed to return a move in time.')

            successors = state.getSuccessors()
            if action not in successors.keys():
                raise Exception(
                    str(state.getCurrentPlayer()) + ' made an illegal move.')

            state = successors[action]

            msg([action])
            msg([state])

        return state.getWinner()
Esempio n. 6
0
def die(objs):
    msg(['[KOL HABASA] '] + str)
    sys.exit(0)