Question: The first deliverable has three related components: (10 points) You must implement the Board class given to you in the zip file for the

The first deliverable has three related components: (10 points) You must implementthe Board class given to you in the zip file for theproject. It must behave as described in the Javadoc comments included inthe skeleton file you received. Make sure to read through those commentsso that you know what is required. Your Board class will betested using the P1Test.java file that was also included in the zipfile for the project. Like the homework, each test has a numberin its name indicating how much each test is worth. The testpoints add up to a total of 10 points. (10 points) Youmust implement the Game class given to you in the zip file

The first deliverable has three related components: (10 points) You must implement the Board class given to you in the zip file for the project. It must behave as described in the Javadoc comments included in the skeleton file you received. Make sure to read through those comments so that you know what is required. Your Board class will be tested using the P1Test.java file that was also included in the zip file for the project. Like the homework, each test has a number in its name indicating how much each test is worth. The test points add up to a total of 10 points. (10 points) You must implement the Game class given to you in the zip file for the project. The only required method is main. When the Game class is executed, the user should be able to play one game of the puzzle. 1. The game begins by prompting the user for a difficulty level between 1 and 10. The application should then generate a random board by starting from a solved puzzle and then making that many random moves. (Note that this is one of the constructors you are required to implement in the board class). It is possible that after making random moves, the board is actually in the solved configuration. You must continue regenerating the board by making the requested random moves until the board you end up with is not solved. 2. After displaying the board on the screen, the game proceeds by repeatedly prompting the player for a move and displaying the updated board on the screen. Each of these prompts and responses is called a round. 3. The rounds continue until either the player wins the game by reaching the solved board configuration (all the Xs are on the outer edges of the board) and the game displaying a message indicating the player has won or the player loses by reaching a repeated board configuration and the game displaying a message indicating that the player has lost. Again, a demonstration of the expected behavior will be provided in class, so make sure to watch it to see what is required. Your grade will be based on how closely your game resembles the one in the demonstration, so once you get your game working, spend some extra time trying to get your output to look as much as possible like the output from the demonstration. You must make use of the Board class in your application. Command Prompt - java -cp algs4.jar;bin p1.Game V W X Y Z +-+-+-+-+-+ a|*| |*|*|*|A +-+-+-+-+ b|| || ||B c|*| | | |*|C +-+-+-+-+-+ d|*|*| | |*|D +-+-+-+-+-+ e|*|*|*|*|*|E +-+-+-+ v w x y z Enter a letter for your move: 2 package p1; 6 public class Game { 70 8 9 public static void main(String[] args) { } 18 19 20 1234567ERDENENAN2 10 11 The Game/Puzzle The game/puzzle consists of a 5 by 5 grid of cells. Each cell could be empty or could contain an 'X'. The object of the game/puzzle is to arrange the X's around the outer edges of the grid (the 16 cells that make up the bottom and top row and the leftmost and rightmost columns). You can shift the cells around by shifting an entire row left or right or by shifting an entire column up or down. Cells that shift off the end wrap around to the other end. Below are the full details about the 20 moves available to a player: a-e: Shift an entire row to the left ('a' shifts the topmost row and e the bottommost row). A-E: Shift an entire row to the right ('A' shifts the topmost row and E the bottommost row). v-z: Shift an entire column down ('v' shifts the leftmost column and z the rightmost column). V-Z: Shift an entire column up ('v' shifts the leftmost column and z the rightmost column). The player continues to make moves until either they win by arranging the X's around the edges of the grid or they lose by repeating a board position. This is probably easier to understand via a demonstration. A demonstration of how the game is played will be given in class, so please make sure to take a look at the lecture recording if you did not attend the class meeting where the demonstration was given. 1 package p1; 30 import java.util.Arrays; 4 import java.util.Random; 6 public class Board { 1234567896123 private boolean ( ) ( ) board; * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. That some of the possible moves don't actually change what the board looks like. 100 /** 11 12 13 14 * 170 PERANZN2222222333 * @param moves the number of moves to make when generating the board. */ public Board(int moves) { board = new boolean [5] [5]; // Initialize the board as a 5x5 array // Start with a solved board for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { board [i][j] = (i == 0 || i == 4 || j 0 || j == 4); } } // Make random moves Random random = new Random(); for (int i = 0; i < moves%;B i++) { int moveIndex = random.nextInt(5); char move = (char) ('a' + moveIndex); move (move); } * Checks if the board is solved. * @return {@code true} if the board is solved and {@code false} otherwise. * A board is solved if the 16 s occupy the outermost cells in the grid (top * and bottom rows and leftmost and rightmost columns). */ public boolean is Solved () { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { boolean isEdgeCell = (i == 0 || i == 4 || j == 0 || j == 4); if (isEdgeCell && !board [i][j]) { return false; } else if (!is EdgeCell && board [i] [j]) { return false; 41 42 43 440 45 /** 46 47 48 49 500 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 } return true; * Construct a puzzle board using a 2D array of booleans to indicate which cells are filled and which are empty. * @param b a 5x5 boolean array where true cells indicate that the corresponding position in the puzzle board starts filled and false indicates the position starts cleared. The board must have exactly 16 filled positions and 9 unfilled positions. public Board (boolean [ ] [ ] b) { if (b.length != 5 || b[0].length != 5) { throw new IllegalArgumentException("Invalid board size"); int filledCount = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (b[i][j]) { filledCount++; 76 77 780 /** 79 80 81 * 82 83 84 85 86 */ 870 88 89 } 90 91 92 93 94 } 95 96 97 98 99 100 } 101 } 102 103 if (filledCount != 16 || (25 - filledCount) != 9) { throw new IllegalArgumentException("Invalid board configuration"); } board = new boolean [5] [5]; for (int i = 0; i < 5; i++) { board [i] = Arrays.copyOf(b[i], 5); 106 1070 108 /** 109 110 111 * Makes a move on the board the board. Moves 'a' through 'e' shift the given row * to the left while moves 'A' through 'E' shift the given row to the right. * Moves 'v' through 'z' shift the given column down while moves 'V' through 'Z' *shift the given column up. 112 113 * @param m the move to make. 114 115 1160 117 118 119 120 * @throws IllegalArgumentException if the argument is not a valid move letter. */ public void move(char m) { if (m = 'a' && m 0; j--) { 121 122 123 board [i][j] = board [i][j } board [i][0] = temp; 1]; 124 125 126 127 128 129 130 131 132 } 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 } else { 148 } } else if (m >= 'A' && m = 'v' && m 0; i--) { } boolean temp = board [i] [col]; board [i] [col] = board [i - 1] [col]; board [i1] [col] = temp; - 1; 1; i++) { } else if (m >= 'V' && m * Returns {@code true} if a given cell of the board is filled and {@code false} * otherwise. The top row (corresponding to 'a' moves) is row 0. The leftmost * column (corresponding to 'v' moves) is column 0. 157 1580 /** 159 160 161 162 * 163 164 * @param col the column of the cell being querried 165 166 1670 * @param row the row of the cell being querried * @return {@code true} if the cell is filled and {@code false} otherwise. */ public boolean is Filled (int row, int col) { 168 169 170 return board [row][col] == true; 171 } 172} 173

Step by Step Solution

3.39 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It appears youve provided a Java class called Board with incomplete methods and some errors in the code Ill correct the code and provide explanations for the changes made java package p1 import javaut... View full answer

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 Programming Questions!