Starting from:

$25

CSE307 - Principles of Programming Languages - Homework Assignment 06 - Solved

Prolog-ing Your Torture: Programming in Prolog using XSB


 

1. Indiana Jones in a temple of doom (a different one):

 

Indiana Jones has become trapped in an antechamber of a lost Mayan temple in the Yucatan.  The spiked walls are closing in.  There is a lever along one wall which will open a hole in the ceiling.  There is a crate in a corner.  If Dr. Jones pulls the lever, moves the crate to the center of the room, climbs on top of the crate, lashes his whip onto a projection on the roof, and then climbs through the hole, then he can barely escape with his life.

 

The task here is to logically deduce the sequence of steps that Indiana Jones must take to escape from the room.  You will specify the problem as a logic programming in XSB Prolog.  A query to the program escape(X) should return successfully, and the sequence of steps required to escape should be assigned to the variable X (there should only be a single solution).

 

The following predicates will be useful for encoding the problem:

 

1.                  state(J, C, H, L, P, S) is a Prolog predicate that describes the current state of the room: X is the location of Indian Jones, C is the location of the crate, H is the location of the hole, L is the location of the lever, P is the state of the lever (up for hole closed, down for hole open), and S identifies the action that produced the current state of the room.

 

2.                  Let S be the current state with the Indiana Jones in location X.  In this state the Dr. Jones can walk from X to position Y and the action is captured by the predicate walk(X, Y, S).

 

3.                  Let S be the current state with Indiana Jones located in position X, which is the same position as the lever.  In this state, Dr. Jones can pull the level from the up position to the down position to open the hole in the ceiling.  The action producing this state is pull(S), and the state of the lever will change from up to down.

 

4.                  Let S be the current state with Indiana Jones in location X, which is the same location as the crate.  Dr. Jones can push the crate to the position of the hole in the center of the room at location Y.  The action is captured by the predicate push(X, Y, S).  Note: Dr. Jones does not move with the crate.  The push action changes the location of the crate, but the location of Dr. Jones remains the same.

 

5.                  Let S be the current state with Indiana Jones in position X, which is the same position as the crate and the hole.  In this state Dr. Jones can climb on the crate.  The predicate that captures this action is climb(S).

 

6.                  Let S be the current state with Indiana Jones on top of the crate after climbing.  In this state Dr. Jones can use his whip to lash onto a roof projection through the hole.  The predicate that captures this action is whiplash(S).

 

7.                  Let S be the current state with Indiana Jones having lashed onto a roof project with his whip.  In this state, Dr. Jones can climb the whip and escape the deathtrap room.  The predicate that captures this action is escape(S).

 

Assume that in the starting state, i, Indiana Jones is at position a, the lever is at position l, and its state is up, the crate is at position c, and the hole is at position h.  This state can be expressed with the following fact.

 state(a, c, h, l, up, i).

 

Your program will consist of this fact and a set of rules.  When we query for escape(X), the initial fact and the rules should enable the Prolog to infer that the escape fact is true, and assign the steps taken by Indiana Jones to escape to X

 

More products