当前位置: 首页>>代码示例>>Python>>正文


Python Game.initialize_board方法代码示例

本文整理汇总了Python中Game.Game.initialize_board方法的典型用法代码示例。如果您正苦于以下问题:Python Game.initialize_board方法的具体用法?Python Game.initialize_board怎么用?Python Game.initialize_board使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game.Game的用法示例。


在下文中一共展示了Game.initialize_board方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parent_selection

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import initialize_board [as 别名]
 def parent_selection(self):
     # only 'most fit' players are selected for reproduction
     parents = []
     pop_range = range(POP_SIZE)
     tourn_range = range(TOURN_SIZE)
     
     # selecting next population
     while(len(parents) < POP_SIZE):
         
         # take random sample of players for tournament
         competitors = random.sample(self.population, TOURN_SIZE) 
                            
         win_counts =  np.array([0]*TOURN_SIZE)  # list of all 0s
         
         # have each player play other players once
         for p1 in tourn_range:
             for p2 in tourn_range:
                 
                 player1 = competitors[p1]
                 player2 = competitors[p2]
                                         
                 # verify AI doesn't play itself
                 if player1 != player2:
                     # player j plays player k
                     g = Game(player1, player2, BOARD_SIZE)
                     g.initialize_board()
                     
                     if DEBUG:
                         print 'Player 1 weights: ', player1.heuristic.weights
                         print 'Player 2 weights: ', player2.heuristic.weights
                     winner = g.play()
                     
                     # only increment counts if true winner (no draws)
                     if player1 == winner:
                         win_counts[p1] += 1
                     elif player2 == winner:
                         win_counts[p2] += 1
         
         # find all 'best players'
         best_player_indices = np.where(win_counts == (max(win_counts)))[0]
     
         # if more than one 'best player' is found, choose randomly
         best_player = competitors[random.choice(best_player_indices)]
         parents.append(best_player)
     
     return parents
开发者ID:akhilkapoor,项目名称:AI_EVO,代码行数:48,代码来源:Evolution.py

示例2: play_old_vs_new

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import initialize_board [as 别名]
    def play_old_vs_new(self,tronEvo):

        # redefine some globals
        globals()['BOARD_SIZE'] = 60
        globals()['DISPLAY'] = True
            
        player1 = random.choice(tronEvo.last_pop)
        player2 = random.choice(tronEvo.last_pop)
        
        print 'Player 1 weights:', player1.heuristic.weights
        print 'Player 2 weights:', player2.heuristic.weights

        g = Game(player1, player2, BOARD_SIZE)
        g.display = DISPLAY
        g.initialize_board()
        
        g.play(True)
        raw_input('Hit enter to exit..')
开发者ID:akhilkapoor,项目名称:AI_EVO,代码行数:20,代码来源:Main.py

示例3: test_game

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import initialize_board [as 别名]
 def test_game(self):
     p1 = Player()
     p1.name = 'p1'
     p1.pos = [BOARD_SIZE/2,BOARD_SIZE/4]
     p1.heuristic = Heuristic()
     p1.heuristic.weights.append(1000)
     p1.heuristic.weights.append(20)
     p1.heuristic.weights.append(20)
     
     p2 = Player()
     p2.name = 'p2'
     p2.pos = [BOARD_SIZE/2,3*BOARD_SIZE/4]
     p2.heuristic = Heuristic()
     p2.heuristic.weights.append(-20)
     p2.heuristic.weights.append(20)
     p2.heuristic.weights.append(20)
     g = Game(p1, p2, BOARD_SIZE)
     g.display = True
     g.initialize_board()
     
     #g.describe_board(g.board)
     
     g.play()
开发者ID:akhilkapoor,项目名称:AI_EVO,代码行数:25,代码来源:Main.py


注:本文中的Game.Game.initialize_board方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。