Question
JAVA PLEASE! Create three classes: GameBoard.java, Queen.java, Play.Game.java Within Queen.java, add two private ints for row and column location. Add getters and setters for these
JAVA PLEASE!
Create three classes: GameBoard.java, Queen.java, Play.Game.java
Within Queen.java, add two private ints for row and column location. Add getters and setters for these ints. Create a constructor to initialize row and col to some value.
Within Game.Board.java, create a private char[][] to hold the board state, create a method to print the gameboard state and a method setQueen() to add queens to a given location on the board.
Within Play.Game.java, create the main method and test your current code by creating 4 queens and adding them to the board at any location and then print the board to ensure everything works thus far. TEST EDGE CASES (2 queens on the same sport, out of bound locations ext)
Within Play.Game.java, add methods getN() and getM(). These methods will handle fetching user input for the number of Queens (N) and the dimension of the board (M). Test to make sure the user cant provide bad input
Within GameBoard, add a method called validSpace() that should take a row and a column and return a Boolean value if the space is not attacked by another queen. If another queen could move to that location (given the rules of chess), then validSpace() should return false. There are several ways this method can be implemented, you can use anyway you can think of. Be sure to test this well, we want to make sure it works before introducing recursion.
We will now bring it all together by providing the recursive method in Play.Game.java that will cause the queens to be places in the right places. You want to follow the algorithm outlined in the pseudo code in the previous slide. Implement this pseudo code within the method scanBoard and call this method from main. Print the board state everytime you recurse to make sure everything
Some pseudo code to get everyone started Algorithm: solve(n, c) Input: n the number of queens to assign,c-column to start with o I/ Base case here, what should it be? o For each row r If (r, c) is a non-attacked square Place queen n on cell [r,c Found solve(n-1, c+1) . If (found) o Return true End if End if o End for o Return false Idea is to move over a column to try and place a queen every time we recurseStep 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