Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

Is there a link between chronic stress and memory function?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago