python
import random

field = [['~' for _ in range(10)] for _ in range(10)]

ships = [(4, 'Авианосец'), (3, 'Крейсер'), (3, 'Эсминец'), (2, 'Торпедный катер'), (2, 'Торпедный катер'), (2, 'Торпедный катер'), (1, 'Лодка'), (1, 'Лодка'), (1, 'Лодка'), (1, 'Лодка')]

def place_ship(ship):
size, name = ship
direction = random.choice(['горизонтально', 'вертикально'])
if direction == 'горизонтально':
while True:
x = random.randint(0, 9)
y = random.randint(0, 10 - size)
if all(field[x][y+i] == '~' for i in range(size)):
for i in range(size):
field[x][y+i] = name[0]
break
else:
while True:
x = random.randint(0, 10 - size)
y = random.randint(0, 9)
if all(field[x+i][y] == '~' for i in range(size)):
for i in range(size):
field[x+i][y] = name[0]
break

for ship in ships:
place_ship(ship)

def print_field():
print(' ', ' '.join(map(str, range(10))))
for i in range(10):
print(i, ' '.join(field[i]))

def check_hit(x, y):
if field[x][y] != '~':
ship_name = ''
for ship in ships:
if ship[0] == int(field[x][y]):
ship_name = ship[1]
print('Попадание в', ship_name)
field[x][y] = 'X'
else:
print('Мимо!')

while True:
print_field()
target_x = int(input('Выберите строку (0-9): '))
target_y = int(input('Выберите столбец (0-9): '))
check_hit(target_x, target_y)
if all(all(cell == '~' for cell in row) for row in field):
print('Вы победили!')
break
