I'm working on a unique Eight Queens (N Queens, but always 8) problem that, instead of printing out the chessboard, prints "Yes" if there is exactly one queen in each row and one in each column, and "No" otherwise. I don't quite understand how to do the check for one queen in each row and one in each column, and I need some help figuring it out. The Eight Queens code this is based on is below:
I don't want to use recursion or multiple functions (if possible)
Why not?
I don't want to use any header files I haven't already included
Again, why not?
... "Yes" if there is exactly one queen in each row and one in each column, ...
It's the eight queens problem, not the eight rooks. You have to test for diagonal as well.
EDIT: I should add more to my post. I am wondering why it is that you want to avoid the specific approaches to solving this problem. Keep in mind "Because I didn't learn that yet\No one taught me that yet" is not a valid excuse as this site is here to teach.
EDIT 2: int board[8]; This would make for a funny looking board. Chess boards are 8x8 for a total 64 squares. You need a two dimensional array for this problem.
- First things first, you need a two dimensional array for this. There is no getting around that.
- Next, I suggest making a struct that holds an X and a Y Coord to represent each queen. Once you have this struct then testing if any two share the same row or column is as simple as testing if any share the same value for X or Y.
- Testing diagonal is going to be a bit harder, if you can get the above stuff done and post some code then we can tackle this one next.
bool arr[4][4];
initilize all 16 bool to 0.
1. let the user input two coordinate.
2. check Rookwise. (if two Rooks can capture each other)
3. check Bishopwise. (if two Bishops can capture each other)
4. a) if any capture is possible, goto step1.
b) else if no capture is possible, say the user that he succeeded.
bool arr[4][4];
initilize all 16 bool to 0.
1. let the user input two coordinate.
2. check Rookwise. (if two Rooks can capture each other)
3. check Bishopwise. (if two Bishops can capture each other)
4. a) if any capture is possible, goto step1.
b) else if no capture is possible, say the user that he succeeded.
oh my god, if you don't understand this.... actual program is 10x hard.
search Google for C++ solution code. try to understand them, then program your own version.