Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need assistance with this method. Don't change the method type, decoding UTF8 import java.util.Scanner; /** * Determines if a sequence of cells of length

I need assistance with this method. Don't change the method type, decoding UTF8

import java.util.Scanner;

 /** * Determines if a sequence of cells of length len in a game board is clear or not. This is used * to determine if a ship will fit on a given game board. The x and y coordinates passed in as * parameters represent the top-left cell of the ship when considering the grid. * * @param board The game board to search. * @param xcoord The x-coordinate of the top-left cell of the ship. * @param ycoord The y-coordinate of the top-left cell of the ship. * @param len The length of the ship. * @param dir true if the ship will be vertical, otherwise horizontal * @return 1 if the cells to be occupied by the ship are all Config.WATER_CHAR, * -1 if the cells to be occupied are not Config.WATER_CHAR, and * -2 if the ship would go out-of-bounds of the board. */ public static int checkWater(char board[][], int xcoord, int ycoord, int len, boolean dir) { //FIXME return 0; } /** * Checks the cells of the game board to determine if all the ships have been sunk. * * @param board The game board to check. * @return true if all the ships have been sunk, false otherwise. */ public static boolean checkLost(char board[][]) { //FIXME return false; } /** * Places a ship into a game board. The coordinate passed in the parameters xcoord and ycoord * represent the top-left coordinate of the ship. The ship is represented on the game board by * the Character representation of the ship id. (For this method, you can assume that the id * parameter will only be values 1 through 9.) * * @param board The game board to search. * @param xcoord The x-coordinate of the top-left cell of the ship. * @param ycoord The y-coordinate of the top-left cell of the ship. * @param len The length of the ship. * @param dir true if the ship will be vertical, otherwise horizontal. * @param id The ship id, assumed to be 1 to 9. * @return false if the ship goes out-of-bounds of the board, true otherwise. */ public static boolean placeShip(char board[][], int xcoord, int ycoord, int len, boolean dir, int id) { //FIXME return false; } /** * Randomly attempts to place a ship into a game board. The random process is as follows: * 1 - Pick a random boolean, using rand. True represents vertical, false horizontal. * 2 - Pick a random integer, using rand, for the x-coordinate of the top-left cell of the * ship. The number of integers to choose from should be calculated based on the width of * the board and length of the ship such that the placement of the ship won't be * out-of-bounds. * 3 - Pick a random integer, using rand, for the y-coordinate of the top-left cell of the * ship. The number of integers to choose from should be calculated based on the height of * the board and length of the ship such that the placement of the ship won't be * out-of-bounds. * 4 - Verify that this random location can fit the ship without intersecting another ship * (checkWater method). If so, place the ship with the placeShip method. * * It is possible for the configuration of a board to be such that a ship of a given length may * not fit. So, the random process will be attempted at most Config.RAND_SHIP_TRIES times. * * @param board The game board to search. * @param len The length of the ship. * @param id The ship id, assumed to be 1 to 9.. * @param rand The Random object. * @return true if the ship is placed successfully, false otherwise. */ public static boolean placeRandomShip(char board[][], int len, int id, Random rand) { //FIXME return false; } /** * This method interacts with the user to place a ship on the game board of the human player and * the computer opponent. The process is as follows: * 1 - Print the user primary board, using the printBoard. * 2 - Using the promptChar method, prompt the user with "Vertical or horizontal? (v/h) ". * A response of v is interpreted as vertical. Anything else is assumed to be horizontal. * 3 - Using the promptInt method, prompt the user for an integer representing the * "ship length", where the minimum ship length is Config.MIN_SHIP_LEN and the maximum * ship length is width or height of the game board, depending on the input of the user * from step 1. * 4 - Using the promptStr method, prompt the user for the "x-coord". The maximum value * should be calculated based on the width of the board and the length of the ship. You * will need to use the coordAlphaToNum and coordNumToAlpha methods to covert between int * and String values of coordinates. * 5 - Using the promptInt method, prompt the user for the "y-coord". The maximum value * should be calculated based on the width of the board and the length of the ship. * 6 - Check if there is space on the board to place the ship. * 6a - If so: * - Place the ship on the board using placeShip. * - Then, call placeRandomShip to place the opponents ships of the same length. * - If placeRandomShip fails, print out the error message (terminated by a new * line): "Unable to place opponent ship: id", where id is the ship id, and * return false. * 6b - If not: * - Using promptChar, prompt the user with "No room for ship. Try again? (y/n): " * - If the user enters a 'y', restart the process at Step 1. * - Otherwise, return false. * * @param sc The Scanner instance to read from System.in. * @param boardPrime The human player board. * @param boardOpp The opponent board. * @param id The ship id, assumed to be 1 to 9. * @param rand The Random object. * @return true if ship placed successfully by player and computer opponent, false otherwise. */ public static boolean addShip(Scanner sc, char boardPrime[][], char boardOpp[][], int id, Random rand) { return false; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions