CS 451 Programming Paradigms
LISP Assignment Two: Search Problems
Knight's Path and Water Jugs

Both of the parts of this assignment use the search architecture that we have been discussing in class. You are welcome to use ideas in the code that we have already looked at to help you develop your code. You must come up with representation choices and additional functions, such as those used to generate new states in the search graph for the particular problems.

Part One: Water Jugs Problem


This problem is described on p. 423 of your course notes, problem #10. You need to devise the state-generation rules that your breadth-first, depth-first, and possibly best-first (if you choose to do it) search engines can use. You should show traces of the solution produced by each of your search engines using the rules for the water jugs problem. The problem states that there are two jugs, one capable of holding 3 and the other capable of holding 5 gallons of water. Jugs can be filled, emptied, and dumped one into the other either until the poured-into jug is full or until the poured-out-of jug is empty. The task is to devise a sequence of actions that will produce 4 gallons of water in the large jug. Note: it is possible to write this problem (and thus the rules for its solution) to work for any values where the 3,5, and 4 occur. Doing this is one thing you could do to earn better than the base grade of B.

Write lisp functions that solve the water jugs problem (by giving a set of moves in order that will produce the required amount). You should do this once using depth-first search and then again using breadth-first search. Turn in ON PAPER in class your code and sample runs for both kinds of search.

Part Two: Knight's Path Problem


In the game of chess the knight piece makes moves by going either one square in a non-diagonal direction and then two squares in an orthogonal direction or by going two squares in a non-diagonal direction and then one square in an orthogonal direction.

For example, a knight can move up one and over two, over one and up two, down two and over one, etc. This creates a "radius" of eight positions that a knight can reach in one move from any given position (minus any that would take the knight off the board).

Your assignment is to write functions in Lisp that take a board location for the START position of a knight and a board location for the GOAL position of a knight and generate a path of knight moves that that takes the knight from the START to the GOAL. The board positions should just be pairs of integers (two-element lists) from 1 to 8, representing the row and column in the chess board.

You will want to use the search techniques discussed in class and in the lecture notes. You should turn in two different sets of functions--one that finds a knight's path from START to GOAL positions using depth first search and one that finds a knight's path from START to GOAL positions using breadth first search. Make sure you also turn in test runs of both sets of functions.

Notice that you are in fact returning a PATH and not just a yes/no answer concerning the existence of a path.

You should turn in your code and the results of the tests on PAPER. Your code must work to get points for the assignment--what you do beyond that (thoroughness in coding and testing, presentation) determines how good your grade will be.


[ Back to CS451: The LISP Segment ]