Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using Visual Studio C++ programming /*----- S o l v e ( )------ Bogus attempt to find the shortest path through the maze.

I am using Visual Studio C++ programming

/*----- S o l v e ( )------

Bogus attempt to find the shortest path through the maze. In this solve part, I am trying to convert the function to queue algorithm.

*/

bool Solve(Maze &maze, Queue &queue)

{

maze.Start.Dequeue; // The current position

// Move to the start cell.

curPos = maze.Start();

maze.Mark(curPos, 0);

// Repeatedly find a next move until the goal is reached.

while (curPos != maze.Goal())

{

// Get the current position's distance from the start position.

unsigned dist = maze.State(curPos);

// Find an open neighbor position and go there.

if (maze.State(curPos + StepEast) == Open)

queue.Enqueue(curPos += StepEast);

else if (maze.State(curPos + StepSouth) == Open)

queue.Enqueue(curPos += StepSouth);

else if (maze.State(curPos + StepWest) == Open)

queue.Enqueue(curPos += StepWest);

else if (maze.State(curPos + StepNorth) == Open)

queue.Enqueue(curPos += StepNorth);

else if (!queue.Empty()) {

curPos = queue.Dequeue();

}

else

// No place to go; give up.

return false;

// Mark the open neighbor position one more than the current position.

maze.Mark(curPos, dist + 1);

}

// Found a solution.

return true;

}

/*----- R e t r a c e ( ) -----

I am trying to make solve and RetracePath function work in the queue algorithm

PURPOSE

Mark the path from the goal to the start cell.

INPUT PARAMETERS

maze -- the maze object to be marked

*/

void Retrace(Maze &maze, Queue &queue)

// Fill in the missing code

{

do { //Loops through the queue from head to bottom and marks each position as a path

maze.Mark.Head(),maze.Mark.tail();

queue.Dequeue();

} while (!queue.Empty());

}

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

More Books

Students also viewed these Databases questions

Question

5. Explain the supervisors role in safety.

Answered: 1 week ago

Question

4. Who should be invited to attend?

Answered: 1 week ago