private void button3_Click(object sender, EventArgs e) { if (cbAlgorithm.SelectedItem != null) { var colorGrid = new ColoredGrid(10, 10); if ((string)cbAlgorithm.SelectedItem == "BinaryTree") { BinaryTree.Maze(colorGrid, (int)numericUpDown1.Value); } else if ((string)cbAlgorithm.SelectedItem == "Sidewinder") { Sidewinder.Maze(colorGrid, (int)numericUpDown1.Value); } var start = colorGrid[0, 0]; var distances = start.Distances; var(newStart, distance) = distances.Max; start = newStart; distances = start.Distances; var(end, distance2) = distances.Max; colorGrid.Distances = start.Distances; colorGrid.BackColor = pbColor.BackColor; pB.Image = colorGrid.ToPn(start, end); } }
private void GenerateMaze() { switch (mazeName) { case "Backtracking": { RecursiveBacktracking mazeGenerator = new RecursiveBacktracking(Width, Height); CellRB[,] maze = mazeGenerator.GenerateMaze(); SpawnMaze(maze); } break; case "Sidewinder": { Sidewinder mazeGenerator = new Sidewinder(Width, Height); CellSidewinder[,] maze = mazeGenerator.GenerateMaze(); SpawnMaze(maze); }; break; case "BinaryTree": { BinaryTree mazeGenerator = new BinaryTree(Width, Height); CellBT[,] maze = mazeGenerator.GenerateMaze(); SpawnMaze(maze); } break; default: Debug.Log("Unknown algorithm"); break; } }
public void FireSidewinder() { Rigidbody sidewinderClone = Instantiate(sidewinderPrefab, spawn.position, spawn.rotation) as Rigidbody; Sidewinder sidewinderScript = sidewinderClone.GetComponent <Sidewinder>(); // sidewinderClone.AddForce(spawn.forward * sidewinderScript.speed, ForceMode.VelocityChange); }
private Maze GetMaze(int width, int height, Algorithms algorithm) { switch (algorithm) { case Algorithms.AldousBroderAvoidLinks: return(AldousBroderAvoidLinks.Create(height, width)); case Algorithms.AldousBroder: return(AldousBroder.Create(height, width)); case Algorithms.AldousBroderWilson: return(AldousBroderWilson.Create(height, width)); case Algorithms.BinaryTree: return(BinaryTree.Create(height, width)); case Algorithms.Sidewinder: return(Sidewinder.Create(height, width)); case Algorithms.Wilson: return(Wilson.Create(height, width)); case Algorithms.WilsonJb: return(WilsonJb.Create(height, width)); } throw new Exception($"Cannot get maze for algorithm '{algorithm}'"); }
public void TestBinaryTreeColoredGrid() { var coloredGrid = new ColoredGrid(25, 25); Sidewinder.On(coloredGrid); coloredGrid.Distances = coloredGrid.GetCenterCell().Distances; coloredGrid.ToBitmap().Save("sidewinder-colored.png"); }
private void button4_Click(object sender, EventArgs e) { if (cbAlgorithm.SelectedItem != null) { Image img = null; var longestGrid = new DistanceGrid(10, 10); if ((string)cbAlgorithm.SelectedItem == "BinaryTree") { BinaryTree.Maze(longestGrid, (int)numericUpDown1.Value); } else if ((string)cbAlgorithm.SelectedItem == "Sidewinder") { Sidewinder.Maze(longestGrid, (int)numericUpDown1.Value); } var start = longestGrid[0, 0]; var distances = start.Distances; var(newStart, distance) = distances.Max; var newDistances = newStart.Distances; var(goal, distance2) = newDistances.Max; longestGrid.Distances = newDistances.PathTo(goal); var output = longestGrid.ToUgly(goal); TextWriter ts = new StreamWriter(@"C:\1.txt"); ts.Write(output); ts.Close(); var robot = new Robot { Location = new PointBot { X = 2 * newStart.Column + 1, Y = 2 * newStart.Row + 1 } }; var robot2 = new Robot { Location = new PointBot { X = 2 * newStart.Column + 1, Y = 2 * newStart.Row + 1 } }; var robot3 = new Robot { Location = new PointBot { X = 2 * newStart.Column + 1, Y = 2 * newStart.Row + 1 } }; var maze = Maze.Load(@"C:\1.txt"); var ai = new AI { Robot2 = robot2, Maze = maze, Robot = robot, Robot3 = robot3 }; var a = true; var b = true; var c = true; do { pictureBox1.Image = ai.ToImg(maze, robot, robot2, robot3); pictureBox1.Update(); a = ai.MakeStep(); b = ai.MakeStep2(); c = ai.MakeStep3(); Thread.Sleep(400); } while (a || b || c); } }
private static void ColorizeThetaMazes() { var grid = new ColoredPolarGrid(100); BinaryTree.Maze(grid); var start = grid[0, 0]; grid.Distances = start.Distances; var img = grid.ToImg(25); img.Save("binaryTheta.png"); grid = new ColoredPolarGrid(100); Sidewinder.Maze(grid); start = grid[0, 0]; grid.Distances = start.Distances; img = grid.ToImg(25); img.Save("sidewinderTheta.png"); grid = new ColoredPolarGrid(100); AldousBroder.Maze(grid); start = grid[0, 0]; grid.Distances = start.Distances; img = grid.ToImg(25); img.Save("aldousBroderTheta.png"); grid = new ColoredPolarGrid(100); HuntAndKill.Maze(grid); start = grid[0, 0]; grid.Distances = start.Distances; img = grid.ToImg(25); img.Save("huntAndKillTheta.png"); grid = new ColoredPolarGrid(100); RecursiveBacktracker.Maze(grid, startAt: null); start = grid[0, 0]; grid.Distances = start.Distances; img = grid.ToImg(25); img.Save("recursiveBacktrackerTheta.png"); grid = new ColoredPolarGrid(100); Wilsons.Maze(grid); start = grid[0, 0]; grid.Distances = start.Distances; img = grid.ToImg(25); img.Save("wilsonsTheta.png"); Process.Start("binaryTheta.png"); Process.Start("sidewinderTheta.png"); Process.Start("aldousBroderTheta.png"); Process.Start("huntAndKillTheta.png"); Process.Start("recursiveBacktrackerTheta.png"); Process.Start("wilsonsTheta.png"); }
private void button4_Click(object sender, EventArgs e) { Image img = null; var longestGrid = new DistanceGrid(10, 10); // BinaryTree.Maze(longestGrid); Sidewinder.Maze(longestGrid); var start = longestGrid[0, 0]; var distances = start.Distances; var(newStart, distance) = distances.Max; var newDistances = newStart.Distances; var(goal, distance2) = newDistances.Max; longestGrid.Distances = newDistances.PathTo(goal); var output = longestGrid.ToUgly(goal); TextWriter ts = new StreamWriter(@"C:\Users\nikit\Documents\LOLi_tex\1.txt"); ts.Write(output); ts.Close(); var robot = new Robot { Location = new PointBot { X = 1, Y = 1 } }; var robot2 = new Robot { Location = new PointBot { X = 1, Y = 1 } }; var robot3 = new Robot { Location = new PointBot { X = 2 * newStart.Column + 1, Y = 2 * newStart.Row + 1 } }; var maze = Maze.Load(@"C:\Users\nikit\Documents\LOLi_tex\1.txt"); var ai = new AI { Robot2 = robot2, Maze = maze, Robot = robot, Robot3 = robot3 }; var a = true; var b = true; var c = true; do { pB.Image = ai.ToImg(maze, robot, robot2, robot3); a = ai.MakeStep(); b = ai.MakeStep2(); c = ai.MakeStep3(); Thread.Sleep(1500); } while (a || b || c); //timer1.Enabled = true; }
private void button1_Click(object sender, EventArgs e) { if (cbAlgorithm.SelectedItem != null) { Image img = null; var grid = new Grid(10, 10); if ((string)cbAlgorithm.SelectedItem == "BinaryTree") { img = BinaryTree.Maze(grid, (int)numericUpDown1.Value).ToImg(); } else if ((string)cbAlgorithm.SelectedItem == "Sidewinder") { img = Sidewinder.Maze(grid, (int)numericUpDown1.Value).ToImg(); } pB.Image = img; } }
public static void Main(string[] args) { var longestGrid = new DistanceGrid(10, 10); // BinaryTree.Maze(longestGrid); Sidewinder.Maze(longestGrid); var start = longestGrid[0, 0]; var distances = start.Distances; var(newStart, distance) = distances.Max; var newDistances = newStart.Distances; var(goal, distance2) = newDistances.Max; longestGrid.Distances = newDistances.PathTo(goal); var output = longestGrid.ToUgly(goal); Console.WriteLine(output); Console.WriteLine("The exit cell(and the farthest from the start) coordinates: x=" + goal.Column + " y=" + goal.Row); TextWriter ts = new StreamWriter(@"C:\1.txt"); ts.Write(output); ts.Close(); var robot = new Robot { Location = new Point { X = newStart.Column, Y = newStart.Row } }; var robot2 = new Robot2 { Location = new Point { X = newStart.Column, Y = newStart.Row } }; var robot3 = new Robot3 { Location = new Point { X = newStart.Column, Y = newStart.Row } }; var maze = Maze.Load(@"C:\1.txt"); var ai = new AI { Robot2 = robot2, Maze = maze, Robot = robot, Robot3 = robot3 }; ai.StartBot(ai); }
public ActionResult Sidewinder() { ViewBag.Title = "Sidewinder Maze"; ViewBag.Message = "" + "<p>Below is my chapter 1 implementation of the 'Sidewinder' maze building algorithm. The algorithm follows these rules:</p>" + "<ol><li>Start in the bottom left cell. Visit each cell only once - traversing each row left to right before moving to the row above and starting again at the left most cell.</li>" + "<li>If the cell visited is the top right cell, do nothing.</li>" + "<li>If the cell visited is in the top row, carve East.</li>" + "<li>For all other cells, a true/false value is generated randomly (coin flip). Like the Binary Tree algorithm, one side of the coin carves East. " + "If the coin lands on the other side OR if the cell is in the far-right row, the algorithm will look back on the consecutive East running cells and pick one cell at random to carve North.</li></ol>" + "<p>The sidewinder maze building algorithm has less bias than the binary tree maze building algorithm. " + "There is no longer a straight, northern passage on the right edge of the maze. Both the binary tree and sidewinder algorithms do have a bias involving a straight eastern row along to top row.</p>" + "<p>This algorithm produces a 'perfect maze' - where each cell can be reached by only one route. There are no loops or intersecting paths.</p>" + "<p>Since each cell is visited only once, this maze building algorithm has a time complexity of O(n) - linear time.</p>" + "<p>The maze is dynamically generated. Refresh the page to generate a new maze.</p>"; var mazeBuilder = new Sidewinder(); var Model = mazeBuilder.BuildMaze(12, 12); return(View("Maze", Model)); }
public void TestSidewinder() { var grid = new Grid(5, 5); Sidewinder.On(grid).ToBitmap().Save("sidewinder.png"); }