Or you could try turtle.

下面是我在pythonturtle中实现的一个最简单的map follower。(不是迷宫跟随者,因为它不做任何回溯。)这可以让你大致了解如何使用数组来包含迷宫结构来绘制迷宫和穿过迷宫的物体:from turtle import Turtle, Screen

MAP = '''

XXXXXXXXOX

XOOOOOOOOX

XOXXXXXXXX

XOOOOXXXXX

XXXXOXXXXX

XXXXOXXXXX

XXXXOOOOOX

XXXXXXXXOX

XOOOOOOOOX

XOXXXXXXXX

'''

MAP_ARRAY = [list(row) for row in MAP.strip().split('\n')]

MAP_ARRAY.reverse() # put 0, 0 in lower left corner

ADJACENT = [

(0, 1),

(-1, 0), (1, 0),

(0, -1),

]

SCALE = 3

STAMP_SIZE = 20

WIDTH, HEIGHT = len(MAP_ARRAY[0]), len(MAP_ARRAY)

def any_adjacent(x, y):

return [(x + dx, y + dy) for dx, dy in ADJACENT if 0 <= x + dx < WIDTH and 0 <= y + dy < HEIGHT and MAP_ARRAY[y + dy][x + dx] == 'O']

def move(): # slowly navigate the MAP, quit when no where new to go

x, y = turtle.position()

adjacent_squares = any_adjacent(int(x), int(y))

# always moves to first valid adjacent square, need to consider

# how to deal with forks in the road (e.g. shuffle adjacent_squares)

for adjacent in adjacent_squares:

if adjacent not in been_there:

turtle.goto(adjacent)

been_there.append(adjacent)

screen.ontimer(move, 1000) # one second per move, adjust as needed

break

screen = Screen() # recast the screen into MAP coordinates

screen.setup(WIDTH * STAMP_SIZE * SCALE, HEIGHT * STAMP_SIZE * SCALE)

screen.setworldcoordinates(-0.5, -0.5, WIDTH - 0.5, HEIGHT - 0.5)

turtle = Turtle('square', visible=False)

turtle.shapesize(SCALE)

turtle.speed('fastest')

turtle.penup()

for y, row in enumerate(MAP_ARRAY): # draw the MAP

for x, character in enumerate(row):

if character == 'X':

turtle.goto(x, y)

turtle.stamp()

turtle.color('red')

turtle.shapesize(SCALE / 2)

turtle.goto(1, 0) # should use unique character in MAP to indicate start & end points

turtle.showturtle()

been_there = [] # prevent doubling back

move()

screen.mainloop()

python 迷宫边界_用Python绘制迷宫般的线条?相关推荐

  1. python 时间序列预测_使用Python进行动手时间序列预测

    python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...

  2. python 概率分布模型_使用python的概率模型进行公司估值

    python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...

  3. 用python实现点阵屏_用Python代码来绘制彭罗斯点阵的教程

    这里是显示彭罗斯点阵的Python的脚本.是的,这是可以运行的有效Phython代码. 译注:彭罗斯点阵,物理学术语.上世纪70年代英国数学家彭罗斯第一次提出了这个概念,称为彭罗斯点阵(Pen-ros ...

  4. python主程序流程图_用Python编程绘制流程图,你用过吗?

    您一定听说过 "Graphviz"绘图软件吧.Graphviz (Graph Visualization Software) 是一个由AT&T实验室启动的开源工具包,它采用 ...

  5. 数据结构迷宫代码_数据结构课程设计——迷宫求解(二)

    前言 接上文的介绍,本文将主要介绍如何生成随机迷宫,在网上找到的资源也比较多,这里我选取了随机 Prim 算法生成迷宫,选择这个算法的理由如下: 算法思想简单,易于实现 生成的迷宫比较自然,不会出现明 ...

  6. 使用python预测基金_使用python先知3 1创建预测

    使用python预测基金 This tutorial was created to democratize data science for business users (i.e., minimiz ...

  7. python集群_使用Python集群文档

    python集群 Natural Language Processing has made huge advancements in the last years. Currently, variou ...

  8. python 网页编程_通过Python编程检索网页

    python 网页编程 The internet and the World Wide Web (WWW), is probably the most prominent source of info ...

  9. python机器学习预测_使用Python和机器学习预测未来的股市趋势

    python机器学习预测 Note from Towards Data Science's editors: While we allow independent authors to publish ...

最新文章

  1. vi 环境,跳转函数定义
  2. jq的ajax和模块引擎
  3. Oracle感慨(转)
  4. void *变量用法
  5. 将同时共享的用户数量限制为20_共享充电宝市场需求及计划
  6. shell按照时间排序_【经典排序】希尔排序
  7. Kerberos KDC not reachable
  8. 集成学习:Boosting与Bagging
  9. php array_walk和array_map区别
  10. NERO-光盘刻录程序教程集
  11. android studio 登录与注册,Android Studio实现QQ的注册登录和好友列表跳转
  12. win10子系统安装php,win10 ubuntu 子系统安装php
  13. ASP.net和ASP的区别
  14. Flash和JS实现的图片幻灯片切换特效
  15. Android多维商品属性SKU选择
  16. 西门子 延时 光控 声控开关 5TG0 211 -1CC1 提高 灵敏度 的方法
  17. python axes_对Numpy中轴(axes)的解释(汉化版)
  18. java实现简单压缩与解压缩功能
  19. Java实现 LeetCode 113 路径总和 II
  20. GameStop的下半场:散户疯狂复仇,大空头彻底投降,但“世纪逼空大战”远未结束...

热门文章

  1. 拓扑结构计算机网络结构,计算机网络的常见的七种拓扑结构
  2. “word在试图打开文件时遇到错误”解决办法,亲测可用
  3. 头歌华氏度和摄氏度的换算
  4. python pygame 游戏实践: 俄罗斯方块(Tetris Game)第一步
  5. 亲和图信息管理联想发散思维
  6. 用山脊图展示后验分布
  7. idm老是下载到99多就停止了 idm下载中断后无法继续下载
  8. 1026. 多米诺和三格骨牌铺瓦问题
  9. 打开虚拟机时报硬盘UUID 已经存在的解决办法
  10. acl 2020 Question Answering