Version date: 8-sep-94 9:25am
For each part, write the appropriate Lisp code, run it on your computer, and make a single file containing:
/afs/andrew/scs/cs/15-381/handin/useridWhere userid above is your Andrew account.
If you do not have an andrew account, please send the file by email to
dredish@cs.cmu.eduand include in the Subject line "15-381 HW1". Please do not use email if you have an Andrew account.
The homework is due by 10:30am, Thursday September 22, 1994.
Your program must print the following information:
;;; One problem space representation for the water jug problem (setq *start* '(0 0)) (defun first-jug (state) (car state)) (defun second-jug (state) (cadr state)) (defun mk-state (f s) (list f s)) (defun goalp (state) (eq (first-jug state) 2)) (defun new-states (state) (remove-null (list (fill-first state) (fill-second state) (pour-first-second state) (pour-second-first state) (empty-first state) (empty-second state)))) (defun remove-null (x) (cond ((null x) nil) ((null (car x)) (remove-null (cdr x))) ((cons (car x) (remove-null (cdr x)))))) (defun fill-first (state) (cond ((< (first-jug state) 4) (mk-state 4 (second-jug state)))))) (defun fill-second (state) (cond ((< (second-jug state) 3) (mk-state (first-jug state) 3)))) (defun pour-first-second (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop f) nil) ; Cant pour nothing ((= s 3) nil) ; Second full ((<= (+ f s) 3) ; Empty first into second (mk-state 0 (+ f s))) (t ; Fill second from first (mk-state (- (+ f s) 3) 3))))) (defun pour-second-first (state) (let ( (f (first-jug state)) (s (second-jug state))) (cond ((zerop s) nil) ; Cant pour nothing ((= f 4) nil) ; First full ((<= (+ f s) 4) ; Empty second into first (mk-state (+ f s) 0)) (t ; Fill first from second (mk-state 4 (- (+ f s) 4)))))) (defun empty-first (state) (cond ((> (first-jug state) 0) (mk-state 0 (second-jug state))))) (defun empty-second (state) (cond ((> (second-jug state) 0) (mk-state (first-jug state) 0))))
You and a friend are at the entrance to a fabulous ball room with a large party going on. Although neither of you has brought formal wear, upon entering the Foyer (and seeing a tastefully engraved sign that the main party is in the Checkered Room), you are told politely but firmly that you may not enter the main rooms without a jacket and tie, but that the establishment will loan you each ties and jackets during your visit. There is one white jacket, one white tie, one black jacket, and one black tie (four pieces of clothing altogether). The rooms are layed out as follows:
Either player may make the following moves in this game:
Items dropped in a room stay in that room, and may be picked up by the other player.
Your goal is to produce a series of moves that get one player into the checkered room where the main party is in full swing.
Using the lisp functions new-states and goalp, along with your DFS and BFS functions, solve the problem and note the solution lengths and nodes visited in each case.
Also write a best-first search routine
Use all of your search functions to transform the initial state
| | 1 | 2 | 3 | | --------+-------+-------- | | 4 | 5 | 6 | | --------+-------+-------- | | 7 | 8 | | |
into the goal state:
| | 1 | 8 | 7 | | --------+-------+-------- | | 2 | | 6 | | --------+-------+-------- | | 3 | 4 | 5 | |
For a simple heuristic, try adding the number of squares that are in the final location. Try at least one other heuristic function, and compare the path length and number of nodes searched for breadth-first search, depth-first search, and best-first with your two heuristics.
Watch the class bboard, academic.cs.15-381, for any clarifications, hints or modifications to the assignment. These will also show up on the class Web Home Page, 15-381.html