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


Python Cell.load_dir方法代码示例

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


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

示例1: __load_mapfile

# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import load_dir [as 别名]
    def __load_mapfile(self, filename):
        """ Return the height, width, and lines from the map file. 
        Also do some sanity checking on the way.
        This method is the only one concerned with the map file format.
        Each cell is stored as YZ in the map file, 
        with Y being the type of cell (- for iswalkable, E for entrance),
        and Z being the direction to go next in the path (U,D,L,R).
        """

        # open file
        filepath = os.path.join(os.pardir, 'boards', filename)
        try:
            f = open(filepath)
        except IOError:
            logging.error('Board %s not found at %s' % (filename, filepath))
        lines = f.readlines()

        # sanity checks on board width and height
        height = len(lines)
        if height == 0:
            logging.critical('Board %s has no lines.' % filename)
            exit()
        else:
            width = len(lines[0].strip().split(','))
            if width <= 1:
                logging.critical('Board %s has not enough cells.' % filename)
                exit()

        # build the cell matrix
        cellgrid = []
        entr_cell = junc_cell = wait_cell = None
        kill_cell = trap_cell = None
        load_cells_count = 0 # track how many loading cells are present
        for i in range(height):
            tmprow = []
            line = lines[i].strip().split(',')
            for j in range(len(line)):
                coords = j, i # _cellgrid[i][j] = i from top, j from left
                waypoint, path_direction = line[j][0], line[j][1]
                iswalkable = path_direction in DIR_MAP
                if waypoint == 'E':
                    cell = Cell(self, coords, path_direction, iswalkable, isentr=True)
                    entr_cell = cell
                elif waypoint == 'J':
                    cell = Cell(self, coords, path_direction, iswalkable, isjunc=True)
                    junc_cell = cell
                elif waypoint == 'W':
                    cell = Cell(self, coords, path_direction, iswalkable, iswait=True)
                    wait_cell = cell
                elif waypoint == 'K':
                    cell = Cell(self, coords, path_direction, iswalkable, iskill=True)
                    kill_cell = cell
                elif waypoint == 'T': # traps are walkable
                    cell = Cell(self, coords, path_direction, iswalkable, istrap=True)
                    trap_cell = cell
                else:
                    cell = Cell(self, coords, path_direction, iswalkable)
                # check if loading cell
                if len(line[j]) > 2:
                    load_dir = line[j][2] # direction to move fruits to when recipe match
                    load_cells_count += 1
                    cell.load_dir = load_dir
                tmprow.append(cell)

            cellgrid.append(tmprow)

        # check there's at least one of each cell
        if not entr_cell or not junc_cell or not wait_cell\
            or not kill_cell or not trap_cell:
            logging.critical('Board %s is missing some waypoints' % filename)
            exit()

        return (height, width, cellgrid,
                entr_cell, junc_cell, wait_cell, kill_cell, trap_cell,
                load_cells_count)
开发者ID:gentimouton,项目名称:smofac,代码行数:77,代码来源:board.py


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