Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For purely random, you start with an empty grid and a "candidate" list (also empty).</p> <p>Place the first tile in the centre of the grid, then add each adjacent tile to the one you just placed into the "candidate" list. Then, each turn, choose a random entry in the "candidate" list and place a tile there. Look at each adjancent grid location next to where you just placed the tile, and for each one that is also empty, put it on the "candidate" list for the next time around (if not already there).</p> <p>To avoid creating holes in your tile grid, increase the probability of selecting a grid location based on the number of adjacent tiles that are already filled (so if only one adjacent tile is already filled, it has low probably. If they're all filled, it'll have a very high probability).</p> <p>In pseudo code:</p> <pre><code>grid = new array[width,height]; candidates = new list(); function place_tile(x,y) { // place the tile at the given location grid[x,y] = 1; // loop through all the adjacent grid locations around the one // we just placed for(y1 = y - 1; y1 &lt; y + 1; y1++) { for(x1 = x - 1; x1 &lt; x + 1; x1++) { // if this location doesn't have a tile and isn't already in // the candidate list, add it if (grid[x,y] != 1 &amp;&amp; !candidates.contains(x1,y1)) { candidates.add(x1,y1); } } } } // place the first tile in the centre place_tile(width/2, height/2); while (!finished) { // choose a random tile from the candidate list int index = rand(0, candidates.length - 1); // place a tile at that location (remove the entry from // the candidate list) x, y = candidates[index]; candidates.remove(index); place_tile(x, y); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload