In the course I'm currently taking, every time I've had to learn a new programming language, one of the first assignments is to create the following effect using it. This was never too hard considering the algorithm never changes, so I decided to try it in the DRoD level editor.
What this is, is a character that follows the wall to its right in order to solve the problem "
How do I get out of this maze?"
Sometimes following the right wall leads to a much longer path to the exit than pathfinding, and sometimes (if the exit is in the middle of the maze) the character will never get out of the maze.
Here is the old script to understand the algorithm easier:
Click here to view the secret text
× Imperative 1
Go to north
Label north
If ...
Move 1,0,0,0
Go to east
Else
Go to west
If End
Label east
If ...
Move 0,1,0,0
Go to south
Else
Go to north
If End
Label west
If ...
Move 0,-1,0,0
Go to north
Else
Go to south
If End
Label south
If ...
Move -1,0,0,0
Go to west
Else
Go to east
If End
Here is the new script, completely infinite loop-free:
Click here to view the secret text
× Imperative 1
Go to north1
Label north1
If ...
Move 1,0,0,0
Go to east1
Else
Go to west2
If End
Label north2
If ...
Move 1,0,0,0
Go to east1
Else
Go to west3
If End
Label north3
If ...
Move 1,0,0,0
Go to east1
Else
Go to west4
If End
Label north4
If ...
Move 1,0,0,0
Go to east1
Else
Wait 0
Go to west1
If End
Label east1
If ...
Move 0,1,0,0
Go to south1
Else
Go to north2
If End
Label east2
If ...
Move 0,1,0,0
Go to south1
Else
Go to north3
If End
Label east3
If ...
Move 0,1,0,0
Go to south1
Else
Go to north4
If End
Label east4
If ...
Move 0,1,0,0
Go to south1
Else
Wait 0
Go to north1
If End
Label west1
If ...
Move 0,-1,0,0
Go to north1
Else
Go to south2
If End
Label west2
If ...
Move 0,-1,0,0
Go to north1
Else
Go to south3
If End
Label west3
If ...
Move 0,-1,0,0
Go to north1
Else
Go to south4
If End
Label west4
If ...
Move 0,-1,0,0
Go to north1
Else
Wait 0
Go to south1
If End
Label south1
If ...
Move -1,0,0,0
Go to west1
Else
Go to east2
If End
Label south2
If ...
Move -1,0,0,0
Go to west1
Else
Go to east3
If End
Label south3
If ...
Move -1,0,0,0
Go to west1
Else
Go to east4
If End
Label south4
If ...
Move -1,0,0,0
Go to west1
Else
Wait 0
Go to east1
If End
Attached is also a hold demonstrating it. If you stick around long enough
using the old script, you'll see the script is not flawless as it is prone to infinite loop syndrome.
EDIT: Look below for the file Timos Maze level for the updated file. Shorter and easier to understand, though you need to make sure a new variable is made for each character. (These variables can be reused throughout the hold, however).
EDIT 2: New updated version uploaded.
EDIT 3: The 2nd line, Go to north1, can be changed to another "
direction1"
label depending on which wall you want the NPC to start following from the start.
[Last edited by vinheim at 10-31-2010 09:56 AM]