def init_field(self, startpoint):
'''Place the mines and reveal the starting point.
Internal details:
It will wrap in `init_field2` in guessless mode.
It will place the mines by itself when not in guessless
mode.
'''
if self.guessless:
# Wrap in the best version.
self.init_field2(startpoint)
else:
safe = self.field.get_neighbours(startpoint) + [startpoint]
cells = list(filter(
lambda x: x not in safe,
self.field.all_cells()
))
# Choose self.n_mines randomly selected mines.
cells.sort(key=lambda x: os.urandom(1))
mines = cells[:self.n_mines]
self.field.clear()
self.field.fill(mines)
self.field.reveal(startpoint)
评论列表
文章目录