I'm trying to make a minesweeper game using lists in python. I have have this code so far:
import random as r
import sys
#dimension of board and number of bombs
width = int(sys.argv[1])
height = int(sys.argv[2])
b = int(sys.argv[3])
#creates the board
board = [[0.0] * width] * height
#places bombs
for i in range(b):
x = r.randint(0, width - 1)
y = r.randint(0, height - 1)
board.insert(x, y, 0.1)
#prints board
for i in range(len(board)):
for j in range(len(board[i]))
print(board[i][j], end=" ")
I'm trying to get the bombs to be placed at random places on the board, but insert()
only accepts 2 args. Is there any other way in which I can do this?
I have an idea to place a random bomb in row 1, then a random bomb in row 2, and so on and once it hits row n it loops back to row 1 until enough bombs have been placed, but I'm not sure if it will work (and I have no way of testing it because I have do idea how to do that either). I feel like this solution is pretty inefficient, so I'm also wondering if there's a more efficient way to do it.