Skip to content

Commit

Permalink
Solution

Browse files Browse the repository at this point in the history
  • Loading branch information
K. Petrychenko committed Jul 11, 2024
1 parent 670eaee commit 579ba4b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def _validate_field(self) -> None:
length: int = len(ship.decks)
if length in counts:
counts[length] += 1
if counts[1] != 4 or counts[2] != 3 or \
counts[3] != 2 or counts[4] != 1:
if (
counts
[1] != 4 or counts[2] != 3 or counts[3] != 2 or counts[4] != 1
):
raise ValueError("Invalid number of ships of each type")
self._check_no_neighbors()

Expand All @@ -99,8 +101,10 @@ def _check_no_neighbors(self) -> None:
deck.row + direction[0],
deck.column + direction[1]
)
if neighbor in self.field and \
self.field[neighbor] != ship:
raise \
ValueError("Ships are located "
"in neighboring cells")
if (
neighbor
in self.field and self.field[neighbor] != ship
):
raise ValueError(
"Ships are located in neighboring cells"
)

0 comments on commit 579ba4b

Please sign in to comment.