relax one assert
[qbe.git] / minic / test / knight.c
blob273e651e210bff59ea0382a011b5e42fdd528112
1 #include <stdlib.h>
2 #include <stdio.h>
4 void *calloc();
6 int N;
7 int **b;
9 board()
11 int x;
12 int y;
14 for (y=0; y<8; y++) {
15 for (x=0; x<8; x++)
16 printf(" %02d", b[x][y]);
17 printf("\n");
19 printf("\n");
20 return 0;
23 chk(int x, int y)
25 if (x < 0 || x > 7 || y < 0 || y > 7)
26 return 0;
27 return b[x][y] == 0;
30 go(int k, int x, int y)
32 int i;
33 int j;
35 b[x][y] = k;
36 if (k == 64) {
37 if (x != 2 && y != 0 && abs(x-2) + abs(y) == 3) {
38 board();
39 N++;
40 if (N == 10)
41 exit(0);
43 } else
44 for (i=-2; i<=2; i++)
45 for (j=-2; j<=2; j++)
46 if (abs(i) + abs(j) == 3 && chk(x+i, y+j))
47 go(k+1, x+i, y+j);
48 b[x][y] = 0;
49 return 0;
52 main()
54 int i;
56 b = calloc(8, sizeof (int *));
57 for (i=0; i<8; i++)
58 b[i] = calloc(8, sizeof (int));
59 go(1, 2, 0);