Question: def has _ ship [ fleet grid: list [ 1 ist [ str ] ] , fow _ start: int, col _ start: int, ship

def has_ship[fleet grid: list[1ist[str]], fow_start: int, col_start: int,
ship_syntol: str, ship_sizer int) bool:
wauneturn True if and only if a ship that (1) uses ship_symbol as its thip
symool and (2) has length ship_size appears in fleet onid starting at
position (row start, col_start), where (rou_start, col_start) is the
top-most/luft-most correr of the ship.
If the ship has ship_size z or more and appears as both a colum and a row,
return False.
Preconditions:
=1i(i,j)==1-8rleetrrid
def has_ship(fleet_grid: list[1ist[str]], row_start; int, col_starts int, ship_symboli str, ship_size: int]=> booli
"*"Return True if and only if a ship that (1) uses ship_symbol as its ship symbol and (2) has length ship_size appaars in fleet grid starting at position (rou_start, col_start), where (row_start, col_start) is the tro-most/left nost corner of the ship.
If the ship has ship size 2 or more and appears as both a column and a row, return False.
Preconditions:
len(flaat_grid)
Ien(fleet grid[i])=len(fleetgrid) for each value of in inge(len(fleet grid))
row_start c len(fleet_grid)
ib col_start i len(fleet_grid)
MIII SHIP_SIZI = ship_size s= HAX_SHr_SIZE
fleet grid[i][5] i= ship syrbol for each of the coordinates
) Ca (rom_start =1, col_start) or
(i, j)=(row_stant, col_start -1)
when those coordinstes ape valid indexes for fleat_grid
grid =[[EYPTY,'b', EMPTY],['a','b', EMPTY],[EAPTY, EFPTY, ENPTY]] has,ship(erid,a,1,'b',2)
True
has_ship(grid, e,1,'b',1)
False
has_ship(grid,6,1,?'b',3
False
has_ship(erid,1, e,'a',1)
True has ship(erid,(:8,8,b',3}
False
 def has_ship[fleet grid: list[1ist[str]], fow_start: int, col_start: int, ship_syntol: str, ship_sizer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!