Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago