Versions Compared

Key

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

...

The point of the MVC is to separate how a program looks to the user from what it does.   In the above UML diagram, you can see that we have two separate packages:  edu.rice.comp211.sudoku.gui and edu.rice.comp211.sukodu.model that hold the "view" and "model" components respectively.

...

Likewise, the model, GameModel communicates with the outside world via its IViewAdapter.   The model does use the code in the data and util} packages, but only to define data structures and provide utility capabilities.   All communications to the view take place through the {{IViewAdapter which is in the model pacakge.  Like the view, the model code has no idea what the implementation of IViewAdapter is.

...

  • initGUI - intializes the GUI components.
  • addCells - displays the given cells on the screen.   Used to update the view with the latest state of the board.
  • showMessage - a utility method to display the given string as a pop-up dialog box.

 Key Methods of IModelAdapter

Most method are self-evident.  See the Javadocs.

  • validate -- performs a validation of the board, returning a string that describes the current state of the board.
  • findMinChoiceCell performs a search of the board to find the cell whose choices could be tested and that would lead to the fastest solution of the board.  The heuristic used to choose the cell is up to the student.   The returned string is the toString() of the chosen cell.

Key Methods of GameModel

There are a number of utility methods to perform useful self-evident tasks--see the Javadocs.

  • currentBoard - a field which references the board that is currently being solved.
  • loadStrs -- takes a vector of strings, which are the rows of a puzzle, and translates the strings into the cells of a new current board.  This method is compatible with the puzzle generation utilities, but is not yet hooked up to them.
  • validateBoard - performs a validation check on the current board and returns a string describing the current state of the board.   This method calls validateCellSet on every cell set of the rows, columns and blocks of the board.   Examine this method carefully to get ideas on how to process the board!
  • getSolvedCellValues -- gets a HashSet<Integer> containing all the values from the solved cells in a cell set.   This is used when reducing a cell.
  • countCellChoices -- a utility method that will return the number of choices in all the unsolved cells in a given cell set
  • Wiki Markup
    {{reduceCellSet}} \-\- \[_Student implemented_<span style="color: #ff0000"><em>Student implemented</em></span>\]&nbsp; perform a single reduction pass on every cell in a given cell set.
  • Wiki Markup
    {{reduceBoard}} \-\- \[_Student implemented_<span style="color: #ff0000"><em>Student implemented</em></span>\]&nbsp; perform a single reduction pass on every cell in the board.
  • Wiki Markup
    {{solve}} \-\- \[_Student implemented_<span style="color: #ff0000"><em>Student implemented</em></span>\] perform reduction passes on the board until the board is either&nbsp;shown to be solved or unsolvable.&nbsp;&nbsp; This method should be able to handle boards that are reducible, irreducible, or unsolvable.
  • Wiki Markup
    {{findMinChoiceCell}} \-\- \[_Student implemented_<span style="color: #ff0000"><em>Student implemented</em></span>\] Use some heuristic to find the best choice for a cell whose values represent the fastest path to a solution.&nbsp;&nbsp; This method is used when an irreducible board is encountered and the solving process needs to iterate through the choices of a given cell to test for possible solutions.&nbsp;&nbsp; If a board is solvable, on _any_ cell, &nbsp;at least one value choice in an unsolved cell will always lead towards a solution.&nbsp;&nbsp; Other choices may lead to unsolvable boards.
  • Wiki Markup
    .{{solveIrreducibleBoard}} \-\- \[_Student implemented_<span style="color: #ff0000"><em>Student implemented</em></span>\] Given an irreducible board (a board that doesn't change when a reduction pass is performed), looks for a solution by testing the choices of a chosen cell.&nbsp;&nbsp; Note that a particular value choice in a cell could lead to an irreducible board, so this is fundamentally a recursive process\!&nbsp;

 Key Methods of IViewAdapter

  • setCellViews -- takes a vector of cell sets that define the blocks of a puzzle (Board.blks) and displays the board on the screen.
  • showMessageDialog -- utility method to show a string on the screen as pop-up dialog box.   This is useful for showing status results.

Testing the GameModel

For testing purposes, a GameModel can be instantiated using an implementation of IViewAdapter whose method a no-ops.    The methods of the GameModel can then be called. 

  • Test game files can be made to load the GameModel with well-defined boards for testing.    

...

  • {{GameModel} can both save and load games at any stage of reduction, so well-defined testing scenarios can be created where the board is in an exactly defined state, i.e. where every cell's value(s) are known precisely.       

Puzzle Generation Utilities

 The supplied code also contains a self-contained package {edu.rice.comp211.sudoku.generate}}