I'm working on a simple minesweeper game in python, and am trying to create a function that inserts mines into an empty board.
Note that the board is in the form of a list of lists, as so:
[[col, col, col...],[col,col,col...],[...],[...]...]
my function looks like this:
def insert_mines(NUM_MINES):
for mine in range(NUM_MINES):
rand_row = randint(0, NUM_ROWS - 1)
rand_col = randint(0, NUM_COLS - 1)
if BOARD[rand_row][rand_col] == 'O':
BOARD[rand_row][rand_col] = 'X'
NUM_MINES = NUM_MINES - 1
else:
BOARD[rand_row][rand_col] = 'X'
print NUM_MINES
when I run it with num_mines = 96, it never prints zero, which is what it should print if all the mines have been inserted.
What could be the cause of this?
note that 'X' represents a mine and 'O' is just a board space with no mine.