Skip to content

Instantly share code, notes, and snippets.

@willianrocha
Last active June 8, 2018 19:47
Show Gist options
  • Save willianrocha/4e65b023c704906236ceda407c6b29ab to your computer and use it in GitHub Desktop.
Save willianrocha/4e65b023c704906236ceda407c6b29ab to your computer and use it in GitHub Desktop.
import random
class square(object):
def __init__(self):
self.is_bomb = random.choice([True, False])
self.n_bomb = 0
def __str__(self):
if self.is_bomb:
return 'x'
else:
return str(self.n_bomb)
def look_neighborhood(board):
n = 10
m = 10
for x in range(n):
for y in range(m):
bombs = 0
for i in range(x-1,x+2):
for j in range(y-1, y+2):
if i >= 0 and i < n and j >= 0 and j < m:
if board[i][j].is_bomb: bombs += 1
board[x][y].n_bomb = bombs
def print_board(board):
for x in board:
for y in x:
print(y, end=' ')
print()
def init_board():
board = [[square() for m in range(10)] for n in range(10)]
return board
board = init_board()
look_neighborhood(board)
print_board(board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment