Homework 2

Implementing Search to solve a "Challenge"


Due: Friday, September 21st, 11:00 AM


Introduction

You guys have been around long enough and probably remember having classes over in Wright hall.  I am a big fan of the Wright Challenge, and I love reading (and solving) the wacky puzzles that the brilliant Dr. E posts around the building several times each semester.  Almost every semester I would find a puzzle that was a great AI kind of problem - in particular, ones that can be solved with the construction and application of intelligent searching agents. 

This homework assignment was blatantly stolen from Puzzle 2. made available during the Spring of 2004()??

Puzzle 2  involves a 3x3 pendent of jewels.  Each of the 9 jewels is either a diamond, a ruby, or an emerald.  These jewels can be changed by casting a spell at a particular jewel.  This spell will change a diamond into a ruby, a ruby into an emerald, or an emerald into a diamond. Unfortunately, the spell also modifies the jewels touching the particular jewels both horizontally and vertically! 

Thus, if you started with the following pendant:

DRE
RED
EDR

and cast a spell at the center emerald, you would end up with the following pendant

DEE
EDR
ERR

The "goal" of this puzzle is that given a starting pendent, find the shortest sequence of spells that will turn the pendent into one containing 9 of the same jewel. 

BEAUTIFUL!  A straightforward search problem where at each node in the search you have 9 possible next moves (9 possible spell locations).  The challenge is picking which of the 5 strategies we might use.  We will talk about this in class, but I think there are two which make the most sense. 

Requirements

For this homework you should write a Java program (other languages POSSIBLE upon pre-approval) that fits the following requirements:

 

Hints from past experience with this assignment...

1)  Remember what happens when you "copy" a referential data type in Java... you only get a copy of the reference, not a copy of the object.  This means that if you have a node that you want to copy several times and modify to create the children nodes, you need to be careful what you do to copy the node.  Students have a habit of saying something like:

    Node parent = new Node();
    Node child1 = parent;
    Node child2 = parent;
    Node child3 = parent;
    child1.modifyOneWay();
    child2.modifyAnotherWay();
    child3.modifyYETAnotherWay();

This just gives you FOUR variables all of which point to the same single instance.  Students end up forgetting this and then being surprised when child1, child2, and child3 are identical and TOTALLY screwed up (in essence, they just cast 3 different spells on the same single object.

You will need to write code which produces a true, second copy of whatever data structure you use in your tree.

Remember that if you are using Java referential types, they often have methods to provide these copies.  For example, if you want ot make a copy of an array you can use System.arraycopy...

    int[] board = new int[14];
    //some code to put actual values in the board
    int[] boardcopy = new int[14];
    System.arraycopy(board,0,boardcopy,0,board.length);

 

2)  When it gets to be time to test your code, start with simple problems.  For example,

DED
EEE
DED

can EASILY be turned into a pendent of all diamonds by casting the spell on the center emerald.  Shortest solution is ONE move.  If your code can't solve this, than you have a significant problem.  Similarly, your code should detect that

EEE
EEE
EEE

is already a solution and requires no moves at all.

 

Submitting Your Work

Prior to the deadline, use the homework submission system (http://math-cs.cns.uni.edu/~schafer/submit/which_course.cgi) to upload any files you have produced. 

You should bundle all of your files into a zip file.

In addition to online copies, please submit hard copies of this assignment at the start of class on the day it is due.