Basic Prolog Maze Runner Simple Program

You are asked 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 a to intersection b of length 10 meters.

You are to write a rule

solve(X, Y, P, N) :- ...

that will find a path P of length N (if one exists) from intersection X to intersection Y.

The intent is that the user will invoke solve as a query, specifying X and Y as constants and P and N as variables.

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)

P = [a, b, c, d]

N = 30 If at this point the user types a semicolon, the interpreter should respond with

P = [a, b, d]

N = 20

One more semicolon should produce

no

There are no more paths.

Subtleties

1. Note that passageways are bi-directional; if you can walk 10 meters from a tob, you can

also walk 10 meters from b toa.

2. Most mazes will have cycles. Your code must cope with them. There's no point in

passing through the same intersection more than once, and you certainly don't want the

interpreter to fall into an infinite regression doing so.

3. Note that the bi-directionality of passageways creates a huge number of trivial cycles:

you'll want to avoid walking from a tob and back to a again.

Hints

1. You might find the tutorials at the link below very useful.

2. You shouldn't need to use any imperative features of Prolog (the cut, fail, or

database ordering) for this work. 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!

3. You'll want to add distances. Remember that you must use the is predicate to force

arithmetic computation.

4. generating all possible solutions, sorting them, and then producing them one-by-one on

demand. Other approaches may be easier, however. You may need the use of cut and fail

for the this part of the work.

and test cases/mazes.

Skills: Prolog

( 2 reviews ) Hafizabad, Pakistan

Project ID: #19041216

6 freelancers are bidding on average \$52 for this job

ahmsak

Hello Sir, I am a computer science tutor, I teach (among others) Prolog and Advanced Algorithms. I have done many projects like this, and I'm one of the top Prolog developers, and you can check by clicking on my prof More

\$50 USD in 1 day
(104 Reviews)
6.3
cimemi

Hi, I am a software engineer experienced in Prolog (I am using SWI Prolog). I can complete your project within 3 days from awarding, properly tested and commented. Looking forward to hearing from you.

\$45 USD in 2 days
(27 Reviews)
4.7
rmendoza83

Hi i am expert on prolog, I can help you on this, you can check my lastest feedback and see the most of them are done in prolog.

\$50 USD in 2 days
(12 Reviews)
4.4
idleswell

Hello, I use Prolog programming daily in my regular employment. I will create a Prolog program to solve these mazes. I will be using SWI Prolog. A milestone payment for the full budget for your project must be de More

\$126 USD in 3 days
(2 Reviews)
3.1
kurbsky

solve(X, Y, P ,N):- solve2(X, Y, [], P, N). solve2(X, X, _, [], 0). solve2(X, Y, PP, [X|P], N):- X \= Y, pway(X, Z, N1), noinc(Z, PP), solve2(Z, Y, [X|PP], P, N2), N is N1 + N2. solve2(X, Y, PP, More

\$10 USD in 1 day
(1 Review)
1.2
ilpol

Hello! I've read your description and have several questions. 1. You say I don't need "not" statement for search, but to cut cycles I need to use member predicate with not, e.g. I will proceed if X is not member of pa More

\$30 USD in 6 days
(0 Reviews)
0.0