anonymine_engine.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:anonymine 作者: oskar-skog 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号