## ICS 361 --Artificial Intelligence Programming

### State Space Representations and Search

#### Assignment #2

This assignment is worth 100 points.

The State Space Problem Representation is described in lecture notes as well as Norvig & Russell or Luger AI texts.

Create state space representations of the following problems:

1. (20 pt) Farmer, Wolf, Goat and Cabbage (ref Alg Ch 13 pp. 177-)
2. (20 pt) Water Jugs (ref Alg Ch 13 p. 183)
3. (40 pt) 8 puzzle (ref AI text: Norvig & Russell or Luger)
Implement iterative (not recursive) versions of both breadth-first and depth-first search strategies, using *open* and *closed* lists (Ref Luger SS p. 99-). Your search code must be independent of the application problem. I.e. you should use the same search code for all 3 problems.
The *start* state, *goal* state and allowable *moves* will be in global variables and passed as parameters to the search methods. You may wish to start with the code in Luger's Algorithms book, Ch. 13.
During all your searches, print the first node on *open* during each iteration (the node that is expanded). When the goal is reached, print the length of the *open* and *closed* lists as well as the entire solution path. You may use a depth limit of 20 on the 8 puzzle problem.

FWGC and Water Jugs puzzles have fixed beginning and ending states. The 8-puzzle, however can start in any configuration, and has two distinct goal states.
To solve an 8 puzzle problem, you must be able to easily specify the start and goal states. Global variables are suggested. Values may be set in several ways such as reading them in from a file, loading a file of lisp definitions, or entering them from the console. For your 8-puzzle transcript, use the following start and goal states.

```Start:        Goal:
-------      -------
|2|8|3|      |1|2|3|
-------      -------
|1|6|4|      |8| |4|
-------      -------
|7| |5|      |7|6|5|
-------      -------```
Create meaningful comments in ALL files with the assignment information and a description of each of the variables and functions used in the file.
Load your code in to Lisp and save the output of solving each of the puzzles using dribble, transcript or saving a buffer in emacs. [UHUnixName]2OUT.txt (add A, B, C if more than one file). Depth-, breadth-, and best-first searches applied to the Monkeys and Coconuts river crossing problem is here. States are represented by a 3-tuple with the number of Ms then number of Cs on the start side and the 3rd part of the state shows the side where the boat is currently located. Both Ms and Cs can paddle the boat. The maximum capacity of the boat is 2 (at least one M or C must be in the boat to paddle). The goal is to move all Ms and Cs to the opposite side while making sure that Ms do not outnumber Cs on either side of the river. If that should happen, the Cs would be eaten.
Follow the example output for the Monkeys and Coconuts problem.
• (20 p) Report: For each puzzle,
• describe a successful strategy for solving the puzzle. (English)
• How many different states are possible in the search space?
• How many states are possible in the 15 puzzle (4 by 4 sliding tiles)?
• (10 p) Extra credit: Create and generate transcripts for 2 more examples of the 8 puzzle. At least one of the examples must end with the alternative end state
```Goal:
-------
|1|2|3|
-------
|4|5|6|
-------
|7|8| |
-------```

Note: You will extend the code from this assignment to implement the best-first search strategy in assignment #3.

### Turn in the following on Laulima:

Several plain text files containing your commented code, your report, and output (script) files for all problems.

(c) N. E. Reed, 2004-2016