aboutsummaryrefslogtreecommitdiff
path: root/minic/test/queen.c
diff options
context:
space:
mode:
Diffstat (limited to 'minic/test/queen.c')
-rw-r--r--minic/test/queen.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/minic/test/queen.c b/minic/test/queen.c
index c998e2a..86058d2 100644
--- a/minic/test/queen.c
+++ b/minic/test/queen.c
@@ -8,18 +8,13 @@ print() {
int x;
int y;
- y = 0;
- while (y < 8) {
- x = 0;
- while (x < 8) {
+ for (y=0; y<8; y++) {
+ for (x=0; x<8; x++)
if (t[x + 8*y])
printf(" Q");
else
printf(" .");
- x++;
- }
printf("\n");
- y++;
}
printf("\n");
}
@@ -29,8 +24,7 @@ chk(int x, int y) {
int r;
r = 0;
- i = 0;
- while (i < 8) {
+ for (i=0; i<8; i++) {
r = r + t[x + 8*i];
r = r + t[i + 8*y];
if (x+i < 8 & y+i < 8)
@@ -41,11 +35,8 @@ chk(int x, int y) {
r = r + t[x-i + 8*(y+i)];
if (x-i >= 0 & y-i >= 0)
r = r + t[x-i + 8*(y-i)];
- if (r)
- return 1;
- i++;
}
- return 0;
+ return r;
}
go(int n, int x, int y) {
@@ -54,17 +45,14 @@ go(int n, int x, int y) {
N++;
return 0;
}
- while (y < 8) {
- while (x < 8) {
+ for (; y<8; y++) {
+ for (; x<8; x++)
if (chk(x, y) == 0) {
t[x + 8*y]++;
go(n+1, x, y);
t[x + 8*y]--;
}
- x++;
- }
x = 0;
- y++;
}
}