资源简介
A星算法的Python实现,在控制台直接执行脚本可以看到模拟图
代码片段和文件信息
#!/usr/bin/env python
import sys
CC_RED_BEGIN = ‘\033[0;31m‘
CC_GREEN_BEGIN = ‘\033[0;32m‘
CC_YELLOW_BEGIN = ‘\033[0;33m‘
CC_BLUE_BEGIN = ‘\033[0;34m‘
CC_END = ‘\033[0m‘
def createMap(width height):
ret = []
for ln in xrange(height):
ret.append([0] * width)
return ret
def printNode(node):
s = ‘%02X‘ % (node)
if node == 1:
s = CC_RED_BEGIN + s + CC_END
elif node == 2:
s = CC_GREEN_BEGIN + s + CC_END
elif node == 3:
s = CC_YELLOW_BEGIN + s + CC_END
elif node == 4:
s = CC_BLUE_BEGIN + s + CC_END
sys.stdout.write(s)
def printSpace():
sys.stdout.write(‘ ‘)
def printLf():
sys.stdout.write(‘\n‘)
def printMap(mp):
for ln in mp:
for node in ln:
printNode(node)
printSp
评论
共有 条评论