Maze solving: Difference between revisions
Content deleted Content added
Updated D entry |
|||
Line 667:
This entry reads a maze generated by http://rosettacode.org/wiki/Maze_generation#D and chooses two random start-end points.
<lang d>import std.stdio, std.random, std.string, std.array, std.algorithm,
std.file, std.conv;
enum int cx = 4, cy = 2; // Cell size x and y.
Line 674:
struct V2 { int x, y; }
bool solveMaze(char[][] maze, in V2 s, in V2 end) pure nothrow @safe @nogc {
if (s == end)
return true;
foreach (immutable d; [V2(0, -cy), V2(+cx, 0), V2(0, +cy), V2(-cx, 0)])
if (maze[s.y + (d.y / 2)][s.x + (d.x / 2)] == ' ' &&
maze[s.y + d.y][s.x + d.x] == ' ') {
Line 691:
void main() {
auto maze = "maze.txt".
immutable
assert (h > 0);
immutable
immutable start = V2(cx2 + cx * uniform(0, w), cy2 + cy * uniform(0, h));
immutable end = V2(cx2 + cx * uniform(0,
maze[start.y][start.x] = pathSymbol;
|