if(a-2>=0&&b-1>=0&&board[a-2][b-1]==0) count++;
if(a-2>=0&&b+1<M&&board[a-2][b+1]==0) count++;
if(a+2<M&&b-1>=0&&board[a+2][b-1]==0) count++;
if(a+2<M&&b+1<M&&board[a+2][b+1]==0) count++;
if(a-1>=0&&b+2<M&&board[a-1][b+2]==0) count++;
if(a-1>=0&&b-2>=0&&board[a-1][b-2]==0) count++;
if(a+1<M&&b+2<M&&board[a+1][b+2]==0) count++;
if(a+1<M&&b-2>=0&&board[a+1][b-2]==0) count++; return count ; }
//寻找路径函数
void findway(int m,int n) {
dir f[8],path ; int i,j,k, stepnum ; stepnum=1 ; i=m ; j=n ;
printf("output the position and the number of the position:\n"); while(stepnum<M*M && i>=0 && j>=0) {
board[i][j]=stepnum; printf("%d,%d,%d ",i,j,board[i][j]);
path.pathnum=8 ; //用来标志可走方向数的最小值 for(k=0;k<8;k++) //对方向数组赋初值 {
f[k].r=-1 ; f[k].c=-1 ; }
//如果第一个方向可走,则将坐标及可选方向数赋给f[0],以下同理 if(i-2>=0&&j-1>=0) {
f[0].r=i-2 ; f[0].c=j-1 ;
f[0].pathnum=pathnum(f[0].r,f[0].c); }