扫雷算法
我即将用 Java 设计我自己的扫雷器。 在分析真实的Windows 7扫雷游戏时,我遇到了这种情况。
未覆盖的方块(箭头所指),可能是 1 或可能没有任何数字(空的正方形)。 但在 Windows 7 扫雷中,这个方块有 1。
假设:通过分析,我发现所有的地雷总是被数字包围。
如果我遵循我的假设,那么就没有其他的了,未覆盖的正方形应该是 1。
如果我遵循这个假设,那么设计扫雷器的逻辑会更容易。 因为,
步骤1:随机分配有地雷的方格。(使二维数组中特定的(i,j)元素为-1)。
第 2 步:给每个方格编号,等于其周围的地雷数量。 (在这种情况下,假设成立)。
我的问题是,
- 如果未覆盖的方块是空方块,会出现什么问题?
- 这个假设是扫雷游戏中的规则吗?
- 我是否必须遵循假设,以使我的编码更简单 实施?
- *如果我提出了一款新的扫雷艇,其规则是反对 假设,我的新扫雷舰最终会不稳定吗?是这样,怎么办?
*->我并不是故意违反规则,我尝试删除对用户的冗余提示/键。
I am about to design my own minesweeper in Java.
And while analyzing the real windows 7 minesweeper, I came across this situation.
The uncovered square(pointed by arrow), may be 1 or mayn't have any number(an empty square).
But in windows 7 minesweeper, this square has 1.
hypothesis: And by analyzing I came to know that all the mines are always surrounded by numbers.
If I go with my hypothesis, then no other go, the uncovered square should be 1.
And designing the logic for the minesweeper will be easier, if I follow this hypothesis.
since,
step 1: Randomly assign the squares with mines.(Make the specific (i,j)element in the 2D array to be -1).
step 2: Number each square, equal to the number of mines surrounding it. (In this case, the hypothesis became true).
And my questions are,
- What wrong if the uncovered square is an empty square?
- Does that hypothesis is the rule in minesweeper?
- Does I have to follow the hypothesis, to make my coding simpler
to implement?- *If I proposed a new minesweeper with the rule against the
hypothesis, does my new minesweeper will end up in instability?Is so,how?
*->I am not intentionally breaking the rules, I try to removing redundant hint/keys to the user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,尖角的方块有一个数字——它与我的方块相邻(恰好是一个),所以它得到一个 1。空的方块只是零的简写。
Of course the pointed square has a number - it is adjacent to (exactly one) mine square so it gets a 1. The empty squares are just shorhand for zero.
这个方格不能没有编号,数字代表有多少个地雷触及该方格。未编号的方格为“0”,表示没有地雷接触。
所以是的,地雷必须始终被编号的方块包围。
The square could not be unnumbered, the numbers represent how many mines are touching that square. Unnumbered squares are "0", meaning no mines touching.
So yes, a mine must always be surrounded by numbered squares.
你看不到数字的原因是扫雷的填充算法。
它显示所有值为 0 的字段(0 显示为空)。它会显示之前显示的所有相邻字段,这些字段具有非零值。
角落中的字段没有相邻的零值字段,因此无法自动显示。
它带有 1。
如果您有一个 10x11 字段,最后一行为空,则该字段将显示值为 1。Windows
版本显示 1 的原因可能是您已经用标志标记了所有现有的地雷因此 Windows Minesweeper 会显示所有剩余字段。
The reason you don't see a number there is the fill algorithm of minesweeper.
It reveals all the fields which have a 0 value (0 is shown as empty). And it reveals all the adjacent fields to those revealed before, which have a non zero value.
The field in the corner does not have an adjacent zero value field and thus cannot be revealed automatically.
It carries a 1.
If you'd have a 10x11 field with the last row being empty, This field would be revealed with value 1.
The reason why the Windows version shows a one may be that you already marked all the existing mines with flags and so Windows Minesweeper reveals all the remaining fields.