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


Python AI.prepare方法代码示例

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


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

示例1: MapGen

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import prepare [as 别名]

#.........这里部分代码省略.........
            
        return (row, col)

    def _place_tiles(self, deck):
        '''Place tiles on the board.'''

        for row_num, num_cols in enumerate(CatanConstants.tile_layout):
            row = []
            self._board.append(row)

            for col in range(num_cols):
                row.append(Hex(deck.pop()))
        
    def _make_deck(self):
        '''Return a shuffled deck of unplaced resources.'''

        deck = CatanConstants.get_resource_distribution_pool()
        random.shuffle(deck)
        return deck

    def draw_ascii(self):
        '''Render the board in a terminal.'''
        
        f = lambda hex: hex.get_token()
        
        for row in self._board:
            if len(row) == 3:
                print " ".join([f(c) for c in row])
            elif len(row) == 2:
                print " " + " ".join([f(c) for c in row]) + " "
            elif len(row) == 1:
                print (2 * " ") + f(row[0]) + (2 * " ")
                
    def prepare(self):
        '''Create optimized data structures for easy access to some common game data.'''
        
        # TODO
        #CatanApp.set_vertices(self._board) # this part is important
        self._create_resource_map()
        self._create_vertex_map()
        self._create_vertex_set()
        self._create_road_set()
        
        self._settlements = {}
        self._roads = set([]) 
        
        # this is the available set of nodes on which settlements can be built
        self.available_settlement_set = self._vertex_set.copy()
        
        # place the robber on the desert hex
        self._find_desert_hex()
        self._robber_hex = self._desert_pos
        #self._robber_hex = self._resource_map["desert"][0]
        
        self.ai.prepare()
        
    def _find_desert_hex(self):
        '''Find the desert hex and set self._desert_pos to its position in the form (row, col).'''
        
        for row_i, row in enumerate(self._board):
            for col, hex in enumerate(row):
                if hex.get_resource() == "desert":
                    self._desert_pos = (row_i, col)
                    return
        
    def cull_bad_settlement_vertices(self, v):
开发者ID:boompig,项目名称:pyCatan,代码行数:70,代码来源:map_gen.py


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