private MapBuilder GetBasicMapBuilder() { var builder = new MapBuilder(30, 15); builder.AddPath(1, 1, Directions.East, 5); builder.AddPath(3, 1, Directions.South, 5); builder.AddPath(3, 5, Directions.East, 5); return(builder); }
public MapViewModel(ILogger <MapViewModel> logger) { _logger = logger; // create a simple map for use with a start and end var builder = new MapBuilder(30, 15); builder.AddPath(1, 1, Directions.East, 5); builder.AddPath(3, 1, Directions.South, 5); builder.AddPath(3, 5, Directions.East, 5); builder.AddStart(2, 1); builder.AddEnd(5, 5); Map = builder.Build(); }
public MapBuilder Generate(int width, int height, Algorithms algorithm = Algorithms.AldousBroderAvoidLinks) { var maze = GetMaze(width, height, algorithm); Maze = maze; var builder = new MapBuilder(width, height); // find all horizontal paths for (var y = 0; y < height; y++) { var onPath = false; var pathStart = 0; for (var x = 0; x < width; x++) { var cell = maze[y, x]; if (cell.EasternBoundary || !cell.Links.Contains(cell.East)) { // so no path to the right if (onPath) { // we've reached the end onPath = false; Debug.WriteLine($"Easterly path from [{pathStart},{y}] to [{x},{y}]"); builder.AddPath(pathStart, y, Directions.East, x - pathStart + 1); } } else { if (!onPath) { onPath = true; pathStart = x; } } } } // find all vertical paths for (var x = 0; x < width; x++) { var onPath = false; var pathStart = 0; for (var y = 0; y < height; y++) { var cell = maze[y, x]; if (cell.SouthernBoundary || !cell.Links.Contains(cell.South)) { // so no path to the bottom if (onPath) { // we've reached the end onPath = false; Debug.WriteLine($"Southerly path from [{x},{pathStart}] to [{x},{y}]"); builder.AddPath(x, pathStart, Directions.South, y - pathStart + 1); } } else { if (!onPath) { onPath = true; pathStart = y; } } } } builder.AddStart(maze.LongestPath.First().Col, maze.LongestPath.First().Row); builder.AddEnd(maze.LongestPath.Last().Col, maze.LongestPath.Last().Row); return(builder); }