Prolog Help

Conor026

Member
May 20, 2003
118
0
0
I`m doing a project in college for PROLOG.
The basic idea of it is a fire escape program that gets you out of a building that has rooms on fire.

You have labels for the rooms and corridors and you tell the program which rooms or corridors are
on fire and the program will list an escape route using the labels. e.g. Room4 is the room,label for the rooom is G4.
I have all the donkey work done of listing the what is a room and corridor e.g. room(G4) , corridor(F1).
and the relationships between them e.g. RC(G4,F1)

What i need help on the the intelligent code (The recursive step). If some can recommend a site to look up or could give me the code it would be great.

Notes: 1.base case you are beside the Exit
2.recursive step to find the exit
3.Make sure to go into rooms you`ve never been in,Otherwise you be in a infinite loop e.g. A to B to A to B....
4.Make sure room going into isn`t on member list of rooms already entered or on fire


Here is the project abstract:

Prolog Project

Notes:
· Each floor is comprised of rooms (grey areas) and corridors (white areas).
· Rooms and corridors are connected together (e.g. a room?s door opens onto a corridor).
· There are 3 exits: the front door, the back door, and the fire escape (which can only be used from the first floor).
· A flight of stairs connects the 2 floors.

The Problem
Given that a number (one or more) of rooms and corridors are on fire, work out a safe escape route(s) from a given room. The escape route cannot use any room or corridor that is on fire for the escape.

The main predicate will take the following form:
· fire-escape(<area-to-escape-from>, <list-of-areas-on-fire>,<escape-route>).

Given an area to escape from (room or corridor) and a list of areas (rooms and corridors) on fire, the predicate will work out any safe escape routes that exist.

Examples:
?- fire-escape(f4,[cf2,f3],R).

R = [f4,f5,cf5,stairs,cg3,cg4,cg5,cg8,front-door,exit]
More (y/n)? y

R = [f4,f5,cf5,stairs,cg3,cg1,cg2,g9,back-door,exit]
More (y/n)? y

R = [f4,f5,cf5,cf4,cf3,cf7,fire-escape,exit]
More (y/n)? y

no

A predicate quick-escape/3 which only returns the shortest route (fewest elements in escape list) is also required. Example:
?- quick-escape(g3,[cg8],R).

R = [g3,cg4,cg3,cg1,cg2,g9,back-door,exit]
More (y/n)? y

no