Question
I apologize for posting this multiple times. My instructor wants in in recursive and I am stumped. Thanks namespace cis237assignment2 { class Program { public
I apologize for posting this multiple times. My instructor wants in in recursive and I am stumped.
Thanks
namespace cis237assignment2 { class Program {
public static void Main()
{
}
public void Main(string[] args)
{
///
}
public class Maze {
/// const int X_START = 1; const int Y_START = 1;
/// char[,] maze1 =
{ { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }, { '#', 'S', '.', '.', '#', '.', '.', '.', '.', '.', '.', '#' }, { '#', '.', '#', '.', '#', '.', '#', '#', '#', '#', '.', '#' }, { '#', '#', '#', '.', '#', '.', '.', '.', '.', '#', '.', '#' }, { '#', '.', '.', '.', '.', '#', '#', '#', '.', '#', '.', '.' }, { '#', '#', '#', '#', '.', '#', '.', '#', '.', '#', '.', '#' }, { '#', '.', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' }, { '#', '#', '.', '#', '.', '#', '.', '#', '.', '#', '.', '#' }, { '#', '.', '.', '.', '.', '.', '.', '.', '.', '#', '.', '#' }, { '#', '#', '#', '#', '#', '#', '.', '#', '#', '#', '.', '#' }, { '#', '.', '.', '.', '.', '.', '.', '#', '.', '.', '.', '#' }, { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' } };
public int counter { get; set; }
// Get the start location (x,y) and try to solve the maze public virtual void solve(int x, int y) { if ([x, y]) { maze1[x, y] = 'S'; int position = index + 1; } }
// Backtracking method public virtual bool step(int x, int y) {
counter++;
//System.out.println(this.toString());
///
///
maze1[x, y] = '*'; bool result;
// Try to go Right result = step(x, y + 1); if (result) { return true; }
// Try to go Up result = step(x - 1, y); if (result) { return true; }
// Try to go Left result = step(x, y - 1); if (result) { return true; }
// Try to go Down result = step(x + 1, y); if (result) { return true; }
maze1[x, y] = ' ';
// Go back return false; // Get the start location (x,y) and try to solve the maze //public void solve(int x, int y) { if (step(x, y))
maze1[x, y] = 'S'; } } }
// Backtracking method public bool step(int x, int y) { int counter = 0; counter++;
//System.out.println(this.toString());
///
///
maze1[x, y] = '*'; bool result;
// Try to go Right
result = step(x, y + 1); if (result) { return true; }
// Try to go Up result = Step(x - 1, y); if (result) { return true; }
// Try to go Left result = step(x, y - 1); if (result) { return true; }
// Try to go Down result = step(x + 1, y); if (result) { return true; }
///
// Unmark this location maze1[x, y] = ' ';
// Go back return false; }
private bool Step(int v, int y) { throw new NotImplementedException(); }
public override string ToString() { string output = ""; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { output += maze1[x, y] + " "; } output += " "; } return output; }
public static void main(string[] args) { Maze m = new Maze(); // Locate the exit m.Maze[1][1] = 'X';
// Start solving the maze from (8, 1) m.solve(8, 1); Console.WriteLine(m); Console.WriteLine("Total calls: " + m.counter); }
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started