I've been trying to make a terminal-based Minesweeper clone in Python. Here is my function for generating the minefield:
BOMB = '#' # The symbol for the bomb
def generateField(width, height, bombs):
field = [[0] * height] * width # Make the empty array grid
for bomb in range(0, bombs):
x, y = random.randint(0, width - 1), random.randint(0, height - 1)
print((x, y)) # For debugging, remove later
field[x][y] = BOMB #
return field
It's not complete yet. However, when I called generateField(12, 12, 12) for a board of width 12, height 12, width 12 bombs, it gives me something like this:
[
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#'],
[0, '#', 0, 0, 0, '#', '#', '#', 0, '#', '#', '#']
]
Could someone give me an explanation for what is happening, or what is wrong?