0

I have this labyrinth:

Labyrinth image

and I need to make a navigation mechanism (on SWI-Prolog) through the rooms of the labyrinth. The prerequisites of the navigation mechanism are the following:

  1. The navigation has to support the start from ANY room and the end to ANY room as well.
  2. The user has to enter the starting room and the ending room.
  3. Check if the starting room is simultaneously the ending room and if it is,print the appropriate message and terminate the program.
  4. To find the accessible room of the current room.
  5. Check if the candidate room for selection has been reused again and if it has,then this room is rejected and it continues with other room.
  6. When a route is found from the starting room to the finish room, then this route is printed.
  7. The mechanism is repeated until all possible routes are found.
  8. The printing of possible paths should be of the form: a-->b-->j-->i-->h-->g-->k-->d-->e-->I am in room e.
  9. The program will start with the go/2 predicate with the two parameters of the starting and the ending room.

How can I make the Knowledge Base on this program??

I started with this:

room(a).
room(b).
room(c).
room(d).
room(e).
room(f).
room(g).
room(h).
room(i).
room(j).
room(k).

I am not sure but I think I need to use the following helping predicates:

member(X,[X|L]):- !.
member(X,[Y|L]):- member(X,L).

writelist([]).
writelist([L|Lt]):- write(L),write('-->'),writelist(Lt).
false
  • 10,264
  • 13
  • 101
  • 209
Alex_Z
  • 1
  • 3
  • That is a bad, non-relational version of member/2 (which is built-in). Here's good code: https://www.swi-prolog.org/pldoc/doc/_SWI_/library/lists.pl?show=src#member/2 – brebs May 23 '23 at 17:02
  • Some clues: https://stackoverflow.com/search?q=%5Bprolog%5D+labyrinth – brebs May 23 '23 at 17:06
  • I think I need to set the accessible rooms for each room...but how I will implement the route from room to room?? (example from A to E) – Alex_Z May 23 '23 at 19:04
  • 1
    [`path(connected,Path,A,B)`](https://stackoverflow.com/q/30328433/772868) with a fitting definition of `connected/2`. – false May 24 '23 at 05:01
  • I need some more help i'm very new to Prolog.I tried with this recursive rule:: path(connected,[start|T],start,end):-path(connected,T,start,end). but it returned false.Do I have to define the connected rooms both ways?? (example connected(a,b) AND connected(b,a) ) – Alex_Z May 24 '23 at 14:04
  • You need to take the **entire code** from the link. – false May 24 '23 at 14:48

0 Answers0