|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<title>Minesweeper Bomb Generation And Tile Revealing | tait.tech</title>
|
|
|
<link rel="stylesheet" href="/assets/css/style.css">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
</head>
|
|
|
<body>
|
|
|
<div id="wrapper">
|
|
|
<nav>
|
|
|
<input type="checkbox" id="menu">
|
|
|
<label for="menu">☰</label>
|
|
|
<div class="menu-content">
|
|
|
|
|
|
<a href="/" class="nav-link" >Home</a>
|
|
|
|
|
|
<a href="/tutoring/" class="nav-link" >Tutoring</a>
|
|
|
|
|
|
<a href="/blog/" class="nav-link" >Blog</a>
|
|
|
|
|
|
<a href="/links/" class="nav-link" >Links</a>
|
|
|
|
|
|
<a href="https://github.com/TTWNO/" class="nav-link" target="_blank" rel="noopener noreferrer" >Code</a>
|
|
|
|
|
|
</div>
|
|
|
</nav>
|
|
|
|
|
|
<h1>Minesweeper Bomb Generation And Tile Revealing</h1>
|
|
|
<h4 class="post-date line-under"></h4>
|
|
|
|
|
|
<div class="article">
|
|
|
<p>When I was creating a little Minesweeper game, I got confused at some points.
|
|
|
My bomb generation didn’t look quite right, and I for sure didn’t quite get the whole cascading tile reveal thing.
|
|
|
With a bit of internet research, I found what I was looking for.
|
|
|
I’ll explain it all in one place for my own and others’ purposes.</p>
|
|
|
|
|
|
<h3 id="bomb-generation">Bomb Generation</h3>
|
|
|
|
|
|
<p>When I started this project I attempted to use a random bomb generator.
|
|
|
By this I mean on each square, before it gets generated, give it a one in 15 change of being a bomb.
|
|
|
Personally, I’m not sure why this never looked right.
|
|
|
Something about the layout of the bombs did not mimic the classic Minesweeper game.</p>
|
|
|
|
|
|
<p>After looking at some open source Minesweeper examples, I found the following algorithms:</p>
|
|
|
|
|
|
<ul>
|
|
|
<li><code class="highlighter-rouge">X = R % W</code></li>
|
|
|
<li><code class="highlighter-rouge">Y = R // H</code></li>
|
|
|
</ul>
|
|
|
|
|
|
<p>Where % is a [modulo] operator</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<footer>
|
|
|
This page is mirrored on <a href="https://beta.tait.tech/2020-09-12-minesweeper.html">beta.tait.tech</a>.
|
|
|
</footer>
|
|
|
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>
|