This question is dirty, I don't need a working solution, I need some psuedo code.
How can I solve this maze? This is a homework question. I have to go from green to red. On each fork, I need to “spawn a thread” and go in that direction. I need to figure out how to get to red, but I'm not sure how to avoid the paths that I have already made (completion with any path is okay, I'm just not allowed to walk in circles).
Here is an example of my problem, I start to move down and see the plug, so one goes to the right and one goes down (or this thread can take it, it does not matter). Now let's ignore the rest of the forks and say that the one that goes straight hits the wall, drops, hits the wall and goes left, then rises. The other thread goes down, hits the wall, and then goes the full way. The lower path was taken twice, starting from different sides.
How to mark this way? Do I need a lock? Is this the only way? Is there a carefree solution?
The implementation is wise. I thought I might have a maze of something like this. I don't like the solution because there is a lot of locking (assuming I block before each read and write of the hasTraverse member). I do not need to use the MazeSegment class below, I just wrote it as an example. I am allowed to build a maze, but I want to. I thought maybe the solution does not require connecting paths and it bothers me. Perhaps I could break the map, instead of using the format below (which is easy to read and understand). But if I knew how to separate it, I would know how to do it, so the problem.
How to walk effectively in this maze?
, , - , , . , , .
class MazeSegment
{
enum Direction { up, down, left, right}
List<Pair<Direction, MazeSegment*>> ConnectingPaths;
int line_length;
bool haveTraverse;
}
MazeSegment root;
class MazeSegment
{
enum Direction { up, down, left, right}
List<Pair<Direction, MazeSegment*>> ConnectingPaths;
bool haveTraverse;
}
void WalkPath(MazeSegment segment)
{
if(segment.haveTraverse) return;
segment.haveTraverse = true;
foreach(var v in segment)
{
if(v.haveTraverse == false)
spawn_thread(v);
}
}
WalkPath(root);
