border
This commit is contained in:
parent
eac39de2be
commit
90836eda25
@ -103,7 +103,7 @@ def kill_field(field):
|
|||||||
for i in range(10):
|
for i in range(10):
|
||||||
for j in range(10):
|
for j in range(10):
|
||||||
if cells[i][j] == '+':
|
if cells[i][j] == '+':
|
||||||
ship = set([(i, j)])
|
ship = [(i, j)]
|
||||||
queue = [(i, j)]
|
queue = [(i, j)]
|
||||||
killed = True
|
killed = True
|
||||||
while queue:
|
while queue:
|
||||||
@ -116,14 +116,14 @@ def kill_field(field):
|
|||||||
elif cells[x - 1][y] == '+':
|
elif cells[x - 1][y] == '+':
|
||||||
if (x - 1, y) not in ship:
|
if (x - 1, y) not in ship:
|
||||||
queue.append((x - 1, y))
|
queue.append((x - 1, y))
|
||||||
ship.add((x - 1, y))
|
ship.append((x - 1, y))
|
||||||
if x < 9:
|
if x < 9:
|
||||||
if cells[x + 1][y] == 'o':
|
if cells[x + 1][y] == 'o':
|
||||||
killed = False
|
killed = False
|
||||||
break
|
break
|
||||||
elif cells[x + 1][y] == '+':
|
elif cells[x + 1][y] == '+':
|
||||||
if (x + 1, y) not in ship:
|
if (x + 1, y) not in ship:
|
||||||
ship.add((x + 1, y))
|
ship.append((x + 1, y))
|
||||||
queue.append((x + 1, y))
|
queue.append((x + 1, y))
|
||||||
if y > 0:
|
if y > 0:
|
||||||
if cells[x][y - 1] == 'o':
|
if cells[x][y - 1] == 'o':
|
||||||
@ -131,7 +131,7 @@ def kill_field(field):
|
|||||||
break
|
break
|
||||||
elif cells[x][y - 1] == '+':
|
elif cells[x][y - 1] == '+':
|
||||||
if (x, y - 1) not in ship:
|
if (x, y - 1) not in ship:
|
||||||
ship.add((x, y - 1))
|
ship.append((x, y - 1))
|
||||||
queue.append((x, y - 1))
|
queue.append((x, y - 1))
|
||||||
if y < 9:
|
if y < 9:
|
||||||
if cells[x][y + 1] == 'o':
|
if cells[x][y + 1] == 'o':
|
||||||
@ -139,9 +139,11 @@ def kill_field(field):
|
|||||||
break
|
break
|
||||||
elif cells[x][y + 1] == '+':
|
elif cells[x][y + 1] == '+':
|
||||||
if (x, y + 1) not in ship:
|
if (x, y + 1) not in ship:
|
||||||
ship.add((x, y + 1))
|
ship.append((x, y + 1))
|
||||||
queue.append((x, y + 1))
|
queue.append((x, y + 1))
|
||||||
if killed:
|
if killed:
|
||||||
for x, y in ship:
|
for x, y in ship:
|
||||||
cells[x][y] = 'x'
|
cells[x][y] = 'x'
|
||||||
|
for x, y in find_borders(ship[0][0], ship[0][1], len(ship), not bool(ship[-1][1] - ship[0][1])):
|
||||||
|
cells[x][y] = '.'
|
||||||
return ''.join([''.join(arr) for arr in cells])
|
return ''.join([''.join(arr) for arr in cells])
|
||||||
|
Loading…
Reference in New Issue
Block a user