Question: This assignment uses Java and focus on recursion loops Included is a visual representation of the assignment A grid is presented with some squares filled

This assignment uses Java and focus on recursion loops

This assignment uses Java and focus on recursion loops Included is a

Included is a visual representation of the assignment

visual representation of the assignment A grid is presented with some squares

A grid is presented with some squares filled in black and some filled in white, and some are unfilled (gray). Fill in the gray squares as black or white so that every row and every column has the same number of black and white squares, and there are never three or more squares of the same color next to each other in a row or column. We use a 2D array of integers for our grid and represent the two different filled in colors as the two different integer values 1 and 2, and unfilled squares as 0. Please implement the following method in the Unruly class: public static boolean solve(int[][] grid) Your code can assume that the array is full of 0, 1, and 2 values and is a square of even width and height Your method should leave all the existing 1 and 2 values and try to fill in all the Os with 1 and 2 values so that every row and column has an equal number of 1 and 2 values and there is no run of three or more 1 or 2 values in a row or column. If there is such a solution, you should leave the grid filled in with a solution of all 1 and 2 values according to the rules and return the value true. If there is no solution, solve should return false. (HINT: Your code will probably restore the grid to the original state in that case.) If you wish, you may also use helper methods in your code. Make sure you follow and understand the "Recursive Backtracking General Strategy" described in class. For each recursive call, a "move" should correspond to filling in a square. Make sure that you stop yourself from making a move that would result in a rule violation. If you do this, your code should be fast enough for all the given examples. For each problem, your code will be given a time limit to prevent extremely slow solutions. (For the most complex boards, your code will have a time limit of 5 minutes on a relatively modern computer.) For this assignment, you shouldn't need to find code to search for the "best" next move to make; this is more likely to lead to bugs in your code. Keep it simple! You should probably use loops instead of making your code "purely recursive" like Recursionintro. A grid is presented with some squares filled in black and some filled in white, and some are unfilled (gray). Fill in the gray squares as black or white so that every row and every column has the same number of black and white squares, and there are never three or more squares of the same color next to each other in a row or column. We use a 2D array of integers for our grid and represent the two different filled in colors as the two different integer values 1 and 2, and unfilled squares as 0. Please implement the following method in the Unruly class: public static boolean solve(int[][] grid) Your code can assume that the array is full of 0, 1, and 2 values and is a square of even width and height Your method should leave all the existing 1 and 2 values and try to fill in all the Os with 1 and 2 values so that every row and column has an equal number of 1 and 2 values and there is no run of three or more 1 or 2 values in a row or column. If there is such a solution, you should leave the grid filled in with a solution of all 1 and 2 values according to the rules and return the value true. If there is no solution, solve should return false. (HINT: Your code will probably restore the grid to the original state in that case.) If you wish, you may also use helper methods in your code. Make sure you follow and understand the "Recursive Backtracking General Strategy" described in class. For each recursive call, a "move" should correspond to filling in a square. Make sure that you stop yourself from making a move that would result in a rule violation. If you do this, your code should be fast enough for all the given examples. For each problem, your code will be given a time limit to prevent extremely slow solutions. (For the most complex boards, your code will have a time limit of 5 minutes on a relatively modern computer.) For this assignment, you shouldn't need to find code to search for the "best" next move to make; this is more likely to lead to bugs in your code. Keep it simple! You should probably use loops instead of making your code "purely recursive" like Recursion

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!