Description
1. Develop an ‘isPermutation’ function that takes two lists as arguments and returns true if the second list is a permutation of the
first (i.e., if the two lists contain all the same elements, but may be in different orders), and false otherwise.
2. Develop an ‘isSublist’ function that takes two lists as arguments and returns true only if every 1 element of the second list
appears somewhere in the first list, with the elements appearing in the same order. As a clarifying example, isSublist ([1, 2, 3, 9,
8, 5, 6, 0, 1], [3, 8, 6, 0]) is True.
3. Download the sample code I have provided on D2L and use this code to build a text-based adventure game in Prolog. The
sample code will run a very simplistic version of such a game, with a sample run depicted included on the following page.
In addition to the following list of tasks that MUST be completed, your game will be evaluated as though it were a standalone
project. Your game should be creative, entertaining, and should demonstrate your competence with the Prolog programming
language.
1. Add a command that will reset the game, restoring the player to the starting position and items to their original locations.
2. Create a drop/1 command that will drop an item from the inventory into the room in which the player is currently located.
3. Create a description for each room and item and, when the player chooses look, provide that description instead of just
providing the room name.
4. The sample code I have provided will sometimes (after an action is taken) fail to return the user to the command prompt
(because Prolog is waiting to see if you will press ; to request a different solution – in my sample run above I pressed ;
whenever prompted). Reconfigure the program such that the user is returned to the prompt after every action. Make sure
that Prolog’s response to a valid action is not “false.”
5. Add to the look command functionality such that the contents of a room are also described. Since there may be multiple
items in a single room, look must identify every item that is located in the same room as the player, not just the first one.
This can be done with backtracking, but the player should not need to press ; to see the entire contents of the room.
6. Add (and replace, if you like) the rooms, paths, and items that I have defined with elements of your own design. You must
have at least six connected rooms and two objects that are required for certain transitions.
University of Calgary
Department of Computer Science
Introduction to Programming Paradigms (CPSC 449)
Assignment 4 of 4
This is a sample run of the game implemented in the “Starting Point for A4.pl” file that is available on D2L.
1 ?- play.
Type in your commands as queries (i.e., using standard Prolog syntax).
You are in room1
true.
2 ?- walk(n).
Nope!
true.
3 ?- walk(w).
You walked w
You are in room3
true ;
Nope!
true.
4 ?- take(keys).
You took the keys
true ;
Nope!
true.
5 ?- walk(e).
You walked e
You are in room1
true ;
Nope!
true.
6 ?- walk(n).
You walked n
You are in room2
true ;
Nope!
true.
4. Write a Prolog program that will solve the following logic puzzle by modeling it as a finite state machine:
While traveling through Moria, Gandalf, Aragorn, Gilmi, and Legolas approach a great chasm. There is a bridge
going across but it can only hold two people at a time. Because of poor planning, they only have a single torch
between the four of them, and since the mines are particularly dark, the torch must be carried whenever someone
tries to cross the bridge. Legolas is the fastest and can cross the bridge in only one minute, and Aragorn is in pretty
good shape too so he can cross it in three minutes. Gimli, being a dwarf, has stubby legs, so it will take him five
minutes, and since Gandalf is over 2000 years old, it will take him eight minutes to cross the bridge. Whenever two of
the company cross the bridge together, they must stick together so that they both know where they are going. This
entails that they move at the pace of the slower of the two. Is it possible for all of them to cross the bridge in 18
minutes or less? How?
Your solution to this question must answer True or False for the first question (i.e., Is it possible…?) and it must provide an
unambiguous description of the action plan for the second question (i.e., How?).