|
programming help
Lab #8 8
Queens
For this lab, you are to write a program that will figure out how to place 8 queens on a standard 8x8 chess
board such that no queen can capture any other and display the board to the user. Your program must
derive the answer logically, i.e. you cannot write a program with just a printf() statement. An example
output is shown:
_ _ _ _ _ _ _ _
|0|0|0|X|0|0|0|0|
|0|0|0|0|0|0|X|0|
|0|0|X|0|0|0|0|0|
|0|0|0|0|0|0|0|X|
|0|X|0|0|0|0|0|0|
|0|0|0|0|X|0|0|0|
|X|0|0|0|0|0|0|0|
|0|0|0|0|0|X|0|0|
The simplest way for your program to find a solution would be a brute force algorithm trying every single
possibility until a valid solution is found, but considering that there are 64!/(648)!
or
178,462,987,637,760 possibilities, you'll find that this takes far too long. If you have a really really fast
computer and it could test 1 billion possibilities a second, this would take nearly 124 days to compute all
possibilities, although a solution would likely be found sooner. Obviously, some method of reducing
possibilities is needed.
This lab should take more than 1 week. The appropriate amount of time will be given to any student
requiring more. It would be a good idea to run whatever solution you come up with by your TA before
proceeding to program it.
Hints: One such way to reduce possibilities is to keep in mind that upon placing the first queen on the
chess board, 15 of the squares are not possible choices for the next queen. Upon placing the second, 13
additional squares are not possible, then 11, 9, 7, 5, 3. Given an arbitrary first placement, there are 1*(6415)*(
641513)*...*(
641513119753)
or 25,401,600 possibilities. This order of magnitude is much
more manageable than 178,462,987,637,760.
Recursion could be extremely helpful in coming up with a solution to this problem.
__________________
...It's that look on thier face....when you know you are about to die...
|