本文整理汇总了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')