Question
In java Create a data structure that represents a 25X25 grid. You will use this grid to place the two battleships and to track the
In java
Create a data structure that represents a 25X25 grid. You will use this grid to place the two battleships and to track the progress of your search for the battleships. 1. Read in Coordinates Coordinates are stored in a file named input.txt. Each line represents ONE game so the following sample represents three different runs of the game. For each game there is one carrier and one submarine. The carrier occupies 5 cells represented by the first five coordinates in the line (below), and the submarine represents the remaining three coordinates. See example below:
(0,0)(0,1)(0,2)(0,3)(0,4)(4,15)(4,16)(4,17)
(5,9)(5,10)(5,11)(5,12)(5,13)(20,5)(20,6)(20,7)
(15,3)(16,3)(17,3)(18,3)(19,3)(24,6)(24,7)(24,8)
Create a 25X25 grid and place the carrier and submarine onto the grid.
Create a BattleshipSearch class This class is responsible for searching the grid for both the carrier and the submarine. (Note: Just reading the results from the input file.read in the coordinates, place the ships, and then independently search for them! You must use a search strategy and will output the text shown at the bottom of the page to the console for each game (with example coordinates from first row of text file). For each game systematically use each of the following three search strategies
Create a family of search strategies.
a. Horizontal Sweep Strategy: Start at 0,0 and perform a systematic line-by-line sweep through the grid until you have found both ships.
b. Random Search Strategy: Use the random number generator to randomly check coordinates until you have found both ships. c. Strategic Search: Figure out a more efficient search strategy and implement it as the third strategy. See how efficient your approach can be.
Game 1: Strategy:
Horizontal Sweep Number of cells searched: 240
Carrier found: (0,0) to (0,4) Submarine found: (4,15) to (4,17)
Strategy: Random Search Number of Cells searched: 490
Carrier found: (0,0) to (0,4) Submarine found: (4,15) to (4,17)
Strategy: Strategic Search Number of Cells searched: 110
Carrier found: (0,0) to (0,4) Submarine found: (4,15) to (4,17)
Repeat the game for each row in the input file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started