Help:=proc(): print(`InBoard(pt,m,n), WMove(m,n,P) `): print(`KingNeis(pt), PathRook(pt1,pt2)`): end: #InBoard(pt,m,n): InBoard:=proc(pt,m,n) local i,j: i:=pt[1]: j:=pt[2]: evalb(1<=i and i<=m and 1<=j and j<=n): end: KingNeis:=proc(pt) local i,j: option remember: i:=pt[1]: j:=pt[2]: {[i+1,j],[i-1,j],[i,j+1],[i,j-1],[i+1,j-1],[i-1,j+1], [i+1,j+1],[i-1,j-1]}: end: #Inputs a position P (a triple [WK,WR,BK]) #where WK are the coordinaes of the White King # BK are the coordinates of the Black King #WR are the coordinates of the White Rook #in an m by n chess-board [i,j], 1<=i<=m , 1<=j<=n WMove:=proc(m,n,P) local WK,BK,WR,i,j,Neis,pt,eh,ES,i1: WK:=P[1]: WR:=P[2]: BK:=P[3]: #WK=[i,j] i:=WK[1]: j:=WK[2]: Neis:={[i+1,j],[i-1,j],[i,j+1],[i,j-1],[i+1,j-1],[i-1,j+1], [i+1,j+1],[i-1,j-1]} minus KingNeis(BK): eh:={}: for pt in Neis do if InBoard(pt,m,n) and pt<>WR then eh:=eh union {[pt,WR,BK]}: fi: od: i:=WR[1]: j:=WR[2]: Neis:= {seq([i1,j],i1=1..m), seq([i,j1],j1=1..n)} minus {WR}: for pt in Neis do if InBoard(pt,m,n) and pt<>WK then eh:=eh union {[pt,WR,BK]}: fi: od: end: #PathRook(pt1,pt2): all the points visited in the #rook's move from pt1 to pt2 PathRook:=proc(pt1,pt2) local i1,j1: if pt1[1]<>pt2[1] and pt1[2]<>pt2[2] then ERROR(`Rook can't go from `, pt1, `to `, pt2, `in one move`): fi: if pt1[1]=pt2[1] then RETURN({seq([pt1[1],j1],j1=min(pt1[2],pt2[2])+1.. max(pt1[2],pt2[2])-1)}): else RETURN({seq([i1,pt1[2]],i1=min(pt1[1],pt2[1])+1.. max(pt1[1],pt2[1])-1)}): fi: end: