home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
prolog
/
library
/
prolo_c
/
exampl53.pro
< prev
next >
Wrap
Text File
|
1986-10-06
|
2KB
|
64 lines
/*Program 53*/
/*
The program was changed a little from the
version in the manual. Fail was added to the
end of go(Here,There) rather than to
route(Room,Room,RoomList) to have a true
solution. The fail will cause backtracking to
all solutions and the added clause go(_,_)
will allways return true. Also added was
writlist that writes a list in reverse.
Goal to enter is on page 114 of the manual.
*/
domains
room = symbol
roomlist = room*
predicates
gallery(room,room) /* There is a gallery between two rooms */
neighborroom(room,room) /* Necessary because it does not matter which
direction we go along a gallery */
avoid(roomlist)
go(room,room)
route(room,room,roomlist) /* This is the route to be followed. Roomlist
consists of a list of rooms already visited. */
member(room,roomlist)
clauses
gallery(entry,monsters).
gallery(entry,fountain).
gallery(exit,fountain).
gallery(food,gold_treasure).
gallery(fountain,hell).
gallery(fountain,food).
gallery(fountain,mermaid).
gallery(fountain,robbers).
gallery(mermaid,exit).
gallery(monsters,gold_treasure).
gallery(mermaid,gold_treasure).
gallery(robbers,gold_treasure).
neighborroom(X,Y) if gallery(X,Y).
neighborroom(X,Y) if gallery(Y,X).
avoid([monsters,robbers]).
go(Here,There) if route(Here,There,[Here]),fail.
go(_,_).
route(Room,Room,VisitedRooms) if
member(gold_treasure,VisitedRooms) and
write(VisitedRooms) and nl.
route(Room,Way_out,VisitedRooms) if
neighborroom(Room,Nextroom) and
avoid(DangerousRooms) and
not(member(NextRoom,DangerousRooms)) and
not(member(NextRoom,VisitedRooms)) and
route(NextRoom,Way_out,[NextRoom|VisitedRooms]).
member(X,[X|_]).
member(X,[_|H]) if member (X,H).