Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to solve this by brute force, this is how he wants us to code it. QueensPuzzleSolver: PuzzleTest: 2. Eight-Queens Problem 2.1. Problem Description

image text in transcribed

image text in transcribed

I'm trying to solve this by brute force, this is how he wants us to code it.

QueensPuzzleSolver:

image text in transcribed

PuzzleTest:

image text in transcribed

2. Eight-Queens Problem 2.1. Problem Description A chess board is an 8x8 matrix on which chess pieces are placed. A real chess game has a variety of pieces that have different rules defining how each can move and whom they can attack. For example, the queen can attack any other piece on the same row, column, or diagonal. Your program is to find solutions to the Eight Queens Problem. Place eight queens on a standard chess board such that no queen can attack another. There are 92 unique solutions! 2.2. Notes . . You must use the PuzzleSolve class and PuzzleTest interface to solve this problem. Your solution must be recursive. Turn in only your source file: Queens PuzzleSolver.java. It will have an inner class which defines your implementation of PuzzleTest. Make sure your class is not in a package (that is, it is in the default package). . Your output must include the names of all team members. Hint: What is your Universe? The Queen positions 1- 8. Generate all possible combinations of these positions and test each one. Each candidate represents the position of that queen on that row. Therefore, you don't have to worry about queens attacking on rows and columns, that's handled by the nature of your solution. You just need to check diagonals. Determining whether two queens can attach on the diagonal is simpler than you may think. Look at some examples by hand and see if you can determine the simple mathematical relationship 2.3. Required Main Class Queens Puzzle Solver 2.4. Required Input Not applicable 2.5. Required Output Your output should look like the following: Eight-Queens Puzzle - Team Member 1, Team Member 2, Team Member 3, Solution #1 Q Q Solution #2 Q Q ... The other 89 solutions have been left off ... Solution #92 Q Q Q Queens PuzzleSolverRedux.java X PuzzleTest.java 1 import java.util.ArrayList; 2 3 public class Queens PuzzleSolverRedux [] 4 public static void main(String[] args) { ArrayList seq = new ArrayList(); ArrayList univ = new ArrayList(); for (int i = 1; i solve(8, seq, univ, new QueenTest()); } private static class TestClass implements PuzzleTest { public boolean test(ArrayList candidate) { return false; // 9 10 11 12 13 14 x 15 16 17 18 6819 20 21 22 23 24 25 26 27 280 29 30 31 32 33 34 35 36 37 } 38 //Hint: calculate slope between each pair of queens } public void foundSolution (ArrayList soution) { //Print chessboard. } } - x Queens Puzzle SolverRedux.java PuzzleTest.java X 10 /*. 7 8 import java.util.ArrayList; 9 10 public interface PuzzleTest [ 11 public boolean test(ArrayList candidate); 12 public void foundSolution(ArrayList soution); 13 }

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

More Books

Students also viewed these Databases questions