Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Minesweeper solution in Uncategorized category for Minesweeper by capback250
COORDS = ((-1,-1), (-1, 0), (-1, 1), (0,-1), (0, 1), (1, -1), (1, 0), (1, 1))
def checkio(field):
if field[0][0] == -1:
return [False, 0, 0]
out = [None, None, None, None]
for i1, k1 in enumerate(field):
for i2, k2 in enumerate(k1):
if k2 in range(1, 9):
minesaround = 0
unknow = 0
empty = 0
justNumbers= 0
for c in COORDS:
x, y = i1 + c[0], i2 + c[1]
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] == 9:
minesaround += 1
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] == -1:
unknow += 1
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] == 0:
empty += 1
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] in range(1,9):
justNumbers += 1
if minesaround == field[i1][i2]:
for c in COORDS:
x, y = i1 + c[0], i2 + c[1]
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] == -1:
return [False, x, y]
minesaround += 1
if (8 - minesaround - empty - justNumbers) == 1:
for c in COORDS:
x, y = i1 + c[0], i2 + c[1]
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]) and field[x][y] == -1:
return [True, x, y]
if k2 == -1:
around = 0
for c in COORDS:
x, y = i1 + c[0], i2 + c[1]
if x >= 0 and y >=0 and x < len(field) and y < len(field[0]):
around += field[x][y]
if out[0] is None:
out = [around, True, i1, i2]
if around > out[0]:
out = [around, True, i1, i2]
return out[1:]
Jan. 31, 2016