Assignment 2: 8 Queens (10 points)

Write a program that uses recursion to place eight queens on a chessboard (8 x 8 board) such that no queen is "attacking" another. (Queens in chess can move vertically, horizontally, or diagonally.)

Files We Give You

You may use the makefile below to manage building this assignment:

#
# PROGRAM: 8 queens
# AUTHOR:  your name
#

CXXFLAGS+=-Wall -Werror -std=c++11

PROGS=queens

.PHONY: all clean world

all: $(PROGS)

clean:
	rm -f *.o $(PROGS)

world: clean all

Files You Must Write

You will write one file for this assignment:

Input

There is no input data for this assignment.

Output

Below are some of the exactly 92 solutions to the eight queens problem. Your program must print them all in exactly the following format (obviously the blue lines are not part of your output and are shown for reference):

z123456@turing:~/csci501/Assign2$ ./queens
solution 1
X - - - - - - -
- - - - X - - -
- - - - - - - X
- - - - - X - -
- - X - - - - -
- - - - - - X -
- X - - - - - -
- - - X - - - -
solution 2
X - - - - - - -
- - - - - X - -
- - - - - - - X
- - X - - - - -
- - - - - - X -
- - - X - - - -
- X - - - - - -
- - - - X - - -
solution 3
...
z123456@turing:~/csci501/Assign2$

where a 'X'; means a queen is on that square of the board and a '-' means the square is empty.

There must be a header for each solution counting its number starting with 1 (as shown above.)

Your output must not include any blank lines or blanks at the end of any line.

Note that it is very important that your output be formatted exactly as shown above. In grading your program, its output will be checked by another program (we wrote) that expects as input a solution in this precise format.

Note that the ORDER in which your program identifies and prints the solutions is not important. But if you follow the hints below and start on the first line and at left column (and then proceed in top-down and left-right order) when placing each queen then your first two solutions will match those shown above.

Handing In Your Assignment

To hand in your assignment you must follow the instructions in the Assignment Submission Instructions (as you did for Assignment 0.)

Hints

Last modified: 2020-09-05 08:36:48 CDT