Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Math Expert


Home >> Math

A chessboard contains 64 squares that form 8 rows and 8 columns.

The most powerful piece in the game of chess is the queen because it can attack any other piece within its row, within its

column, or along its diagonal.

The Eight Queens problem asks you to place eight queens on the chessboard so that no queen can attack any other queen.

Complete all the methods in Queens.java that have a comment saying "To be implemented for Homework 5". You must also

write a driver that uses the Queens class to place the queens on the board in a manner that no queen can attack any other queen.

Your driver must also make the call to display the chess board with your computed solution(s).

Extra Credit:

 Revise the program that you just wrote for the Eight Queens problem so that it answers the following questions:

How many backtracks occur? That is, how many times does the program remove a queen from the board?

How many calls to isUnderAttack are there?

How many recursive calls to placeQueens are there?

 You can begin the Eight Queens problem by placing a queen in the second square of the first column instead of the first square.

You can then call placeQueens to begin with the second column.

This revision should lead you to a new solution.

Write a program that finds all solutions to the Eight Queens problem.

Instead of using an 8-by-8 array to represent the board in the Eight Queens program, you can use a one-dimensional array to

represent only the squares that contain a queen.

Let col be an array of eight integers such that

col[k] = row index of the queen in column k + 1

For example, if col[2] = 3, then a queen is in the fourth row (square) of the third column that is, in board[3][2] .

Thus, you use col[k] to represent a queen.

This scheme requires that you also store information about whether each queen is subject to attack. Because only one queen

per column is permitted, you do not have to check columns. To check for a row attack, define an array rowAttack such that

rowAttack[k] is nonzero if the queen in column k + 1 can be attacked by a queen in its row.

To check for diagonal attacks, observe that diagonals have either a positive slope or a negative slope. Those with a positive

slope are parallel to the diagonal that runs from the lower left corner of the board to the upper right corner. Diagonals with a

negative slope are parallel to the diagonal that runs from the upper left corner to the lower right corner.

Convince yourself that if board[i] [j] represents a square, then i + j is constant for squares that are in a diagonal with a

positive slope, and i - j is constant for squares that are in a diagonal with a negative slope. You will find that i + j ranges from

0 to 14 and that i - j ranges from -7 to +7. Thus, define arrays posDiagonal and negDiagonal such that posDiagonal[k] is true

if the queen in column k + 1 can be attacked by a queen in its positive-sloped diagonal, and negDiagonal[k] is true if the

queen in column k + 1 can be attacked by a queen in its negative-sloped diagonal.

Math, Academics

  • Category:- Math
  • Reference No.:- M91599692
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Math

Maths assignment - 1 analysis of a data setusing a

Maths Assignment - 1. Analysis of a data set Using a continuous data set you are requested to collect in the types of data and gathering data section, perform a statistical analysis on your data. You have opportunities t ...

Assignment - provide solution to the following questionsq1

Assignment - Provide solution to the following questions: Q1. Evaluate the following: ∫xsin3x dx Q2. If , then for what value of α is A an identity matrix? Q3. The line y = mx + 1 is a tangent to the curve y 2 = 4x. Find ...

Questions -q1 prove the following identitiesa sinx y sinx

Questions - Q1. Prove the following identities a. sin(x + y) + sin(x - y) = 2 sin x cos y b. sec(x - y) = cos(x + y)/(cos 2 x - sin 2 y) c. tan 2 x - sin 2 x = (tan x sin x) 2 Q2. Solve the following equations for x ∈ [0 ...

Instructionsthe aim of the assignment is that the

Instructions The aim of the assignment is that the student/group studies and applies numerical methods such as Euler's method, the Improved Euler's method and the Runge-Kutta method to solve first-order differential equa ...

Question you will recommend a course of action regarding

Question: You will recommend a course of action regarding strategic planning in light of the issue the healthcare organization is facing. Be sure to address the following: 1. Provide a brief summary of the issue facing t ...

1 suppose that n 10088821 is a product of two distinct

1. Suppose that n = 10088821 is a product of two distinct primes, and Φ(n) = 10082272. Determine the prime factors of n. 2. It is easy to show that the converse of Fermat's Theorem does not hold; i.e., the congruence a n ...

Questions - provide solution to the following questionsq1

Questions - Provide solution to the following questions: Q1. Evaluate the following: ∫xsin3xdx Q2. If , then for what value of α is A an identity matrix? Q3. The line y = mx + 1 is a tangent to the curve y 2 = 4x. Find t ...

Assignment -question 1 let t and or 0 1 be a boolean

Assignment - Question 1. Let (T, ∧, ∨,', 0, 1) be a Boolean Algebra. Define ∗ : T × T → T and o : T × T → T as follows: x ∗ y := (x ∨ y)' x o y := (x ∧ y)' (a) Show, using the laws of Boolean Algebra, how to define x ∗ y ...

Assignment - solving the five question in the very details

Assignment - Solving the five question in the very details, thanks a lot. Question - Let a ∈ P n be a point. Show that the one-point set {a} is a projective variety, and compute explicit generators for the ideal I p ({a} ...

Question 1 what is the nth order approximation using taylor

Question: 1. What is the nth order approximation using Taylor series? 2. What is Error Propagation? 3. Please explain what the total numerical error is? Please illustrate how the change of step size will affect the total ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As