home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / library / prolo_c / exampl53.pro < prev    next >
Text File  |  1986-10-06  |  2KB  |  64 lines

  1. /*Program 53*/
  2. /*
  3.   The program was changed a little from the
  4.   version in the manual. Fail was added to the
  5.   end of go(Here,There) rather than to
  6.   route(Room,Room,RoomList) to have a true
  7.   solution. The fail will cause backtracking to
  8.   all solutions and the added clause go(_,_)
  9.   will allways return true. Also added was
  10.   writlist that writes a list in reverse.
  11.  
  12.   Goal to enter is on page 114 of the manual.
  13. */
  14.  
  15. domains
  16.     room  =  symbol
  17.     roomlist = room*
  18.  
  19. predicates
  20.     gallery(room,room)      /* There is a gallery between two rooms */
  21.     neighborroom(room,room) /* Necessary because it does not matter which
  22.                             direction we go along a gallery */
  23.     avoid(roomlist)
  24.     go(room,room)
  25.     route(room,room,roomlist) /* This is the route to be followed. Roomlist
  26.                               consists of a list of rooms already visited. */
  27.     member(room,roomlist)
  28.  
  29. clauses
  30.     gallery(entry,monsters).
  31.     gallery(entry,fountain).
  32.     gallery(exit,fountain).
  33.     gallery(food,gold_treasure).
  34.     gallery(fountain,hell).
  35.     gallery(fountain,food).
  36.     gallery(fountain,mermaid).
  37.     gallery(fountain,robbers).
  38.     gallery(mermaid,exit).
  39.     gallery(monsters,gold_treasure).
  40.     gallery(mermaid,gold_treasure).
  41.     gallery(robbers,gold_treasure).
  42.  
  43.     neighborroom(X,Y) if gallery(X,Y).
  44.     neighborroom(X,Y) if gallery(Y,X).
  45.  
  46.     avoid([monsters,robbers]).
  47.  
  48.     go(Here,There) if route(Here,There,[Here]),fail.
  49.     go(_,_).
  50.  
  51.     route(Room,Room,VisitedRooms) if
  52.         member(gold_treasure,VisitedRooms) and
  53.         write(VisitedRooms) and nl.
  54.     route(Room,Way_out,VisitedRooms) if
  55.         neighborroom(Room,Nextroom) and
  56.         avoid(DangerousRooms) and
  57.         not(member(NextRoom,DangerousRooms)) and
  58.         not(member(NextRoom,VisitedRooms)) and
  59.         route(NextRoom,Way_out,[NextRoom|VisitedRooms]).
  60.  
  61.     member(X,[X|_]).
  62.     member(X,[_|H]) if member (X,H).
  63.  
  64.