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)

{

///

/// Starting Coordinates.

}

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());

///

/// Accept case - we found the exit * if (maze1[x, y] == 'X') { return true; }

///

/// Reject case - we hit a wall or our path * if (maze1[x, y] == '#' || maze1[x, y] == '*') { return false; }

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());

///

/// Accept case - we found the exit * if (maze1[x, y] == 'X') { return true; }

///

/// Reject case - we hit a wall or our path * if (maze1[x, y] == '#' || maze1[x, y] == '*') { return false; }

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; }

///

/// Deadend - this location can't be part of the solution *

// 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!