PythonCodeFight-Day18

Day_18

Intro

Q24. Mindsweeper

In the popular Minesweeper game you have a board with some mines and those cells that don’t contain a mine have a number in it that indicates the total number of mines in the neighboring cells. Starting off with some arrangement of mines we want to create a Minesweeper game setup.

알고리즘 고민, 및 러프한 코드 작성 중!

작성 흐름

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
# Test case

import numpy as np

matrix = [[True, False, False],
[False, True, False],
[False, False, False]]

# 알고리즘 생각해보기

# 만약 현재 값이 true인 경우, 현재 인덱스의 값은 1
# 만약 현재 값이 false인 경우, 현재 인덱스의 값은 현재 위치 값의 주위에 true 개수

row = len(matrix)
col = len(matrix[0])

MineCounterMat = np.zeros((row, col))

print(row)
print(col)

for idx_row in range(row):

for idx_col in range(col):

MineCounter = 0

CurrVal = matrix[idx_row][idx_col]

if idx_row == 0:
idx_row_set = [idx_row, idx_row + 1]
if idx_row == row:
idx_row_set = [idx_row - 1, idx_row]

if idx_col == 0:
idx_col_set = [idx_col, idx_col + 1]
if idx_col == col:
idx_col_set = [idx_col - 1, idx_col]

print(idx_row_set)
print(idx_col_set)
for mine_row in idx_row_set:
for mine_col in idx_col_set:
if matrix[mine_row][mine_col]:
print(mine_row)
print(mine_col)
MineCounter = MineCounter + 1

MineCounterMat[idx_row][idx_col] = MineCounter

print(MineCounterMat)