domains room = symbol roomlist = room* facts hall(room, room) avoid(roomlist) predicates nondeterm neighbor(room, room) nondeterm go(room, room) nondeterm route(room, room, roomlist) nondeterm member(room, roomlist) nondeterm printlist(roomlist) nondeterm can_leave(roomlist) clauses neighbor(X, Y) :- hall(X, Y). neighbor(X, Y) :- hall(Y, X). go(Start, Finish) :- VisitedRooms = [Start], route(Start, Finish, VisitedRooms). route(exit, exit, VisitedRooms) :- can_leave(VisitedRooms), printlist(VisitedRooms), nl, fail. route(Room, Finish, VisitedRooms) :- neighbor(Room, NextRoom), avoid(DangerousRooms), not( member(NextRoom, DangerousRooms) ), not( member(NextRoom, VisitedRooms) ), route(NextRoom, Finish, [NextRoom|VisitedRooms]). member(X, [X|_]). member(X, [_|Y]) :- member(X, Y). printlist([]). printlist([Head|Tail]) :- printlist(Tail), write(Head), write(" "). % Gives a list of the rooms that must be visited can_leave(VisitedRooms) :- member("5", VisitedRooms), member("14", VisitedRooms). goal write("Maze filename--> "), readln(FileName), consult(FileName), write("-----------------------------------------------------"), nl, go(entry, exit).