The first deliverable has three related components: (10 points) You must implement the Board class...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 PERANZN2222222≈≈333 * @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 <= 'e') { for (int i = 0; i < board.length; i++) { boolean temp = board [i] [m - 'a']; for (int j = m - 'a'; j > 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 <= 'E') { for (int i = 0; i < board.length; i++) { boolean temp = board [i] [board [i].length for (int j = board [i].length } - (m 'A') board [i][j] = board [i][j+ 1]; board [i] [board [i].length 1] = temp; - } else if (m >= 'v' && m <= 'z') { int col = m - 'v'; for (int i = board. length - 1; i > 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 <= 'Z') { int col board [0].length (m - 'V') for (int i = 0; i < board. length boolean temp = board [i] [col]; board [i] [col] = board [i + 1] [col]; board [i+1] [col] = temp; - 'A') - 1]; (m 1; j < board[i].length throw new IllegalArgumentException("Invalid move letter"); - 149 150 151 152 153 1; j++) { * 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 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 PERANZN2222222≈≈333 * @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 <= 'e') { for (int i = 0; i < board.length; i++) { boolean temp = board [i] [m - 'a']; for (int j = m - 'a'; j > 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 <= 'E') { for (int i = 0; i < board.length; i++) { boolean temp = board [i] [board [i].length for (int j = board [i].length } - (m 'A') board [i][j] = board [i][j+ 1]; board [i] [board [i].length 1] = temp; - } else if (m >= 'v' && m <= 'z') { int col = m - 'v'; for (int i = board. length - 1; i > 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 <= 'Z') { int col board [0].length (m - 'V') for (int i = 0; i < board. length boolean temp = board [i] [col]; board [i] [col] = board [i + 1] [col]; board [i+1] [col] = temp; - 'A') - 1]; (m 1; j < board[i].length throw new IllegalArgumentException("Invalid move letter"); - 149 150 151 152 153 1; j++) { * 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Business Communication Essentials a skill based approach
ISBN: 978-0132971324
6th edition
Authors: Courtland L. Bovee, John V. Thill
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Patients who undergo chronic hemodialysis often experience severe anxiety. Videotapes of progressive relaxation exercises were shown to one group of patients and neutral videotapes to another group....
-
American football uses a field that is 100.0 yd long, whereas a soccer field is 100.0 m long. Which field is longer, and by how much (give yards, meters, and percent)?
-
In 2024, J J Dishes changed its method of valuing inventory from the FIFO method to the LIFO method. At December 31, 2023, J Js inventories were $96 million (FIFO). J Js records were insufficient to...
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. Determine the IRR(s) for this project. b. Is this project economically attractive? EOY 0 1 2 3 4 5 6 NCF -$101 $411...
-
Smoky Mountain Corporation makes two types of hiking bootsXtreme and the Pathfinder. Data concerning these two product lines appear below: The company has a traditional costing system in which...
-
The KLM Partnership, which uses the accrual method of accounting, is owned equally by Karen ( cash method taxpayer ) , and LM corporation ( accrual method taxpayer ) . Karen is a real estate...
-
1. Which aspect of the French revolution most disturbed commentators? 2. How would you align each of these writers on a spectrum running from extreme right to extreme left in politics? 3. How would...
-
As a part of a financial institution, what is the function of an insurance company? Explain in detail how the function of the ins company compares to the function of a traditional depository...
-
How does symbolic interactionism, originating from the works of George Herbert Mead and later developed by scholars like Herbert Blumer, analyze society through the lens of subjective meanings and...
-
A parallel-plate capacitor has a capacitance of 1.8 F with air between the plates. The capacitor is connected to a 9.1-volt battery and charged. The battery is then removed. When a dielectric is...
-
What are the key features of organisational policies and procedures in reference to Financial Administration and Budgeting?
-
If 10-year interest rates are at 3%...and its volatility is at 100 bps...how many standard deviations away from a yield of 1% are you? If you increase volatility to 200 bps does it become more or...
-
2. Insert necessary equations and functions in the related cells to calculate depreciation expense for the three non-current assets in calculate depreciation expense for the three non-current assets...
-
The row echelon form of an augmented matrix of a linear system with 4 equations in the 4 [1 2 3 4 5] 0 0 1 2 0 0 0 0 0 0 Lo o o 0 unknowns is The free variables of the system are
-
What are conversion costs? What are prime costs?
-
Health care costs are a pressing concern at every level in the economy, from individual households up through companies of all sizes on up to state and federal governments. Many companies that want...
-
To review chapter content related to each set of exercises, refer to the indicated Learning Objective. Revising Messages: Clarity Break the following sentences into shorter ones; revise as necessary...
-
XtremityPlus is known for its outlandish extremesports products, and the Looney Launch is no exception. Fulfilling the dream of every childhood daredevil, the Looney Launch is an aluminum and...
-
In the January 1, 20X8, consolidated balance sheet, the amount of goodwill reported should be a. $0. b. $76,000. c. $95,000. d. $156,000. On January 1, 20X8, Ritt Corporation acquired 80 percent of...
-
In the December 31, 20X8, consolidated balance sheet, the amount of noncontrolling interest reported should be a. $200,000. b. $239,000. c. $251,000. d. $252,000. On January 1, 20X8, Ritt Corporation...
-
On January 1, 20X5, Post Company acquired an 80 percent investment in Stake Company. The acquisition cost was equal to Posts equity in Stakes net assets at that date. On January 1, 20X5, Post and...
Study smarter with the SolutionInn App