5Queens/5Knights on 8x8 board
-
I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i
-
I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i
Hi, I did not study your code in detail, but have two remarks. your code would be (more) readable when you: - show it inside PRE tags (they preserve formatting, in particular indentation) - (if possible) put opening brackets on the right of the previous line (which most people don't do, I prefer it since it allows for more useful code lines per screen) your code would be a lot simpler if you would use a one-dimensional board[64] array (i.e. concatenating the eight rows) it would avoid a lot of for loops. For attack checking, you would have to convert the linear index into a row/col pair which is simply a divide/modulo 8 operation (two preprocessor macros can come in handy here). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne