1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
import numpy as np
matrix = [[True, False, False], [False, True, False], [False, False, False]]
row = len(matrix)
col = len(matrix[0])
MineCounterMat = np.zeros((row, col))
print(matrix)
print(row) print(col)
for idx_row in range(row): for idx_col in range(col):
MineCounter = 0
if idx_row == 0: idx_row_set = [idx_row, idx_row + 1] elif idx_row == row-1: idx_row_set = [idx_row - 1, idx_row] else: idx_row_set = [idx_row - 1, idx_row, idx_row + 1]
if idx_col == 0: idx_col_set = [idx_col, idx_col + 1] elif idx_col == col-1: idx_col_set = [idx_col - 1, idx_col] else: idx_col_set = [idx_col - 1, idx_col, idx_col + 1]
print(idx_row_set) print(idx_col_set)
for mine_row in idx_row_set: for mine_col in idx_col_set: print("row: %d, col: %d" % (idx_row, idx_col)) print("mine_row: %d, mine_col: %d" % (mine_row, mine_col))
if not ((mine_row == idx_row) and (mine_col == idx_col)): if matrix[mine_row][mine_col]: MineCounter = MineCounter + 1 print("Mine Counter: %d" % (MineCounter))
MineCounterMat[idx_row][idx_col] = MineCounter print(MineCounterMat)
|