>>176 #include <stdio.h>
int a[3][3]={{1,0,0},
{0,0,0},
{0,0,0}};
int b[3][3]={{12,20,10},
{2,-1, 0},
{2, 0, 1}};
int c[3][3]={{21,22,21},
{22,-1,20},
{12, 2,10}};
void print_moveto(int b[3][3], int x, int y)
{
printf("(%d,%d)", b[x][y] / 10, b[x][y] % 10);
}
void print_knight(void)
{
int i, j, x=3, y=3;
for (i=0; i<3; i++) {
for (j=0; j<3; j++)
if (a[i][j] == 1) {
x = i; y = j;
printf("★");
} else {
printf("□");
}
printf("\n");
}
printf("move to ");
print_moveto(b, x, y);
printf(" or ");
print_moveto(c, x, y);
printf(".\n");
}
int check(int b[3][3], int x, int y)
{
int i, j;
for (i=0; i<3; i++)
for(j=0; j<3; j++)
if (a[i][j] == 1) {
return (b[i][j] / 10 == x) && (b[i][j] % 10 == y);
}
return 0;
}
void move(int x, int y)
{
int i, j;
for (i=0; i<3; i++)
for(j=0; j<3; j++)
a[i][j] = 0;
a[x][y] = 1;
}
int moveto(void)
{
int x, y;
scanf("%d,%d", &x, &y);
if (x == -1 && y == -1)
return 0;
if (check(b, x, y)) { move(x, y); return 1;}
if (check(c, x, y)) { move(x, y); return 1;}
printf("cannot move to (%d,%d).\n", x, y);
return 1;
}
int main(void)
{
do print_knight();
while (moveto());
return 0;
}