"""
Created on Wed Oct 23 23:01:04 2019
@author: longhuan
"""
import numpy as np
class Node():
def __init__(self,x,y,step):
self.step=step
self.l=x
self.r=y
def Bool(x,y):
return (x>=0 and x<10 and y>=0 and y<9)
def bfs(x,y,X,Y):
axis=[[1,2],[1,-2],[2,1],[2,-1],[-1,2],[-1,-2],[-2,1],[-2,-1]]
vis=np.ones((10,9))*0
node=Node(x,y,0)
vis[x][y]=1
q=[node]
while q:
node=q.pop(0)
if node.l==X and node.r==Y:
print(node.step)
return
for i in range(8):
x=node.l+axis[i][0]
y=node.r+axis[i][1]
if Bool(x,y) and vis[x][y]==0:
vis[x][y]=1
q.append(Node(x,y,node.step+1))
print(node.step)
print(node.step)
bfs(0,0,0,1)