Lab 13: Eight Queens
- The task today is to search for a way to place eight queens
on a chess board so that none can take each other.
- Open a project and make a hello world.
- You can do the rest of this lab one of two ways, start with the four
queens problem, or start with the eight queens problem.
The directions here will go from the four.
- Make an 4x4 array of booleans, all initially set to false.
- Make a function to see if a queen can take another queen;
the inputs to the function are the x and y coordinates of the
two queens. (They can take each other if they're on the
same row, the same column, or diagonal (either way) to each
- Now, place the first queen (the one in the 0 column) in the first
(0) row. Then search for the place the second queen can go.
- Add a loop for the third queen.
- Add a loop for the first, and fourth queen. This should be
four nested loops.
- You should be able to print out all of the ways the four queens
can be set.
- Now, make the board 8x8.
- Now add the four other nested loops.
- If you get this done, try the whole task again using the constraint
satisfaction algebra. Indeed, if you're bold, you can start with