8-queen problem

C

cj

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
 
R

Rufus V. Smith

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

I guess it's safe to say you didn't try googling for "8 queens"

Rufus
 
K

Karl Heinz Buchegger

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.

That's not the way it works in this newsgroup.
If you have problems with your homework, do an attempt
at it until you get stuck. Then post specific questions
about the problem you encounterd with the code you already
have.
 
T

Thomas Matthews

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
 
G

Guest

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.

#include <cstdio>
int main(void) {
printf("QQ-- -- -- --\n");
printf("-- -- QQ -- \n");
printf(" -- -- -- QQ\n");
printf("-- -- --QQ-- \n");
printf(" --QQ-- -- --\n");
printf("-- -- -- QQ \n");
printf(" QQ -- -- --\n");
printf("-- QQ -- -- \n");
return 0;
}

- Dario
 
G

Guest

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.

Errare humanum est, perseverare diabolicum.
So, obviuosly, the folowing is (one of) the right answer(s):

#include <cstdio>
int main(void) {
printf("QQ-- -- -- --\n");
printf("-- -- QQ -- \n");
printf(" -- -- -- QQ\n");
printf("-- -- --QQ-- \n");
printf(" --QQ-- -- --\n");
printf("-- -- -- QQ \n");
printf(" QQ -- -- --\n");
printf("-- --QQ-- -- \n");
return 0;
}

- Dario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top