Skip to content

Commit 2dfc8d1

Browse files
committed
Implement winning configuration check
1 parent 371891b commit 2dfc8d1

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Minesweep/code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ def expand_uncovered(start_x, start_y):
136136
return number_uncovered
137137

138138

139+
def check_for_win():
140+
"""Check for a complete, winning game. That's one with all squares uncovered
141+
and all bombs correctly flagged, with no non-bomb squares flaged.
142+
"""
143+
for x in range(20):
144+
for y in range(15):
145+
visible = tilegrid[x, y]
146+
under = get_data(x, y)
147+
if visible == BLANK:
148+
print('Found a unexplored square at (%d, %d)' % (x, y))
149+
return False #still covewred squares, not done
150+
elif visible == BOMBFLAGGED and under != BOMB:
151+
print('Found misflagged bomb at (%d, %d)' % (x, y))
152+
return False #misflagged bombs, not done
153+
return True
154+
139155
def play_a_game():
140156
number_uncovered = 0
141157
touch_x = -1

0 commit comments

Comments
 (0)