Question: 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

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!