Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def has _ ship [ fleet grid: list [ 1 ist [ str ] ] , fow _ start: int, col _ start: int, ship
def hasshipfleet grid: lististstr fowstart: int, colstart: int,
shipsyntol: str shipsizer int bool:
wauneturn True if and only if a ship that uses shipsymbol as its thip
symool and has length shipsize appears in fleet onid starting at
position row start, colstart where roustart, colstart is the
topmostluftmost correr of the ship.
If the ship has shipsize or more and appears as both a colum and a row,
return False.
Preconditions:
rid
def hasshipfleetgrid: lististstr rowstart; int, colstarts int, shipsymboli str shipsize: int booli
Return True if and only if a ship that uses shipsymbol as its ship symbol and has length shipsize appaars in fleet grid starting at position roustart, colstart where rowstart, colstart is the tromostleft nost corner of the ship.
If the ship has ship size or more and appears as both a column and a row, return False.
Preconditions:
lenflaatgrid
Ienfleet gridilenrid for each value of in ingelenfleet grid
rowstart lenfleetgrid
ib colstart i lenfleetgrid
MIII SHIPSIZI shipsize s HAXSHrSIZE
fleet gridi i ship syrbol for each of the coordinates
Ca romstart colstart or
i jrowstant, colstart
when those coordinstes ape valid indexes for fleatgrid
grid EYPTYb EMPTYab EMPTYEAPTY EFPTY, ENPTY has,shiperid
True
hasshipgrid eb
False
hasshipgrid
False
hasshiperid ea
True has shiperid:
False
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