You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tait.tech/_site/2020-09-12-minesweeper.html

63 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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">&#9776;</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 didnt look quite right, and I for sure didnt quite get the whole cascading tile reveal thing.
With a bit of internet research, I found what I was looking for.
Ill 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, Im 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>