Skip to content

Commit 4cddf2e

Browse files
committed
silly fix to *maybe* satisfy pylint
1 parent a90ff20 commit 4cddf2e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Metro/Metro_RP2350_Minesweeper/gamelogic.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,17 @@ def _set_board(self, x, y, value):
9999
raise ValueError("Game board not initialized")
100100
self.game_board[x, y] = value # pylint: disable=unsupported-assignment-operation
101101

102-
def _get_board(self, x, y):
102+
def _get_board(self, x, y, dx=0, dy=0):
103103
if not isinstance(self.game_board, TileGrid):
104104
raise ValueError("Game board not initialized")
105-
return self.game_board[x, y] # pylint: disable=unsubscriptable-object
105+
106+
if x + dx < 0 or x + dx >= self.grid_width:
107+
return None # Off screen
108+
109+
if y + dy < 0 or y + dy >= self.grid_height:
110+
return None # Off screen
111+
112+
return self.game_board[x + dx, y + dy] # pylint: disable=unsubscriptable-object
106113

107114
def _compute_counts(self):
108115
"""For each mine, increment the count in each non-mine square around it"""
@@ -166,6 +173,7 @@ def square_flagged(self, coords):
166173
return True
167174

168175
def square_chorded(self, coords):
176+
# pylint: disable=too-many-nested-blocks
169177
if self._status in (STATUS_WON, STATUS_LOST):
170178
return False
171179

@@ -174,26 +182,19 @@ def square_chorded(self, coords):
174182
# Count the flags around this square
175183
flags = 0
176184
for dx in (-1, 0, 1):
177-
if x + dx < 0 or x + dx >= self.grid_width:
178-
continue # off screen
179185
for dy in (-1, 0, 1):
180-
if y + dy < 0 or y + dy >= self.grid_height:
181-
continue # off screen
182186
if dx == 0 and dy == 0:
183187
continue # don't process where the mine
184-
if self._get_board(x + dx, y + dy) == FLAG:
188+
if self._get_board(x, y, dx, dy) == FLAG:
185189
flags += 1
186190
if flags == self._get_board(x, y):
187191
# Uncover all non-flagged squares around here
188192
for dx in (-1, 0, 1):
189-
if x + dx < 0 or x + dx >= self.grid_width:
190-
continue # off screen
191193
for dy in (-1, 0, 1):
192-
if y + dy < 0 or y + dy >= self.grid_height:
193-
continue # off screen
194194
if dx == 0 and dy == 0:
195195
continue # don't process where the mine
196-
if self._get_board(x + dx, y + dy) != FLAG:
196+
_tile_content = self._get_board(x, y, dx, dy)
197+
if _tile_content != FLAG and _tile_content != None:
197198
if not self.square_clicked((x + dx, y + dy)):
198199
return False # lost
199200
return True

0 commit comments

Comments
 (0)