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


Python Level.neighbors方法代码示例

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


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

示例1: solve_monkey

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import neighbors [as 别名]
def solve_monkey(dist = False):
    path = 'screenshots/%s.png' % datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    print('Taking screenshot')
    call(['monkeyrunner', 'monkeyscreen.py', path])
    print('Rotating')
    call(['convert', '-rotate',  '90', path, path])
    
    print('Starting image solver')
    val, xmarks, ymarks = solve_image(path, dist)
    
    print('Generating solution path')
    pathparts = splitext(path)
    pathsol = '%s.sol_path.txt' % pathparts[0]
    solfile = open(pathsol, 'w')
    
    level = Level()
    level.rows = len(val)
    level.cols = len(val[0]) 
    for x, y in product(range(level.cols), range(level.rows)):
        c, t = val[y][x][0]
        if t != 0:
            continue
        #print('Tracing color', c)
        # Found a dot, start
        cx, cy, ct = x, y, 0
        while True:
            # Print current
            #print(cx, cy, ct)
            solfile.write('%d %d\n' % (avg([xmarks[cx], xmarks[cx+1]]), avg([ymarks[cy], ymarks[cy+1]])))
            # Find next
            cx2, cy2, ct2 = -1, -1, -1
            for nx, ny in level.neighbors(cx, cy):
                nc, nt = val[ny][nx][0]
                if nc >= 0 and connects(cx, cy, ct, nx, ny, nt):
                    cx2 = nx
                    cy2 = ny
                    ct2 = nt
                    break
            # Found nothing - done
            if cx2 == -1:
                break
            # Delete current and replace with next
            val[cy][cx][0] = -1, -1
            cx = cx2
            cy = cy2
            ct = ct2
        # Delete last
        val[cy][cx][0] = -1, -1
        solfile.write('0 0\n')
    solfile.close()
    
    print('Solving on device')
    call(['monkeyrunner', 'monkeypath.py', pathsol])
    
    print('DONE')
开发者ID:lacop,项目名称:FlowSolver,代码行数:57,代码来源:solve_monkey.py


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