You are to write a simple program in Prolog to find a path through a maze. Your input will consist of facts of the form
pway(a, b, 10).indicating that there is a passageway from intersection
bof length 10 meters. You are to write a rule
solve(X, Y, P, N) :- ...that will find a path
N(if one exists) from intersection
Y. The intent is that the user will invoke
solveas a query, specifying
Yas constants and
Here is a concrete example. Suppose the database contains the following rules:
pway(a, b, 10). pway(b, c, 15). pway(d, c, 5). pway(d, b, 10).If the user types
solve(a, d, P, N)the Prolog interpreter might respond with
P = [a, b, c, d] N = 30If at this point the user types a semicolon, the interpreter should respond with
P = [a, b, d] N = 20One more semicolon should produce
noThere are no more paths.
b, you can also walk 10 meters from
band back to
As extra credit, you could output paths in increasing order of
length. In the example above, for example,
[a, b, d] should
show up before
[a, b, c, d].
Note: I recommend that you worry about ordering only after implementing and
debugging the original version of your program.
fail, or database ordering) for the basic assignment. In fact, you shouldn't even need
not, though you'll probably want
\=(numeric ``not equal''). A solution for the assignment consisting of only seven rules does exist!
reconsultprimitives. Put your program in one file. Put each sample maze in another. Read the program into the interpreter using
consult. Read the first maze the same way. If you change your program, read it again using
reconsult(this will over-ride the earlier definitions of your rules). If you want to try a different maze, read it using
reconsult(this will over-ride all previous
ispredicate to force arithmetic computation.
Be sure to follow the applicable parts of the General Guidelines for All Assignments.
As in previous assignments, you will submit your work using the
script. Make sure to include your test cases/mazes.
Back to the course home page