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. Its probably a simple fix but i cant see it.Overall, I feel that my code is a bit verbose. I also tried to have a 1 appear if the players guess one space away, but its not working and I can't figure out why. I have a 7x7 board of x's and when the player enters a row and column it deletes the columnĪnd replaces it with a. Trying to make simple minesweeper game in python, but have one problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |