如何解决在我的 Knight's Move Python 程序中查找错误
代码
我正在尝试构建一个骑士移动程序,一切正常,但此代码中有一个我找不到的隐藏错误。有人能发现问题吗?
from itertools import product
def solution(src,dest):
A = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19,20,21,22,23],[24,25,26,27,28,29,30,31],[32,33,34,35,36,37,38,39],[40,41,42,43,44,45,46,47],[48,49,50,51,52,53,54,55],[56,57,58,59,60,61,62,63]]
if (src not in range(0,64) or dest not in range(0,64)) :
raise Exception('out of range')
step = 1
r_s = 0
r_e = 7
str_r = 0
str_c = 0
while src:
if r_s <= src <= r_e:
for i in range(0,8):
if A[str_r][i] == src:
str_c = i
break
break
str_r += 1
r_s += 8
r_e += 8
moves = list(product([str_r - 1,str_r + 1],[str_c - 2,str_c + 2])) + list(product([str_r - 2,str_r + 2],[str_c - 1,str_c + 1]))
m_s = [(x,y) for x,y in moves if x >= 0 and y >= 0 and x < 8 and y < 8]
for i,j in m_s:
if A[i][j] == dest:
move_counter = step
return move_counter
while True:
step += 1
List_steps = []
for i,j in m_s:
r_s = 0
r_e = 7
str_r = 0
str_c = 0
while True:
if r_s <= A[i][j] <= r_e:
for x in range(0,8):
if A[str_r][x] == A[i][j]:
str_c = x
break
break
str_r += 1
r_s += 8
r_e += 8
moves = list(product([str_r - 1,str_c + 1]))
m_z = [(x,y in moves if x >= 0 and y >= 0 and x < 8 and y < 8]
for m,n in m_z:
if A[m][n] == dest:
return step
move_counter = 'Not Found'
List_steps += m_z
if move_counter == 'Not Found':
m_s = list(set(List_steps))
continue
if __name__ == '__main__':
A = int(input())
B = int(input())
print(solution(A,B))
错误位置
moves = list(product([str_r - 1,str_c + 1]))
m_z = [(x,y in moves if x >= 0 and y >= 0 and x < 8 and y < 8]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。