マインスイーパ、まだ。私はそれを行う方法を見つけましたが、これを行うには簡単な方法が必要であることを知っています. 周囲にいくつの爆弾 ("b") があるかを表すために、行列に数値を配置する必要があります。これは私が持っているものであり、もっと短い方法が必要であることを知っています。
def check(y,x):
if ((y < 0) or (y >= len(mat1)) or (x < 0) or (x >= len(mat1))):
return (False)
else:
return mat1[y][x]
def addscores():
for x in range(len(mat1)):
for y in range(len(mat1)):
if mat1[y][x] != "b":
if check(y-1,x-1) == "b" or check(y,x-1) == "b" or check(y+1,x-1) == "b" or check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) =="b":
mat1[y][x] = 1
if check(y-1,x-1) == "b":
if check(y,x-1) == "b" or check(y+1,x-1) == "b" or check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y,x-1) == "b":
if check(y+1,x-1) == "b" or check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y+1,x-1) == "b":
if check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y+1,x) == "b":
if check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y+1,x+1) == "b":
if check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y,x+1) == "b":
if check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 2
if check(y-1,x+1) == "b":
if check(y-1,x) == "b":
mat1[y][x] = 2
if check(y-1,x-1) == "b":
if check(y,x-1) == "b":
if check(y+1,x-1) == "b" or check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 3
if check(y+1,x-1) == "b":
if check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 3
if check(y+1,x) == "b":
if check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 3
if check(y+1,x+1) == "b":
if check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 3
if check(y,x+1) == "b":
if check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 3
if check(y-1,x-1) == "b":
if check(y,x-1) == "b":
if check(y+1,x-1) == "b":
if check(y+1,x) == "b" or check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 4
if check(y+1,x-1) == "b":
if check(y+1,x) == "b":
if check(y+1,x+1) == "b" or check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 4
if check(y+1,x) == "b":
if check(y+1,x+1) == "b":
if check(y,x+1) == "b" or check(y-1,x+1) == "b" or check(y-1,x) == "b":
mat1[y][x] = 4
#ETC