Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjo0222988 committed Oct 9, 2023
1 parent 6b131f1 commit 0933528
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,27 @@ def fire(self, row: int, column: int) -> str:

if self.is_drowned:
return "Sunk!"
else:
return "Hit!"
return "Hit!"

def is_it_drowned(self) -> None:
self.is_drowned = True
for deck in self.decks:
if deck.is_alive:
self.is_drowned = False
self.is_drowned = not any([deck.is_alive for deck in self.decks])

def get_length(self) -> int:
return len(self.decks)

@staticmethod
def create_decks(ship_begin: Tuple[int, int],
ship_end: Tuple[int, int]) -> List:

if ship_begin == ship_end:
return [Deck(*ship_begin)]

border = 0
if ship_begin[1] != ship_end[1]:
border = 1
ship_decks = []

ship_decks = [Deck(ship_begin[0], ship_begin[1])]
blank_deck = [ship_begin[0], ship_begin[1]]
for row in range(ship_begin[0], ship_end[0] + 1):
for column in range(ship_begin[1], ship_end[1] + 1):
ship_decks.append(Deck(row, column))

while blank_deck[border] != ship_end[border]:
blank_deck[border] += 1
ship_decks.append(Deck(blank_deck[0], blank_deck[1]))
return ship_decks


Expand All @@ -73,8 +66,7 @@ def fire(self, location: Tuple[int, int]) -> str:
ship = self.field.get(location)
if ship is not None:
return ship.fire(*location)
else:
return "Miss!"
return "Miss!"

def print_field(self) -> None:
row = -1
Expand Down

0 comments on commit 0933528

Please sign in to comment.