templateposa.blogg.se

Simple minesweeper python code
Simple minesweeper python code





simple minesweeper python code

(2 / 3) * width + BOARD_PADDING, (1 / 3) * height - 50,īuttonText = mediumFont.render("AI Move", True, BLACK) Screen.blit(neighbors, neighborsTextRect) LineRect.center = ((width / 2), 150 + 30 * i)īuttonRect = pygame.Rect((width / 4), (3 / 4) * height, width / 2, 50)īuttonText = mediumFont.render("Play Game", True, BLACK)īuttonTextRect.center = buttonRect.center Line = smallFont.render(rule, True, WHITE) "Right-click a cell to mark it as a mine.", Title = largeFont.render("Play Minesweeper", True, WHITE) # Keep track of revealed cells, flagged cells, and if a mine was hit Game = Minesweeper(height=HEIGHT, width=WIDTH, mines=MINES)Īi = MinesweeperAI(height=HEIGHT, width=WIDTH) LargeFont = (OPEN_SANS, 40)īoard_width = ((2 / 3) * width) - (BOARD_PADDING * 2)īoard_height = height - (BOARD_PADDING * 2)Ĭell_size = int(min(board_width / WIDTH, board_height / HEIGHT))īoard_origin = (BOARD_PADDING, BOARD_PADDING)įlag = ("assets/images/flag.png")įlag = (flag, (cell_size, cell_size)) OPEN_SANS = "assets/fonts/OpenSans-Regular.ttf" This is the runner.py that launches the program: import pygameįrom minesweeper import Minesweeper, MinesweeperAI If cell not in (self.moves_made and self.mines): Returns a move to make on the Minesweeper board. This function may use the knowledge in self.mines, self.safesĪnd self.moves_made, but should not modify any of those values. The move must be known to be safe, and not already a move Returns a safe cell to choose on the Minesweeper board. # Update count if cell in bounds and is mine

simple minesweeper python code simple minesweeper python code

# Loop over all cells within one row and columnįor i in range(cell - 1, cell + 2):įor j in range(cell - 1, cell + 2): Within one row and column of a given cell, # Initialize an empty field with no mines # Set initial width, height, and number of mines I'm relatively new in Python Class Objects, but in general, i think the logic i used is valid.ĭef _init_(self, height=4, width=4, mines=2): My code runs for a 2-3 turns and then crashes.I can't find the error but i'm guessing it must be on the add_knowledge function I've tried implementing an AI minesweeper for the past few days.







Simple minesweeper python code