diff --git a/TP5/minesweeper/minesweeper.py b/TP5/minesweeper/minesweeper.py index 243b5be299785e043846ab5ad927cc8d22e15945..0d4925d75196e6ba0fe0e0a7887a966676e8c18e 100644 --- a/TP5/minesweeper/minesweeper.py +++ b/TP5/minesweeper/minesweeper.py @@ -1,6 +1,6 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- - +# Nom = TANOH PASCAL +# TP5 groupe MI 15 +# date: 14/02/2024 """ :mod:`minesweeper` module @@ -61,7 +61,18 @@ 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)] """ - ... + neighbors = [] + for distance_x in range(-1,2): + for distance_y in range(-1,2): + x_1,y_1 = x + distance_x, y + distance_y + if 0 <= x_1 < width and 0 <= y_1 < height and (x_1,y_1) != (x,y): + neighbors.append((x_1,y_1)) + return neighbors + + + + + class Minesweeper(): """ @@ -103,7 +114,19 @@ class Minesweeper(): $$$ game.state == GameState.unfinished True """ - ... + self.width= width + self.height= height + self.nbombs= nbombs + self.state= GameState.unfinished + self.grid = [[cell() for i in range(width)] for j in range(height)] + n=0 + while n<nbombs: + y=random.randint(0,width-1) + x=random.randint(0,height-1) + if not self.grid[x][y].is_bomb: + self._put_a_bomb_at(x,y) + n=n+1 + def get_cell(self, x: int, y: int) -> Cell: """