E
erfan
A rider who is on a horse cruse around.the array is 15*15,and he was
located in (7,7).His horse only can go in "/"or"\". eg.when he was
in (7,7),next,he may go (5,8),(5,6),(6,9),(6,5),(8,9),(8,5)
(9,8),or(9,6) . IF he has three steps,please caculate the location he
would be .
here is my programn,i imitated the 8 Quessn `s way,however,nothing
gain. I am puzzled by the Return function here and there,where should
i straighten it up $B!)(B
#define MAX 3
static int array[15][15];
static int x,y;
static int a,b;
static int x0=7;
static int y0=7;
int g,h;
/*
void showchess()
{
//printf("%d\n",array[a]);
for(int i=0;i<15;i++)
{ for(int j=0;j<15;j++)
{
printf("%3d",array[j]);
}
printf("\n");
}
}
*/
int check(int a,int b,int c) /* c is the number of step*/
{
int x,y;
for(x=a-2;x<=a+2;x++)
for(y=b-2;y<=b+2;y++)
{
if ((x-a)*(x-a)+(y-b)*(y-b)==5)
{
c=c+1;
printf(" x=%d,y=%d\n",x,y);
g=x;
h=y;
return 1;
}
}
return 0;
}
void putchess(int x0,int y0,int n)
{
int z;
array[x0][x0]=1;
if(check(x0,y0,n+1)==1)
{
if(n==MAX-1)
printf("ok");
//showchess();
else
putchess(g,h,n+1);
}
}
int main()
{
putchess(x0,y0,0);
return 1;
}
located in (7,7).His horse only can go in "/"or"\". eg.when he was
in (7,7),next,he may go (5,8),(5,6),(6,9),(6,5),(8,9),(8,5)
(9,8),or(9,6) . IF he has three steps,please caculate the location he
would be .
here is my programn,i imitated the 8 Quessn `s way,however,nothing
gain. I am puzzled by the Return function here and there,where should
i straighten it up $B!)(B
#define MAX 3
static int array[15][15];
static int x,y;
static int a,b;
static int x0=7;
static int y0=7;
int g,h;
/*
void showchess()
{
//printf("%d\n",array[a]);
for(int i=0;i<15;i++)
{ for(int j=0;j<15;j++)
{
printf("%3d",array[j]);
}
printf("\n");
}
}
*/
int check(int a,int b,int c) /* c is the number of step*/
{
int x,y;
for(x=a-2;x<=a+2;x++)
for(y=b-2;y<=b+2;y++)
{
if ((x-a)*(x-a)+(y-b)*(y-b)==5)
{
c=c+1;
printf(" x=%d,y=%d\n",x,y);
g=x;
h=y;
return 1;
}
}
return 0;
}
void putchess(int x0,int y0,int n)
{
int z;
array[x0][x0]=1;
if(check(x0,y0,n+1)==1)
{
if(n==MAX-1)
printf("ok");
//showchess();
else
putchess(g,h,n+1);
}
}
int main()
{
putchess(x0,y0,0);
return 1;
}