Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Supporting Code Details 

Running the Application

Test data available

Programming Tips

Mutating a value outside of an anonymous inner class:

The quandry is that a variable that is declared outside of an anoymous inner class, e.g. visitor implementation, that is accessed by an by the anonymous inner class must be defined as final (Thanks Sun! Argh...).   There a classic "hack" to get around this:

...

Wiki Markup
{{final ICell\[\] aCell = new ICell\[\]\{ new Cell()\}; }}

Wiki Markup
 An anonymous inner class can thus access these variables by using the array syntax:   {{x\[0\]}} and {{aCell\[0\]}}

You may find that in order to keep track of several properties as you loop through cells and cell sets, that you may need to create multiple one-element array values.

Controlling a loop from inside of an anonymous inner class

 Unfortunately, you cannot break or continue a loop while inside of an anonymous inner class that the loop completely encloses (i.e. the anonymous inner class is defined in the body of the loop).    There are two ways to accomplish this though:

  1. Return a boolean or other primitive value from the anonymous inner class (which is probably a visitor being accepted).   Based on the returned value, break or continue with the loop.   Note that returning a value to which you delegate to, e.g. IUtilHostAB/C/D, will not work because you will just find yourself inside another anonymous inner class.
  2. Use the one-element array trick described above.   Set its value from inside the anonymous inner class.  After the anonymous inner class returns, break or continue the loop based on that value. 

How to make copies of a board when you don't know which cell is the one you want to guess from

The problem is that if you lose the reference to the cell that you chose to test its values, you can never find that cell again without doing the whole search over again.   This is because a cell doesn't know where it is in the board (it never needs to know!).

The trick is to keep references to everything you need and to make copies at just the right time.  So here's what to do:

  1. Keep references to BOTH the original board and the cell you found.
  2. Get an array copy of the values in the cell.  Cell.getValueArray() makes a copy.  You can use this array to loop over.
  3. In your loop:
    1. Clear the contents of the cell.  This will mutate your original board!
    2. Set the value of the cell to the desired test value.
    3. Make a copy of the orignal board.  
    4. Solve the copy of the board -- you will need to set the current board to the copy.   Don't mess up the original board!
    5. Repeat with the next test value or quit if you find a solution.

 Requirements

Your assignment is to implement:

...