IAMNEW322432

code 1: minesweeper for notsobot

Jan 12th, 2025
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. {python:
  2. import random
  3.  
  4. # Define the size of the Minesweeper board
  5. board_size = 10
  6. num_mines = 15
  7.  
  8. # Initialize the board with empty spaces
  9. board = [['⬜️' for _ in range(board_size)] for _ in range(board_size)]
  10.  
  11. # Place mines randomly on the board
  12. mines = set()
  13. while len(mines) < num_mines:
  14. x, y = random.randint(0, board_size - 1), random.randint(0, board_size - 1)
  15. mines.add((x, y))
  16.  
  17. # Define the emojis for numbers
  18. number_emojis = ['0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣']
  19.  
  20. # Calculate the number of adjacent mines for each cell
  21. for x in range(board_size):
  22. for y in range(board_size):
  23. if (x, y) in mines:
  24. board[x][y] = '💣'
  25. else:
  26. adjacent_mines = sum((i, j) in mines for i in range(x-1, x+2) for j in range(y-1, y+2) if 0 <= i < board_size and 0 <= j < board_size)
  27. board[x][y] = number_emojis[adjacent_mines]
  28.  
  29. # Function to format the board for display
  30. def format_board(board):
  31. return '\n'.join(''.join(f'||{cell}||' for cell in row) for row in board)
  32.  
  33. # Print the formatted board
  34. print(format_board(board))
  35. }
Tags: notsobot
Advertisement
Add Comment
Please, Sign In to add comment