загружаю исправление дз с 1кой

This commit is contained in:
ehermakov 2023-11-27 20:44:02 +03:00
parent 01d88ffc0f
commit 3c010fa85a
1 changed files with 5 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import math
buttons = []
field_size = 10
ship_size = 3
ship_size = 4
ship_direction = 1
empty_field = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
@ -34,9 +34,9 @@ class ShootResult(Enum):
def set_ship(row, col, size, direction):
if row < 0 or row > field_size - 1:
if row < 0 or row > field_size:
return
if col < 0 or col > field_size - 1:
if col < 0 or col > field_size:
return
index = row * field_size + col
if direction == 0:
@ -120,13 +120,13 @@ def check_possible(field, row, col):
# Здесь мы знаем, что корабль помещается на поле.
if field_size - row >= ship_size:
# Теперь нужно проверить, не заблокировано ли какое-то из полей,
for i in range(row, row + ship_size):
for i in range(row, row + ship_size + 1):
if check_blocked(field, row, col):
return True
if ship_direction == 1:
if field_size - col >= ship_size:
for i in range(col, col + ship_size):
for i in range(col, col + ship_size + 1):
if check_blocked(field, row, col):
return True
return False