Pseudoprogrammer wrote:
I'm assuming the maze has an entrance and an exit which are on the edges of the screen.
Indeed, I got that now. Smile Mufin, what progress?
Ok, well, I have some code now, and it isn't pretty, or yet functional, but I think I've made enough progress to post it.

As of now, the theoretical process is that it will go from each intersection, then go from each possible exit from that point, until it hits a dead end or another intersection. If it hit a dead end, it's supposed to reverse it's trail, then use the same "path following" code (pi/7 or pi/14 as Ans then recalling the program) however with an added parameter (pi/14) that has it delete each cell as it leaves it, then redisplays that cell as empty. After that, it returns to searching for more exits from the first intersection.

If from the first intersection, it finds another intersection, then it'll begin to search from each of that intersection's exits. If it finds the first intersection from that exit, then it will compare the distances it recorded for both the times it went down the paths between the intersections, then delete the longer path.

Yes I realize that this system is flawed: going from intersection A to B, using path 1, then reusing path 1 to go from intersection B to A, would in theory have the program delete path 1, essentially having the program delete most all paths that exist. However, since for some reason it doesn't delete any paths at all, this can't happen. I'm going to prevent this soon by having the program lay "bread crumbs" using a second matrix the same size as the first. Then with that, it will turn the current position it's at from 0 to 1, so it knows where it has been, then prevent itself from going where it has been before.

Anyways, that's all the code I have so far. Here's a pastebin. I was using Merth's TokenIDE and using tabs, so here's your heads up.

PseudoProgrammer, I did notice a problem with your little program, as it only gets rid of dead ends, as Kerm has pointed out, and decided to show you a more visual example of how that can be both useful, and also not so useful.

Before, I go on, I want to be sure you know I think it is a great little method, and have intentions to probably use it in the end product of my program, but it isn't a maze solver by itself.

Here's my given maze as is pictured by the calculator. With this maze, I made it so the entrance and exits that lead outside the maze, for added assurance it won't delete those squares.

I'd say it's a fair sized, simple maze, that unfortunately your solver would have trouble solving.

Here is the end result after running it through your solver.


Now, there are pro's and con's with this, I find. The bad thing is that by itself, it would be impossible to solve anything with any sort of loop, which happens quite often in mazes. The good thing, is that it can easily and quickly look over the entire maze, making it a good tool to be used with the proper other tools.

Of course with your permission, I was hoping to use your code you provided, to make my solver faster, or at least use an easier to implement method for tracking and eliminating dead ends. My plan was that when it finds one intersection and two intersection loops, it will turn on one pixel, so it fakes being two dead ends, so your code will eliminate the unnecessary paths.

I'm not sure if my code would be faster properly working without your code, or with your code, but I find your code would be a good, easy way to get rid of dead ends, until I get my code working properly without, then I can compare.

Now, I'm going to head back to work on trying to figure out what's wrong with my code as is at the moment.
My code was kind of designed as a joke actually, and it's horribly inefficient. But as to the loops within mazes, my code assumes the mazes are what's known as perfect mazes, where there is only one solution (no loops). Here is code (that I also have still not tested, just thinking it up off hand) that should be significantly quicker. You can change the values of the For() loops depending on the size of the maze, but it will function perfectly on full screen regardless. Note that if you do change the values you also need to adjust the values of the pixel tests and whatnot in the second half of the code (the 94s and whatnot).


Code:
For(A,1,61
For(B,1,93
If 2<(pxltest(A,B+1)+pxltest(A,B-1)+pxltest(A+1,B)+pxltest(A-1,B)
pxlon(A,B)
If 2<(pxltest(A,95-B)+pxltest(A,93-B)+pxltest(A+1,94-B)+pxltest(A-1,94-B)
pxlon(A,94-B)
End
End


EDIT: Look into Ant Colony Optimization.
Yeah, I did something like that already, except I added another double nested for loop using opposite directions, then nested the whole thing in a Repeat, so it'll stop the search when goes through a full cycle without modifying any pixels.

And sure, I'll look into that, thanks for the tip.
A minor point: I've actually seen very few mazes where a loop is included; maybe that's just me. With the simplified maze after Pseudo's solver, though, if you found all more-than-two-path intersections (ie, intersections), you could trace each way from each intersection, figure out the duplicate paths, keep only the shortest, and then juts string them together into your solution.
The MineCraft server I frequent uses mazes as a prerequisite for actually "joining the server" (being granted builder permissions) and loops are very often used to give the impression that the maze is larger than it really is. I've found mazes designed for a top-down view of it don't really have many loops, because loops are fairly easy to spot. However inside the maze, they're significantly harder to detect, unless you know what you're doing. Nonetheless, I'd still like it to be completely able to solve any and all mazes, with or without loops, so some code for detecting and eliminating loops will be needed.

Also Kerm, haha yes, I'm already working on doing that. That was what I meant by "one intersection and two intersection loops." I meant loops that will go straight back to where you last turned, or "loops" that are more literally edges that go to and from the same points.

If I can't get this loop detection/elimination part of the code working soon, then I'm going to work on it later. I'm excited to try and implement these shortest path algorithms, and see them go.
Out of curiosity, in the Minecraft example, how do you prevent users from just griefing the maze by constructing walls or destroying pieces of it?
Kerm: Admins and what have you of servers can make certain areas of the server unchangeable.
Pseudoprogrammer wrote:
Kerm: Admins and what have you of servers can make certain areas of the server unchangeable.
That makes perfect sense, that's more or less what I was assuming. So, shall we return to our regularly-scheduled maze discussion?
Well, I found out that the reason my method wasn't deleting dead end paths, was because of the While loop that was running the "path following" method I made. So instead of worrying about it being a single program, for now I've made it a four program, set, although I'm not sure I need the fourth.

The new main program is prgmMAZE, and it uses it's methods prgmMAZE1 for following paths, and recording their distance, where they came from, where they ended, and what exactly is the reason they ended their path following (dead end or a new intersection).

prgmMAZE2 is the path deleting method. It will go to a new cell down the path, delete the old, then redisplay the old as an empty block, and repeat. After all this, it calls prgmMAZE3, which is the one I'm not sure I'm going to need, as this is the only time as of yet that it is called.

prgmMAZE3 makes sure that a given cell in the maze (given using coordinates E,F) will match with it's surroundings, given it has a surrounding (edge of the maze), for when the path deleting method deletes paths, it deletes it's footprints, not tidy up where it is now. Without it, it would lead the program into dead cells of value 0.

Anyways, I also realized that without an intersection "check" sort of code, it always uses the same given intersection coordinates. I added a few lines so that it now checks to be sure a coordinate used, is still an intersection before assuming it is. If it isn't, then it takes those coordinates out of the list. Because of this, I had to start working on given coordinates for source and destination, because otherwise (using my given maze) it would run the quite likely chance that it would delete the cells that are the source and destination, which would be unacceptable, imho at least.

I'm currently working on getting it so it won't have to worry about paths that lead out of the maze boundaries for certain situations, having it use designated source and destination coordinates, prevent it from ever deleting source or destination cells, and a few other things.

And lastly, here's the current code as detoken-ized by TokenIDE:

Code:
prgmMAZE
[[7,10,10,10,14,10,10,14,8][5,2,14,10,9,6,12,3,12][7,12,5,6,12,5,3,10,9][5,5,3,9,5,3,10,12,4][5,7,10,10,11,14,10,9,5][5,5,6,14,10,11,14,10,9][5,5,5,1,6,12,3,10,12][3,9,7,12,5,3,10,8,5][2,10,9,3,11,10,10,10,13->[A]
dim([A]->L1
Ans->dim([B]
0->dim(L2
{1,1,9,9->L3
ClrDraw
AxesOff
GridOff
For(A,1,L1(1
For(B,1,L1(2
If max([A](A,B)={7,11,13,14
augment(L2,{A,B->L2
For(C,1,3
For(D,1,3
Pxl-On(3A-C,3B-D
End
End
If [A](A,B
Pxl-Off(3A-2,3B-2
For(C,3,0,~1
If int(2fPart(.5[A](A,B)/2^C
Pxl-Off(3A-2-not(C)+(C=2),3B-2-(C=3)+(C=1
End
End
End
Repeat W
1->W
For(A,1,dim(L2)-1,2
If 2<sum(int(2fPart(.5[A](L2(A),L2(A+1))/{1,2,4,8
Then
For(B,3,0,~1
L2(A->C
Ans-not(B)+(B=2->E
L2(A+1->D
Ans-(B=3)+(B=1->F
If int(2fPart(.5[A](C,D)/2^B
Then
prgmMAZE1
If max([A](E,F)={1,2,4,8
Then
0->W
2E-C->C
2F-D->D
prgmMAZE2
Else
If E=L2(A) and F=L2(A+1
Then
0->W
E->G
C->E
G->C
F->G
D->F
G->D
prgmMAZE2
Else
E->Z
F->Y
C->V
D->U
J->X
0->W
For(M,3,0,~1
Z->C
Ans-not(M)+(M=2->E
Y->D
Ans-(M=3)+(M=1->F
If int(2fPart(.5[A](C,D)/2^M
Then
prgmMAZE1
If E=Z and F=Y
Then
If J=X
X+2randInt(0,1)-1->X
If J>X
Then
0->W
2C-E->E
2D-F->F
prgmMAZE2
Else
0->W
V->C
2Ans-Z->E
U->D
2Ans-Y->F
prgmMAZE2
Pause
End
End
End
End
End
End
End
End
Else
If not(sum(A={1,dim(L2)-1
seq(L2(B+2(B>A)),B,1,dim(L2)-2->L2
End
End
End

------------------------------

prgmMAZE1
0->J
While not(max([A](E,F)={1,2,4,7,8,11,13,14,15
[A](E,F->H
E->G
2E-C-max(H={3,9})+max(H={6,12->E
G->C
F->G
2F-D-max(H={9,12})+max(H={3,6->F
G->D
End

----------------------------

prgmMAZE2
Repeat max([A](E,F)={1,2,4,7,8,11,13,14,15
[A](E,F->H
E->G
2E-C-max(H={3,9})+max(H={6,12->E
G->C
F->G
2F-D-max(H={9,12})+max(H={3,6->F
G->D
0->[A](C,D
For(K,1,3
For(L,1,3
Pxl-On(3C-K,3D-L
End
End
End
prgmMAZE3

-----------------------

prgmMAZE3
For(V,0,3
{E-not(V)+(V=2),F-(V=3)+(V=1
If Ans(1)(Ans(1)<=L1(1))Ans(2)(Ans(2)<=L1(2
Then
If int(2fPart(.5[A](E,F)/2^V)) and not(int(2fPart(.5[A](Ans(1),Ans(2))/2^(V+2(V<2)-2(V>1
Then
[A](E,F)-2^V->[A](E,F
Pxl-On(3E-2-not(V)+(V=2),3F-2-(V=3)+(V=1
End
End
End


May edit this post later today/tomorrow, I'm posting this before starting my day's work on it, so things may change by the time I decide to hit the sack.
Out of boredom, and while trying to figure out some errors I'm running into (for some reason, it tries to navigate through dead cells, then gets an invalid dim error with the current maze) I made some code that used something between Pseudo's code, and between mine.

It finds a dead end, then follows the dead end to an intersection, so I think it's much more efficient.

In my experience, it only needs to do one look over before it has eliminated all the paths it can, so this code only does one check over the whole maze:

Code:

0->Xmin
1->ΔX
-62->Ymin
1->ΔY
Input
For(A,1,-Y
For(B,1,X
If pxl-Test(A,B)(2<pxl-Test(A+1,B)+pxl-Test(A-1,B)+pxl-Test(A,B+1)+pxl-Test(A,B-1
Then
A->C
C->D
Repeat 2>=pxl-Test(A+1,B)+pxl-Test(A-1,B)+pxl-Test(A,B+1)+pxl-Test(A,B-1
pxl-On(C,D
C->E
C+pxl-Test(C+1,D)-pxl-Test(C-1,D->C
D+pxl-Test(E,D+1)-pxl-Test(E,D-1->D
End
End
End
End


Just in case you're wondering, C needs to be stored to E before it's modified, otherwise in some cases (going around corners coming from either above or below, to either side) it will move twice in one iteration of the path following code.

After realizing what caused the error that made me add that, I had to slap myself, because this is at least the fourth time I've run into this sort of problem with path following code. XD

Tomorrow I'm spending the whole day babysitting, so if I get a free moment or two (I'm bringing a few movies, and their parents said they'd give us a pass so they can go to some jungle gym thing nearby, so I'll get some time there), I'll be spending it working on my maze program.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement