diff --git a/Tp5/minesweeper/minesweeper.py b/Tp5/minesweeper/minesweeper.py index 8358867d13fe64c75a963638d0008fe09e7a3e54..0476c3b02a524913e754f3cde996a6ccb7e7a8d5 100755 --- a/Tp5/minesweeper/minesweeper.py +++ b/Tp5/minesweeper/minesweeper.py @@ -61,17 +61,13 @@ def neighborhood(x: int, y: int, width: int, height: int) -> list[tuple[int, int $$$ neighborhood(3, 9, 10, 10) [(2, 8), (2, 9), (3, 8), (4, 8), (4, 9)] """ - res=[] - if x>0: - res+=[(x-1,y)] - if x< width-1: - res+=[(x+1,y)] - if y>0: - res+=[(x,y-1)] - if y<height-1: - res+=[(x,y+1)] - - return res + neighbors=[] + for i in range(x-1,x+2): + for j in range(y-1,y+2): + if 0<=i<width and 0<=j<height and (i,j)!=(x,y): + neighbors.append((i,j)) + return neighbors + class Minesweeper(): """ @@ -120,7 +116,8 @@ class Minesweeper(): """ self.width= width self.height= height - self.nbombs= nbombs + self.state= GameState.unfinished + self.nbombs=nbombs self.grid=[(cell() for x in range(width) for y in range(height))] @@ -139,8 +136,7 @@ class Minesweeper(): """ - return self.grid[x][y] - + def _put_a_bomb_at(self, x: int, y: int):