cj said:
Hello, I am also looking for information how to write code which finds
solutions to 8-queen problem (position 8 queens on a chess board, or N
queens on a N*N board, so that they do not hit each other). Any input would
be highly appreciated.
Thanks,
C++J
What kind of information, besides writing the program for you?
A queen can attack in all directions for the length of the board.
One presumes immediately that only one queen can exist per row.
Place the queen on a square in row one.
Place a queen on the second row so that it is in a safe spot.
Place the 3rd queen on the 3rd row so that it is in a safe spot.
And so on.
Place the 8th queen on the 8th row so that it is in a safe spot.
If all 8 queens can be placed, print the board configuration
or minimally, the location of each queen.
Move the 8th queen to a new spot if possible. If possible,
print the configuration and try for another one.
Otherwise, move the 7th queen to a new position on the 7th
row and reposition the 8th queen. Repeat until the first
queen has tried all her positions.
Next time, for help with the algorithm or "how to do it",
try Otherwise, post the code that
you are having problems with.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book