Question
A classic computer science puzzle is the eight queens puzzle. It is the problem of placing eight chess queens on an 8*8 chessboard so that
A classic computer science puzzle is the eight queens puzzle. It is the problem of placing eight chess queens on an 8*8 chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column or diagonal. The eight queens puzzle is an example of the more general n-queens problem of placing n queens on an n*n chessboard, where solutions exist for all natural numbers n with the exception of n = 2 and n = 3.
Your problem will be solve to a related problem, the n-knights puzzle. It is the problem of placing 2*n knights on an n*n chessboard, where no knight can capture any other knight.
Design a program that can determine how many solutions the n-knights puzzle has for any number n. To accomplish this, you may choose any algorithm you want including trying every possible combination. However, you must use a data structure that contains within it many objects of a class that describe the solutions. You can choose to create the data structure or use a pre-existing one, but you must create a custom class to describe a solution.
The user should be prompted to enter a number to use for n, If they enter invalid data, they should see an error and retry input. Upon enter a valid data, you should start processing. Periodically, you should output what percent complete you are, showing at least an output every 10% of completion.
Once the processing is complete, you should tell the user the number of solutions you have found. The user should be able to enter Q to quit or the number of a solution. If the solution number does not exists, show an error and allow the user to enter a new input. If the solution exists, show it in ASCII art, pretending the screen is infinitely tall and wide. Do not worry if the real screen wraps the output. Then prompt the user again, repeating until they finally quit.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started