Assignment Two: Epilog
You've finally reached the Dungeon Lord's lair, only to find
he's not quite as medieval as you thought. Your initial reading
on his location has proven to be false. In addition, you have
discovered that the only way to banish him to the plane of
Eternal Torment from whence he came, you must use the Magical
Sword of MacGuffin. You're pretty sure it's somewhere in the
maze, but you're traveling blind. Can you lead your team to
find their way through the maze and defeat the Dungeon Lord?
Changes to the maze:
- You will not be given the X, Y coordinates of the final room containing
the Dungeon Lord. Instead, it will be encoded with a "dl".
- Walls will be encoded as "w", and walkable floor will be marked with an
"f".
- The location of the sword will be marked with an "s". You can walk
through that room.
- There are also doors with keys. There is only one key, that opens all
the doors. Once you have found the key, you can walk through all doors as
if they were walkable floor. You can walk through the room with the
key. The key and sword will not be in the same room; each room has a
single letter designation.
- The location of the key is marked with a "k".
- Doors that can be opened with a key are marked with a "d".
Example:
[[ f, f, f, f, f],
[ w, w, k, w, f],
[dl, w, w, w, f],
[ f, w, s, w, f],
[ f, f, f, d, f]]
You must find a path through the maze:
- Find the key, if neccesary, before going through any doors;
- Retrieve the sword;
- And find the way to the Dungeon Lord's room.
- When you enter the room with the Dungeon Lord with the sword, you complete
the mission and return the path you took.
- You may not need to go through any door before reaching the Dungeon Lord with
the sword.
Prolog Code
-
As before, your code should contain a predicate with the following name
and signature:
mazepath(X, Y, Maze, Path)
- X,Y
- These are the X and Y of the room you begin the
maze in. It is guaranteed to be walkable.
- Maze
- This is a 2d array of atoms, defined above, that represents the
maze. You can travel to any walkable orthogonally-adjacent room. The maze
coordinate system starts at (0, 0) in the top left corner.
- Path
- This should be a list of either 2-tuples or lists
(i.e. in the form [(x1, y1), (x2, y2), ...]
or [[x1, y1], [x2, y2], ...]). Each element of
the path is the coordinates of a room traversed. It
should also contain the starting room and the ending
room.
-
You should return the Path, not just print it out.
-
You do not need to find the length of the path.
To Turn In:
- On Paper:
- Description of what you did to implement the changes;
- Learning Outcome.
- Via Email:
- Well documented Prolog code.
Hints:
-
Check the forum for handy code snippets and library functions.
-
Remember to document your code well. Prolog is not particularly readable by
itself.
-
For good style, especially for documenting predicate signatures, see