int knighttour(int x,int y) { int nextx,nexty,i; for(i=0;i<8;i++){ nextx=x+move[i].x; nexty=y+move[i].y; if(board[nexty][nextx]==0){ board[nexty][nextx]=++count; if(count==size*size){ printBoard(); if(found==3){ printf("%d×%d is finished\n\n",size,size); found=0; return 1; } }else{ if(knighttour(nextx,nexty)==1) return 1; } board[nexty][nextx]=0; --count; } } return 0; }
void knighttour(int x,int y,int movecount) { if(movecount>pow(n,2)) { printboard(board); } else { getnextmove(&x,&y); board[x][y]=movecount; movecount++; knighttour(x,y,movecount); } }
int main(int argc,char **argv) { if( argc!=3) { printf("Need to pass the x and y cordinate of board between 0-19\nExample:./a.out 14 11"); return 0; } int x=atoi(*(argv+1)); int y=atoi(*(argv+2)); int movecount=1; knighttour(x,y,movecount); return 0; }
int main() { int x,y,i,j; printf("盤面の大きさがxからyについて探します。(x<=y)\nxとyを入力してください。\nx,y = "); scanf("%d,%d",&x,&y); for(i=x;i<=y;i++){ size=i; count=1; openBoard(); initBoard(); board[2][2]=1; knighttour(2,2); free(board); } return 0; }