Implement the Solver class. In doing so, you are allowed to define other classes to help you (as well as use “built-in” Java classes or the book’s classes). The point of the solver class is the solve method which takes a board/puzzle configuration represented as a 2D array of booleans and returns a char array containing a minimal sequence of moves that will lead to the solved board (all the cells around the edges being filled). The board configuration is passed in as a 5-by-5 boolean array of Booleans with exactly 16 true cells (filled) and 9 false cells (empty). The solve method then returns an array of characters representing a minimal sequence of moves that solves the puzzle. In other words, if the characters from the returned array are used in order as input to the move method on the Board object representing the initial configuration, the resulting board configuration represents the solved board. Furthermore, the solution must be minimal in the sense that there are no solutions that use fewer moves (although there could be other solutions that use the same number of moves). If the input to the solve method is a board configuration that is already solved, then solution requires no moves and an array of size 0 must be returned. The class also has a no argument constructor that will be called to construct/initialize the solver object. (There are perfectly valid solutions to the project where the constructor does absolutely nothing, but there are also solutions where some preprocessing work done in the constructor allows the solve method to be much faster.) /** * Solves a given puzzle represented as a 5-by-5 boolean array with * 16 trues and 9 falses. * @param start the intial puzzle/board configuration * @return the sequence of moves that solves the puzzle. */ public char[] solve(boolean[][] onset) {      // TODO      throw new RuntimeException("Not implemented"); }     // A simple toy exmaple of how a Solver object is used. public static void main(String[] args) {      boolean[][] bb = {           { true,  true,  true,  true,  true},           {false,  true,  true, false, false},           { true, false, false, false,  true},           { true, false, false, false,  true},           { true,  true,  true,  true,  true}      };        boolean[][] Xbb = {           { true,  true,  true,  true,  true},           {false,  true,  true, false, false},           { true, false,  true, false,  true},           { true, false, false, false,  true},           { true,  true, false,  true,  true}      };        Solver solver = new Solver();      char[] sol = solver.solve(bb);      System.out.println(Arrays.toString(sol));      sol = solver.solve(Xbb);      System.out.println(Arrays.toString(sol)); }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement the Solver class. In doing so, you are allowed to define other classes to help you (as well as use “built-in” Java classes or the book’s classes). The point of the solver class is the solve method which takes a board/puzzle configuration represented as a 2D array of booleans and returns a char array containing a minimal sequence of moves that will lead to the solved board (all the cells around the edges being filled). The board configuration is passed in as a 5-by-5 boolean array of Booleans with exactly 16 true cells (filled) and 9 false cells (empty). The solve method then returns an array of characters representing a minimal sequence of moves that solves the puzzle. In other words, if the characters from the returned array are used in order as input to the move method on the Board object representing the initial configuration, the resulting board configuration represents the solved board. Furthermore, the solution must be minimal in the sense that there are no solutions that use fewer moves (although there could be other solutions that use the same number of moves). If the input to the solve method is a board configuration that is already solved, then solution requires no moves and an array of size 0 must be returned. The class also has a no argument constructor that will be called to construct/initialize the solver object. (There are perfectly valid solutions to the project where the constructor does absolutely nothing, but there are also solutions where some preprocessing work done in the constructor allows the solve method to be much faster.)

/**
* Solves a given puzzle represented as a 5-by-5 boolean array with
* 16 trues and 9 falses.
* @param start the intial puzzle/board configuration
* @return the sequence of moves that solves the puzzle.
*/
public char[] solve(boolean[][] onset) {
     // TODO
     throw new RuntimeException("Not implemented");
}
 
 
// A simple toy exmaple of how a Solver object is used.
public static void main(String[] args) {
     boolean[][] bb = {
          { true,  true,  true,  true,  true},
          {false,  true,  true, false, false},
          { true, false, false, false,  true},
          { true, false, false, false,  true},
          { true,  true,  true,  true,  true}
     };
 
     boolean[][] Xbb = {
          { true,  true,  true,  true,  true},
          {false,  true,  true, false, false},
          { true, false,  true, false,  true},
          { true, false, false, false,  true},
          { true,  true, false,  true,  true}
     };
 
     Solver solver = new Solver();
     char[] sol = solver.solve(bb);
     System.out.println(Arrays.toString(sol));
     sol = solver.solve(Xbb);
     System.out.println(Arrays.toString(sol));
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education