<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ricardo De Castro</title>
    <description>The latest articles on DEV Community by Ricardo De Castro (@ricardo_decastro_0ccd6b8).</description>
    <link>https://dev.to/ricardo_decastro_0ccd6b8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4266780%2Fcdf22f47-f07e-4655-a166-6286ec583727.png</url>
      <title>DEV Community: Ricardo De Castro</title>
      <link>https://dev.to/ricardo_decastro_0ccd6b8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ricardo_decastro_0ccd6b8"/>
    <language>en</language>
    <item>
      <title>Deterministic Browser Solvers in Pure JS: 0.21ms No-Guess Minesweeper and 0.515ms MRV Crowns</title>
      <dc:creator>Ricardo De Castro</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:36:46 +0000</pubDate>
      <link>https://dev.to/ricardo_decastro_0ccd6b8/deterministic-browser-solvers-in-pure-js-021ms-no-guess-minesweeper-and-0515ms-mrv-crowns-17m5</link>
      <guid>https://dev.to/ricardo_decastro_0ccd6b8/deterministic-browser-solvers-in-pure-js-021ms-no-guess-minesweeper-and-0515ms-mrv-crowns-17m5</guid>
      <description>&lt;p&gt;Most browser puzzle games rely on naive random generation and hope the player either gets lucky or restarts when a board breaks. While building &lt;strong&gt;&lt;a href="https://gamersbunker.com/games/tactical-minesweeper/" rel="noopener noreferrer"&gt;Vault Sweeper&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://gamersbunker.com/games/reflex-logic-lab/" rel="noopener noreferrer"&gt;Reflex &amp;amp; Daily Logic Lab&lt;/a&gt;&lt;/strong&gt; in pure Canvas 2D and vanilla JavaScript, we wanted every board to guarantee a strict mathematical property before Frame 1 renders—without blocking the main thread.&lt;/p&gt;

&lt;p&gt;Here is how our two client-side constraint solvers work in production (&lt;code&gt;mphys.js&lt;/code&gt; and &lt;code&gt;lphys.js&lt;/code&gt;), plus the empirical verification numbers published in our &lt;a href="https://gamersbunker.com/data/" rel="noopener noreferrer"&gt;public benchmarks dataset&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Zero-Coin-Flip Minesweeper (&lt;code&gt;mphys.js&lt;/code&gt;): 0.21 ms Deductive Verifier
&lt;/h2&gt;

&lt;p&gt;Traditional minesweeper breaks flow when a 10-minute run ends on an unavoidable 50/50 corner guess. In &lt;strong&gt;Vault Sweeper&lt;/strong&gt; (a 5-floor expedition scaling from &lt;code&gt;7x7&lt;/code&gt; / &lt;code&gt;8&lt;/code&gt; mines up to &lt;code&gt;10x10&lt;/code&gt; / &lt;code&gt;22&lt;/code&gt; mines with 3 shields and 8 tactical relics), a hidden mine guess shouldn't end a tactical run.&lt;/p&gt;

&lt;p&gt;Instead of backtracking over all possible mine configurations on every candidate board, &lt;code&gt;mphys.js&lt;/code&gt; simulates a &lt;strong&gt;human deductive solver&lt;/strong&gt; starting from the guaranteed safe opening zone:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single-cell propagation:&lt;/strong&gt; For any revealed clue cell whose remaining unflagged mines equal &lt;code&gt;0&lt;/code&gt;, mark all hidden neighbors safe. If the remaining unflagged mines equal the count of hidden neighbors, mark all of them as deduced mines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coupled subset difference subtraction:&lt;/strong&gt; For pairs of neighboring revealed frontier cells &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;, compare their hidden neighbor sets &lt;code&gt;H(A)&lt;/code&gt; and &lt;code&gt;H(B)&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;H(A)&lt;/code&gt; is a subset of &lt;code&gt;H(B)&lt;/code&gt;, then &lt;code&gt;H(B) \ H(A)&lt;/code&gt; must contain &lt;code&gt;rem(B) - rem(A)&lt;/code&gt; mines.&lt;/li&gt;
&lt;li&gt;Even when neither is a strict subset, if &lt;code&gt;maxMines(H(A) \ H(B)) == rem(A) - rem(B)&lt;/code&gt; (accounting for exact overlap bounds), &lt;code&gt;H(A) \ H(B)&lt;/code&gt; are all mines and &lt;code&gt;H(B) \ H(A)&lt;/code&gt; are all safe. This handles classic &lt;code&gt;1-2-1&lt;/code&gt; and &lt;code&gt;1-2-2-1&lt;/code&gt; border patterns deterministically without branching.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global remaining mine count check:&lt;/strong&gt; When all remaining frontier constraints leave zero mines or match the exact count of remaining unrevealed cells, resolve the final cells cleanly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If any unrevealed safe cell remains unreachable after constraint propagation saturates, the generator discards the layout and retries. Across &lt;strong&gt;1,000 test boards (&lt;code&gt;7x7&lt;/code&gt; to &lt;code&gt;10x10&lt;/code&gt;)&lt;/strong&gt;, &lt;strong&gt;1,000/1,000&lt;/strong&gt; verify deterministically with an average generation + verification time of &lt;strong&gt;~0.21 ms per board&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once verified, we keep frame times flat at 60 FPS by pre-baking offscreen tile sprites and avoiding runtime blur or shadow filters—even when Floor 3 introduces riveted 2-tap armored tiles.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Exact Uniqueness for Crowns (&lt;code&gt;lphys.js&lt;/code&gt;): 0.515 ms MRV Backtracker
&lt;/h2&gt;

&lt;p&gt;The second solver powers &lt;strong&gt;Daily &amp;amp; Classic Crowns&lt;/strong&gt; (&lt;code&gt;5x5&lt;/code&gt;, UTC-seeded &lt;code&gt;6x6&lt;/code&gt;, and &lt;code&gt;7x7&lt;/code&gt;) inside &lt;strong&gt;&lt;a href="https://gamersbunker.com/games/reflex-logic-lab/" rel="noopener noreferrer"&gt;Reflex &amp;amp; Daily Logic Lab&lt;/a&gt;&lt;/strong&gt;: place exactly 1 crown per row, 1 per column, and 1 per color/pattern region such that no two crowns touch orthogonally or diagonally.&lt;/p&gt;

&lt;p&gt;A subtle trap when generating region puzzles is assuming that growing contiguous regions around a valid planted N-Queens solution produces a unique puzzle. In practice, random Voronoi/flood-fill partitions frequently admit &lt;strong&gt;2 or more valid solutions&lt;/strong&gt;, making logical deduction ambiguous.&lt;/p&gt;

&lt;p&gt;So before accepting any generated board, &lt;code&gt;lphys.js&lt;/code&gt; runs an exact backtracking uniqueness check with &lt;strong&gt;Minimum Remaining Values (MRV)&lt;/strong&gt; variable ordering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pre-filter constraints:&lt;/strong&gt; Every row and region must hold candidates compatible with non-adjacent placement (no touching in an 8-neighborhood).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MRV branching:&lt;/strong&gt; At each step, pick the unassigned row (or region) with the fewest valid candidate columns, place a crown, forward-prune row, column, region, and &lt;code&gt;3x3&lt;/code&gt; diagonal-adjacent candidates, and recurse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Early abort at &lt;code&gt;count &amp;gt;= 2&lt;/code&gt;:&lt;/strong&gt; Since we only care whether the solution is unique (&lt;code&gt;count === 1&lt;/code&gt;), the solver immediately terminates the moment a second valid solution is found.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Across &lt;strong&gt;1,000 test grids (&lt;code&gt;5x5&lt;/code&gt; to &lt;code&gt;7x7&lt;/code&gt;)&lt;/strong&gt;, &lt;strong&gt;1,000/1,000&lt;/strong&gt; pass uniqueness in &lt;strong&gt;0.515 ms average&lt;/strong&gt;. We also pair every color region with subtle geometric micro-patterns so boards stay readable without relying solely on hue discrimination.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Anti-Cheat Bounds &amp;amp; Calibrated Human Priors
&lt;/h2&gt;

&lt;p&gt;When &lt;strong&gt;Reflex &amp;amp; Daily Logic Lab&lt;/strong&gt; switches from Crowns to visual-motor benchmarks—the &lt;strong&gt;5-pod F1 reaction test&lt;/strong&gt; (&lt;code&gt;0.75 s&lt;/code&gt; pod cadence, &lt;code&gt;1.40-4.20 s&lt;/code&gt; randomized blackout hold, &lt;code&gt;+120 ms&lt;/code&gt; false-start penalty) and the &lt;strong&gt;20.0 s Aim Grid&lt;/strong&gt; (&lt;code&gt;2&lt;/code&gt; simultaneous active targets, up to &lt;code&gt;x3.0&lt;/code&gt; combo multiplier at &lt;code&gt;+0.2/hit&lt;/code&gt;)—submitted scores are checked against a lightweight Python + SQLite WAL service (&lt;code&gt;gb-lab-api&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs request a &lt;strong&gt;single-use HMAC ticket&lt;/strong&gt; on start.&lt;/li&gt;
&lt;li&gt;Impossible client payloads (&lt;code&gt;&amp;lt;110 ms&lt;/code&gt; average F1 reaction or &lt;code&gt;&amp;lt;16.0 s&lt;/code&gt; Aim elapsed time) are rejected server-side before updating percentiles.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode / Module&lt;/th&gt;
&lt;th&gt;Key Constants&lt;/th&gt;
&lt;th&gt;Human Prior Median&lt;/th&gt;
&lt;th&gt;Guarantee&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Vault Sweeper&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5 floors (&lt;code&gt;7x7&lt;/code&gt;–&lt;code&gt;10x10&lt;/code&gt;, &lt;code&gt;8–22&lt;/code&gt; mines), 3 shields, 8 relics&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;45 s&lt;/code&gt; Floor 1 par&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1,000/1,000&lt;/code&gt; No-Guess (&lt;code&gt;0.21 ms&lt;/code&gt; avg)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;F1 Reaction Test&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5 pods, &lt;code&gt;1.40–4.20 s&lt;/code&gt; blackout, &lt;code&gt;110–2000 ms&lt;/code&gt; bounds&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;285 ms&lt;/code&gt; avg&lt;/td&gt;
&lt;td&gt;Single-use HMAC + &lt;code&gt;&amp;gt;= 1.2 s&lt;/code&gt; guard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Aim Grid 20s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;20.0 s&lt;/code&gt; arena, 2 live targets, &lt;code&gt;x3.0&lt;/code&gt; combo cap&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2,200 pts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Single-use HMAC + &lt;code&gt;&amp;gt;= 16.0 s&lt;/code&gt; guard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Daily Crowns&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;UTC &lt;code&gt;6x6&lt;/code&gt; (&lt;code&gt;daysSince1970&lt;/code&gt;), Classic &lt;code&gt;5x5–7x7&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;42.0 s&lt;/code&gt; clear&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1,000/1,000&lt;/code&gt; MRV unique (&lt;code&gt;0.515 ms&lt;/code&gt; avg)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All methodology notes and CSV tables are open on &lt;a href="https://gamersbunker.com/data/" rel="noopener noreferrer"&gt;gamersbunker.com/data/&lt;/a&gt;. Feel free to inspect the solvers live in the browser—zero downloads, zero sign-ups—and let me know if you want a deeper breakdown of how we handle subset conflict pruning or pre-baked Canvas sprite caches.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>algorithms</category>
      <category>gamedev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
