Skip to content

Commit

Permalink
fix adjacency ship, replace row and column
Browse files Browse the repository at this point in the history
  • Loading branch information
sashasyrota committed Jan 4, 2025
1 parent 3bb9697 commit e7533b9
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def fire(self, location: tuple) -> str:
return "Miss!"

def print_field(self) -> None:
for column in range(10):
for row in range(10):
if (column, row) in self.field:
if self.field[(column, row)].is_drowned:
for row in range(10):
for column in range(10):
if (row, column) in self.field:
if self.field[(row, column)].is_drowned:
print(" x ", end="")
elif not (self.field[(column, row)].
get_deck(column, row).
elif not (self.field[(row, column)].
get_deck(row, column).
is_alive):
print(" * ", end="")
else:
Expand All @@ -81,9 +81,12 @@ def check_coord_on_desk(self) -> bool:
check_coord_3 = (coord[0] + 1, coord[1] + 1)
if check_coord_3 in self.field:
return False
check_coord_4 = (coord[0] - 1, coord[1] + 1)
if check_coord_4 in self.field:
return False
return True

def _validate_field(self) -> str:
def validate_field(self) -> str:
self.total_ships = len(self.ships)
self.single_deck, self.double_deck = 0, 0
self.three_deck, self.four_deck = 0, 0
Expand All @@ -108,19 +111,3 @@ def _validate_field(self) -> str:
and self.four_deck == 1):
return "Validation passed"
return "Validation not passed"

#
# battle_ship = Battleship(
# ships=[
# ((0, 0), (0, 3)),
# ((0, 5), (0, 6)),
# ((0, 8), (0, 9)),
# ((2, 0), (4, 0)),
# ((2, 4), (2, 6)),
# ((2, 8), (2, 9)),
# ((9, 9), (9, 9)),
# ((7, 7), (7, 7)),
# ((7, 9), (7, 9)),
# ((9, 7), (9, 7)),
# ]
# )

0 comments on commit e7533b9

Please sign in to comment.