Author: Filip Tvrzsky
Date: 13:24:48 04/10/03
Go up one level in this thread
More precise and simply:
#include <stdio.h>
int v = 0, i = 0, j = 0, l = 0, a[9]; // in fact, only a[0] - a[8] is used ...
int main(void)
{
while(a[0] != 8)
{
v = a[j] - a[i];
if (j < 8)
{
if (i == 8)
{
if (l == 0)
{
putchar('\n');
if (j == 0) putchar('\n');
}
if (l == v) putchar('Q');
else putchar('#');
v = ++l;
}
else
{
if (a[i] < 8 && v != 0 && v != i - j && v != j - i) v = 1;
else v = 0;
}
}
if (v != 0)
{
l = l % 8;
if (l == 0) j++;
}
else
{
if (i == 8) a[--i]++;
else
{
if (i == j) a[++i] = 0;
else
{
a[i]++;
if (a[i] >= 8) a[--i]++;
}
}
j = 0;
}
}
}
Hmm, really tricky code, but after five hours of analysing I think it works so:
1) positions of correctly located queens are stored in the array a[8]
2) i is a counter of them and also the number of the row where the next queen
should be placed
3) j is a number of the square in this row
4) v serves for detection if the queen has been placed correctly
5) l works only during the output of the correct position.
Variable s in the original code is actually a constant (8) and k is 1 if the
correct position has been found (i == 8) and output takes place; otherwise it is
0.
Filip
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.