# -*- coding: utf-8 -*-
import numpy as np
def printP():
global n
global pieces
for i in range(n):
for j in range(n):
print "%d\t"%pieces[i][j],
print ""
def init():
'''
初始化棋盘
'''
global n
global pieces
global point #用于记录剩余的点
pieces = [([0]*100)for j in range(100)]
pieces = np.array(pieces)
point = []
for i in range(n):
for j in range(n):
point.append((i,j))
def checkXY(x,y):
'''
检查点(x,y)是否在棋盘上
'''
global n
if x>=0 and x<n and y>=0 and y<n:
return True
return False
def out1(x,y):
'''
找出所有方向(包括已经被走过的点)
'''
global n
global pieces
global direction
outLine1 = []
for i in range(8):
x1 = x+direction[i][0]
y1 = y+direction[i][1]
if checkXY(x1,y1):
outLine1.append((x1,y1))
return outLine1
def out(x,y):
'''
找出所有可能
骑士巡游问题 python
最新推荐文章于 2021-03-18 07:15:53 发布
该博客介绍了一个使用Python解决骑士巡游问题的算法。通过初始化棋盘、检查坐标合法性、找出可行路径并进行剪枝操作,实现寻找棋盘上骑士能巡游的路径。代码中定义了多个辅助函数,如`checkXY`、`out1`、`play`等,最终通过递归搜索尝试找到巡游路径。如果找到路径,会打印出巡游顺序;否则,输出不存在巡游路径。

最低0.47元/天 解锁文章
446

被折叠的 条评论
为什么被折叠?



