![]() You create self.board in the _init_() method, and then only use it in the play() method. Your Game class might not need to be a class at all. ![]() My solution to the "first click shouldn't be a mine" problem is I clear the space around the first click so you always get the eight spaces around the first click for free. So, the bottom right corner would be likely to have less mines. Currently, each square has an individual probability of being a mine and mine generation is stopped when max_mines is reached. I'm also looking to improve the mine generation algorithm. The _point_neighbors function could probably be improved (having a lambda seems to be overkill). The hook for the print_board function seems a bit suspect. I think there's lots of places where my code could be made a lot more readable. Neighbor_set = set(itertools.product(row_neighbors, col_neighbors)) Row_neighbors = list(filter(lambda val: val >= 0 and val = 0 and val <, )) Return ]] for point in self._point_neighbors()] Return len(list(filter(lambda square: square.mine, ]] for point in self._point_neighbors()]))) Represents a single square in the minesweeper board.Ī square may have or may not have a mine, may be clicked or unclicked.ĭef _init_(self, board, row, col, mine): Self.number_of_mines = self.number_of_mines + 1 Is_mine = random.randrange(100) = self.max_mines: """ Determine if a square is a mine while generating the board. Self.squares = for row in range(rows)] """ Return the square at the given row and column."""ĭef _create_squares(self, cols, rows, mines_percentage):Ĭreate a grid of squares of size rows by cols. If not square.mine and not square.clicked: Return " " + str(square.mine_neighbors()) + " " ![]() Self.click_square(neighbor.row, l)ĭef print_board_wrapper(self, print_hook): Neighbors which don't have neighboring mines. ![]() If not self._valid_square(row, col) or self._get_square(row, col).clicked: Self._create_squares(ls, self.rows, mines_percentage) Mines_percentage = (100 * self.max_mines / (rows*cols))/3 """ Represents a minesweeper board with squares. Models.py """ Data models for a minesweeper CLI game. Overall, I feel that my code is a bit verbose. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |