コード例 #1
0
ファイル: agent.py プロジェクト: dlemel8/ai236501
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'    
コード例 #2
0
ファイル: agent.py プロジェクト: dlemel8/ai236501
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'    
コード例 #3
0
ファイル: agent.py プロジェクト: dlemel8/ai236501
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'    
コード例 #4
0
    def move(self, game_state):
        print game_state
        inp = raw_input(
            self.player +
            ' turn. Enter <row col action> (action is N/NE/E/SE/S/SW/W/NW/SPIN): '
        )
        row, col, action = inp.split()
        row = int(row)
        col = int(col)
        action = action.upper()
        res = []
        if (action == 'SPIN'):
            res = SpinAction(row, col)
        else:
            direction_idx = DIRECTIONS.index(Direction(action, (0, 0)))
            res = MoveAction(row, col, DIRECTIONS[direction_idx])
        return res

    def setup(self, player, game_state, turn_time_limit, setup_time_limit):
        self.player = player


agents = {}
agents[WHITE] = AlphaBetaAgent()
agents[BLACK] = DummyAgent()

state = LinesOfActionState(6, 50)

winner = GameRunner(state, agents, 2, 1).run()
print 'Winner:', winner