Skip to content

Instantly share code, notes, and snippets.

@ffariajr
Created February 3, 2020 01:46
Show Gist options
  • Save ffariajr/017f6aa2744f85ae39eadc6ccf0e7c03 to your computer and use it in GitHub Desktop.
Save ffariajr/017f6aa2744f85ae39eadc6ccf0e7c03 to your computer and use it in GitHub Desktop.
Discord Minesweeper Generator
from random import randint
mines = 20
height = 12
width = 12
field = [[0 for x in range(width)] for y in range(height)]
numbernames = ["zero","one","two","three","four","five","six","seven","eight","bomb"]
while mines > 0:
x = randint(0,width-1)
y = randint(0,height-1)
if field[x][y] != 9:
mines -= 1
field[x][y] = 9
for xx in range(x-1,x+2):
for yy in range(y-1,y+2):
if xx >= 0 and yy >= 0 and xx < width and yy < height:
if field[xx][yy] != 9:
field[xx][yy] += 1
result = ""
for y in range(height):
for x in range(width):
result = "{0}||:{1}:||".format(result,numbernames[field[x][y]])
result = "{0}\n".format(result)
print(result[0:len(result)-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment