Homework 2

Email me your answers to the following two problems. For each problem, you should email me your source code (*.java files), and a screenshot of your program executing. You must also answer any questions asked.

There is a Basic Problem and an Advanced Problem. You may choose either one. Choose the advanced problem only if you are a good programmer. You do not need to do both problems. You may collaborate with one other student, but you must let me know if you are doing this.

Basic Problem: Solving the 15 Puzzle

The 15 puzzle is a larger version of the 8 Puzzle. Your assignment is to write a program to solve this puzzle.

Here is the goal state:

and here is an easy initial state (it's not far from the goal):

First, you should download the Java implementation of algorithms from Norvig and Russell's Artificial Intelligence - A Modern Approach from http://code.google.com/p/aima-java/downloads/list. If you don't have Eclipse, you should install it now. Then you can do "File-Import...-Import Existing projects into Workplace" and import the aima-java project. If the import process doesn't work, you will need to create a new project in the same folder and then you will see the classes in Eclipse. Make sure you can run the EightPuzzleDemo.

Now you need to extend the existing 8-puzzle implementation to solve the above 15-puzzle problem. Remember that documentation for the book code is here. To solve a problem with Uninformed Search using the code from the text, you need to write four classes:

  1. a class that represents the Problem state. This class is independent of the framework and does NOT need to subclass anything. In this step you need to write aima.search.fifteenpuzzle.FifteenPuzzleBoard.java. This will resemble EightPuzzleBoard.java.

  2. a subclass of aima.search.framework.GoalTest. This implements only a single function ---boolean isGoalState(Object state); The parameter state is an instance of the class you created in the first step above. In this step you will write aima.search.fifteenpuzzle.FifteenPuzzleGoalTest. This will resemble EightPuzzleGoalTest.java.

  3. a subclass of aima.search.framework.SuccessorFunction. This generates a stream of Successors where a Successor is an object that represents an (action, resultantState) pair. In this release of the code the action is a String (something like "placeQueenAt4,4" and the resultant State is an instance of the class you create in step 1 above. In this step you will write aima.search.fifteenpuzzle.FifteenPuzzleSuccessorFunction. This will resemble EightPuzzleSuccessorFunction.java.

  4. a class that runs your search. This class is independent and does not subclass anything. In this step you need to write aima.search.demos.FifteenPuzzleDemo. This will resemble EightPuzzleDemo.java.

The EightPuzzleDemo.java file is set up to run many search algorithms on the 8 Puzzle. In your own FifteenPuzzleDemo.java file, try to solve the 15-puzzle with BreadthFirstSearch, DepthFirstSearch, DepthLimitedSearch, and IterativeDeepeningSearch. (This just means you don't include the calls to the other methods.) Do all of these four uninformed search algorithms work in this case? If not, report which algorithms work and which not, and explain why some algorithms fail and why some algorithms work (just a sentence or two for each method).

Now try to solve the 15-puzzle with following initial states (this just involves editing the initialization in your FifteenPuzzleDemo.java file): Case 1: At least 59 steps needed.

Case 2: At least 38 steps needed.

Do the four uninformed search algorithms still work for the above two more difficult cases? Why or why not (a sentence or two for each method)?

Advanced Problem

Peg Solitaire is a game consisting of a playing board with 33 holes together with 32 pegs. In the picture above, the hole in the center is empty and the remaining holes contain pegs. The goal is to remove all the pieces except one, which should be in the center. A piece can be removed by jumping an adjacent piece over it into an empty hole. Jumps are permitted horizontally or vertically, but not diagonally.

Your assignment consists of two parts, plus one extra credit part:

  1. Explain (in words) why Breadth First Search and Iterative Deepening are not good methods for this problem.

  2. Program Depth First Search on this problem. You must create classes for the playing board, the successor function and the goal test, and make your classes work with the search code from the text.

  3. (Extra Credit) Design an admissible A* heuristic for this problem and test its effectiveness.