Created
February 3, 2020 01:46
-
-
Save ffariajr/017f6aa2744f85ae39eadc6ccf0e7c03 to your computer and use it in GitHub Desktop.
Discord Minesweeper Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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