Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def step5(grid, n):
- for i in range(n):
- for j in range(n):
- mine_found = False
- if grid[i][j] != -1:
- a = [1, 1, -1, -1]
- b = [1, -1, 1, -1]
- for x in range(len(a)):
- if i + a[x] >= 0 and j + b[x] >= 0 and i + a[x] < n and j + b[x] < n:
- if grid[i + a[x]][j + b[x]] == -1:
- mine_found = True
- if mine_found is True:
- grid[i][j] *= 2
- def solve_minesweeper(puzzle_array):
- n = len(puzzle_array)
- mines = list()
- rows_mines = set()
- ret = [None] * n
- for i in range(n):
- ret[i] = [0] * n
- for j in range(n):
- if puzzle_array[i][j] == 'm':
- mines.append((i, j))
- ret[i][j] = -1
- if i % 2 != 0:
- rows_mines.add(i)
- else:
- ret[i][j] = 0
- for i, j in mines:
- for idx in range(-1, 2):
- for jdx in range(-1, 2):
- if not (idx == 0 and jdx == 0):
- ri = i + idx
- rj = j + jdx
- if ri >= 0 and rj >= 0 and ri < n and rj < n:
- if ret[ri][rj] != -1:
- ret[ri][rj] += 1
- if idx == 1 and jdx == 0:
- if ret[ri][rj] != -1:
- ret[ri][rj] = 2
- if idx == 0 and jdx == 1:
- if ret[ri][rj] != -1:
- ret[ri][rj] = 0
- for row in rows_mines:
- for j in range(n):
- if ret[row][j] != -1:
- ret[row][j] *= 3
- step5(ret, n)
- print(type(ret[0]))
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement