Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Looks like the snake game might work. Track a direction vector, and turn right 90 degrees every time you hit a side or a populated square. The tail keeps extending indefinitely :)</p> <p>Edit : Snakey v0.1 in C#. Works for non square grids too ;)</p> <pre><code>using System; using System.Text; namespace ConsoleApplication1 { class Program { public enum Direction { Up, Down, Left, Right } static void Main(string[] args) { int[,] maze; Direction currentDirection = Direction.Right; bool totallyStuck = false; bool complete = false; int currentX = 0; int currentY = 0; int boundX = 4; int boundY = 5; int currentNumber = 1; int stuckCounter = 0; bool placeNumber = true; maze = new int[boundY, boundX]; while ((!totallyStuck) &amp;&amp; (!complete)) { if (placeNumber) { maze[currentY, currentX] = currentNumber; currentNumber++; stuckCounter = 0; } switch (currentDirection) { case Direction.Right: // Noted short Circuit Bool Evan if ((currentX + 1 &lt; boundX) &amp;&amp; (maze[currentY, currentX + 1] == 0)) { placeNumber = true; currentX++; stuckCounter = 0; } else { placeNumber = false; stuckCounter++; } break; case Direction.Left: if ((currentX - 1 &gt;= 0) &amp;&amp; (maze[currentY, currentX - 1] == 0)) { placeNumber = true; currentX--; stuckCounter = 0; } else { placeNumber = false; stuckCounter++; } break; case Direction.Down: if ((currentY + 1 &lt; boundY) &amp;&amp; (maze[currentY + 1, currentX] == 0)) { placeNumber = true; currentY++; stuckCounter = 0; } else { placeNumber = false; stuckCounter++; } break; case Direction.Up: if ((currentY - 1 &gt;= 0) &amp;&amp; (maze[currentY - 1, currentX] == 0)) { placeNumber = true; currentY--; stuckCounter = 0; } else { placeNumber = false; stuckCounter++; } break; } // Is Snake stuck? If so, rotate 90 degs right if (stuckCounter == 1) { switch (currentDirection) { case Direction.Right: currentDirection = Direction.Down; break; case Direction.Down: currentDirection = Direction.Left; break; case Direction.Left: currentDirection = Direction.Up; break; case Direction.Up: currentDirection = Direction.Right; break; } } else if (stuckCounter &gt; 1) { totallyStuck = true; } } // Draw final maze for (int y = 0; y &lt; boundY; y++) { for (int x = 0; x &lt; boundX; x++) { Console.Write(string.Format("{0:00} ",maze[y, x])); } Console.Write("\r\n"); } } } } </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