i need help to solve the maze path. Thanks in advance
link(a,b).
link(b,c).
link(c,d).
link(f,c).
link(b,e).
link(d,e).
link(e,f).
Write a predicate that defines a route between any two adjacent points (X and Y for example) based on the fact that there is a link between them and a recursive predicate that covers the more general case of a route between any two non-adjacent points (X and Z for example) by establishing for a fact that there is a link between X and a third point in the maze (say Y) and a route between Y and Z.
Two special rooms – one connected to “a” and called “Entry” and another one connected to “f” and called “Exit”. Add a set of facts to reflect the two new rooms. Using the predicates from task 1, write a predicate that finds all possible routes between the Entry and the Exit and creates a list of the visited rooms. Write another predicate that displays the list in the interactive console at the end of every iteration, or in other words every time the Exit is reached. Write a test plan that shows your anticipated results and the actual results. Evaluate this solution and identify any potential problems and the situations that may cause their occurrence.
The problem with this solution is looping.If I want to link(a,f) prolog says no.Is anything wrong with my predicate.
| ?- link(a,b). link(b,c). link(c,d). link(f,c). link(b,e). link(d,e). link(e,f).
route(X,Y):- link(X,Y). route(X,Y):- link(X,Z), route(Z,Y). yes
yes
yes
yes
yes
yes
yes
! ---------------------------------------- ! Error 20 : Predicate Not Defined ! Goal : route(_31102,_31104) :- link(_31102,_31104)
Aborted | ?- link(a,f). no
| ?- route(X,Y). X = a , Y = b ;
X = b , Y = c ;
X = c , Y = d ;
X = f , Y = c ;
X = b , Y = e ;
X = d , Y = e ;
X = e , Y = f ;
X = a , Y = c ;
X = a , Y = e ;
X = a , Y = d
;
X = a , Y = d
| ?- link(X,Z). X = a , Z = b
| ?- | ?- link(X,Z). X = a , Z = b ;
X = b , Z = c ;
X = c , Z = d ;
X = f , Z = c ;
X = b , Z = e ;
X = d , Z = e ;
X = e , Z = f
See this question for a definition of
closure0/3
.Or, to use your new name: