Eight Queens Problem ( Due 08 Mar 2013 )

The Eight Queens Problem is a fairly old problem that has been well discussed and researched. The first published reference to this problem was in a German Chess magazine in 1848 by Max Bezzel. In 1850, Franz Nauck published all 92 solutions of the problem for an 8x8 board. S. Gunther in 1874 suggested a method for finding solutions by using determinants and J.W.L. Glaisher extended this method. E. Dijkstra published a detailed description of the solution of the problem as a depth-first backtracking algorithm.

The original statement of the problem ran as follows - how can we place eight queens on a regular chess board such that no queen can capture another. It turns out there is no unique solution but 92 possible solutions of which only 12 are distinct. The 12 distinct solutions can generate all other solutions through reflections and / or rotations. Here is a table that gives the size of the board, all possible solutions, and all distinct solutions.

Size All Solutions Distinct Solutions
1 1 1
2 0 0
3 0 0
4 2 1
5 10 2
6 4 1
7 40 6
8 92 12

This is a classic back-tracking problem and we have discussed the solution and code in class. The solution that we worked on prints only one possible solution to the problem. There are several variations to this problem and their solution. You choose one of the variations of the problem to work on.

Variation 1: Prompt the user to enter the size of the board. The size of the board must be a number between 1 and 8 inclusive. Keep prompting the user to enter a number in that range, if he does not get it right. For the size of the board that the user specified generate and print all possible solutions for that size. Keep a count of the number of solutions and your last line should print the total number. Here is a possible scenario:

Enter the size of board: 4

x Q x x
x x x Q
Q x x x
x x Q x

x x Q x
Q x x x
x x x Q
x Q x x

There are 2 solutions for a 4 x 4 board.

Variation 2: Prompt the user to enter the size of the board. The size of the board must be a number between 1 and 8 inclusive. Keep prompting the user to enter a number in that range, if he does not get it right. For the size of the board that the user specified obtain the minimum number of queens that can control all the squares in the board and not capture each other. Print just one solution of the problem. Here is a possible scenario:

Enter the size of the board: 8

Minimum number of queens to control all squares is 5

x x x x x x Q x
x x Q x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x Q
x x x Q x x x x
x x x x x x x x
Q x x x x x x x

You will do just one variation of the problem. The file that you will be turning in will be called EightQueens.py. The file will have a header of the following form:

#  File: EightQueens.py

#  Description:

#  Student's Name:

#  Student's UT EID:
 
#  Course Name: CS 313E 

#  Unique Number: 53260

#  Date Created:

#  Date Last Modified:

Use the turnin program to submit your EightQueens.py file. The proctor should receive your work by 11 PM on Friday, 08 March 2013. We will be looking for clean logic and good documentation. There will be substantial penalties if you do not adhere to the guidelines.

References

  1. Eight Queens Problem Article in Wolfram MathWorld.
  2. Article on Eight Queens Problem in Wikipedia Watch the animation of the recursive solution.