From 9513f6e1f1f3c63a9bb9a262a5cc61586dd0fb2a Mon Sep 17 00:00:00 2001 From: Dahmane Lynda <lynda.dahmane.etu@115p6.fil.univ-lille.fr> Date: Fri, 16 Feb 2024 14:31:45 +0100 Subject: [PATCH] init --- Tp5/minesweeper/minesweeper.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Tp5/minesweeper/minesweeper.py b/Tp5/minesweeper/minesweeper.py index 8358867..0476c3b 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): -- GitLab