class node: def __init__(self): self.i=None self.j=None self.h=None self.parent=None self.move=None class pathnode: def __init__(self): self.a=[] self.length=len(self.a) class redknight_chess: def __init__(self,n,s,e): self.start=s self.end=e self.start.h=self.heuristic(self.start) self.end.h=self.heuristic(self.end) self.n=n self.openx=[] self.openx.append(s) self.paths=[None for i in range(100)] self.closex=[] def search(self): k=0 while len(self.openx)>0: if k==5 : return x=self.openx[0] del self.openx[0] self.closex.append(x) if x.i==self.end.i and x.j==self.end.j : #print(x.i,x.j,"went once") self.printpath(x) k=k+1 adj=self.movegen(x) #print(len(adj)) adjr=self.removeseen(adj) #print(len(adjr),"adjr") self.openx=self.openx+adjr def movegen(self,e): #print(e.h,"e.h",e.move,"-----------------") m=e.i n=e.j move=[] p=m-1 q=n-2 nod=node() nod.i=p nod.j=q if p >= 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='UL' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h = 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='UR' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h = 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='R' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h = 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='LR' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h = 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='LL' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h = 0 and q >= 0 and p < self.n and q < self.n : nod.h=self.heuristic(nod) nod.parent=e nod.move='L' #print(nod.move,nod.h,"(",nod.i,",",nod.j,")") if nod.h