Skip to content

Instantly share code, notes, and snippets.

@Qman11010101
Last active September 25, 2019 02:57
Show Gist options
  • Save Qman11010101/472db7eb9c54d6770cbdb6de1e5c504d to your computer and use it in GitHub Desktop.
Save Qman11010101/472db7eb9c54d6770cbdb6de1e5c504d to your computer and use it in GitHub Desktop.
Python Minesweeper Analyzer
# 入力部
print("縦の高さを入力してね")
height = int(input())
print("開いていないブロックをb、地雷と確定しているブロックをm、開いているマスをx、数字はそのまま、スペースを空けないで入力してね")
print("終わったら改行してね")
stage = []
for loop in range(height):
stage.append(list(input()))
# ステージ生成部
xList1 = ["x"] * (len(stage[0]))
xList2 = xList1[:]
stage.append(xList1)
stage.insert(0, xList2)
for line in stage:
line.append("x")
line.insert(0, "x")
for line in stage:
cnt = 0
for block in line:
if block not in ("b", "m", "s", "x"):
line[cnt] = int(block)
cnt += 1
for i in range(10):
# 地雷判定部
for line in range(len(stage)):
for block in range(len(stage[line])):
if type(stage[line][block]) is int:
bls = [stage[line-1][block-1], stage[line-1][block], stage[line-1][block+1], stage[line][block-1], stage[line][block+1], stage[line+1][block-1], stage[line+1][block], stage[line+1][block+1]]
if bls.count("b") + bls.count("m") == stage[line][block]:
if stage[line-1][block-1] == "b":
stage[line-1][block-1] = "m"
if stage[line-1][block] == "b":
stage[line-1][block] = "m"
if stage[line-1][block+1] == "b":
stage[line-1][block+1] = "m"
if stage[line][block-1] == "b":
stage[line][block-1] = "m"
if stage[line][block+1] == "b":
stage[line][block+1] = "m"
if stage[line+1][block-1] == "b":
stage[line+1][block-1] = "m"
if stage[line+1][block] == "b":
stage[line+1][block] = "m"
if stage[line+1][block+1] == "b":
stage[line+1][block+1] = "m"
# 安全判定部
for line in range(len(stage)):
for block in range(len(stage[line])):
if type(stage[line][block]) is int:
bls = [stage[line-1][block-1], stage[line-1][block], stage[line-1][block+1], stage[line][block-1], stage[line][block+1], stage[line+1][block-1], stage[line+1][block], stage[line+1][block+1]]
if bls.count("m") == stage[line][block]:
if stage[line-1][block-1] == "b":
stage[line-1][block-1] = "s"
if stage[line-1][block] == "b":
stage[line-1][block] = "s"
if stage[line-1][block+1] == "b":
stage[line-1][block+1] = "s"
if stage[line][block-1] == "b":
stage[line][block-1] = "s"
if stage[line][block+1] == "b":
stage[line][block+1] = "s"
if stage[line+1][block-1] == "b":
stage[line+1][block-1] = "s"
if stage[line+1][block] == "b":
stage[line+1][block] = "s"
if stage[line+1][block+1] == "b":
stage[line+1][block+1] = "s"
# 表示整頓部
print("------------------------------")
stage.pop(-1)
stage.pop(0)
for loop in range(len(stage)):
stage[loop].pop(-1)
stage[loop].pop(0)
stage[loop] = "".join(list(map(str, stage[loop])))
for line in stage:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment