SOULRiDER

November 18th, 2007, 04:44 AM

The other day during class, we had to use a Backtracking algorithm to traverse a maze and find the path from the entrance to the exit (or vice-versa) that makes the less turns.

Last night i wrote a solution using Dijkstra's algorithm instead of using a backtracking technique. Here is the source code, i hope its clear for everyone to understand.

To try out the program just call it as you normally would and then give the different rows as arguments like this:

For a maze that looks like

111111

11x001

1101x1

call the program this way:

./Laberintos.py 111111 11x001 1101x1 (please note, a 1 means a wall, 0 a free space and x mark entrances/exits. The program is intended to work on a rectangular amze with just 2 x;s, i dont know how it may react in other conditions :P)

Here it goes, enjoy!

Last night i wrote a solution using Dijkstra's algorithm instead of using a backtracking technique. Here is the source code, i hope its clear for everyone to understand.

To try out the program just call it as you normally would and then give the different rows as arguments like this:

For a maze that looks like

111111

11x001

1101x1

call the program this way:

./Laberintos.py 111111 11x001 1101x1 (please note, a 1 means a wall, 0 a free space and x mark entrances/exits. The program is intended to work on a rectangular amze with just 2 x;s, i dont know how it may react in other conditions :P)

Here it goes, enjoy!