Versions Compared

Key

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

...

The view and model packages are thus completely isolated and independent from each other.   The job of the Controller class in the edu.rice.comp211.sudoku.controller package is to assemble the complete, operational application by joining the view and model together.   It does so by creating implementations of both IModelAdapter and IViewAdapter that pass their method calls onto the GameFrame and GameModel respectively.   This may involve simply passing the call along to the appropriate method on the receiver, for instance, IModelAdapter.solve() is implemented to simply call GameModel.solve().   But other methods may require more extensive translation, for instance, IviewAdapter.setCellViews() is implemented to take a Vector<ICellSet> object, convert it into a 2-dimensional array of ICelllViews and then make the call to GameFrame.addCells().   

...

  • 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}} \-\- \[<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}} \-\- \[<span style="color: #ff0000"><em>Student implemented</em></span>\]&nbsp; perform a single reduction pass on every cell in the board.
  • Wiki Markup
    {{solve}} \-\- \[<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}} \-\- \[<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}} \-\- \[<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.

...

 The supplied code also contains a self-contained package {, edu.rice.comp211.sudoku.generate, that is used to read Sudoku puzzles from text files containing a total of over 50,000 solvable puzzles.  These puzzles come from www.printable-sudoku-puzzles.com but are a different format than the Comp211 Sudoku solver uses.   These utilities, which are all contained in the GeneratePuzzle class, can read those data files, pick either a specific puzzle from them, or a random puzzle, display it and save the individual puzzle in a format that the Comp211 Sudoku solver can read.

GeneratePuzzleApp is a a simple GUI interface to GeneratePuzzle that allows the user to easily perform conversions.   Note that the higher numbered data files (located in data\puzzle-src) have more difficult puzzles.   Each data file contains about 10,000 puzzles numbered from 1-10000 (approx.).   An index of zero means to choose a random puzzle from the data file.   

Wiki Markup
{\[GeneratePuzzleApp}} has its own {{main()}} method and thus can be run as a separate, stand-alone&nbsp;application apart from the Sudoko solver.

See the Javadocs for more detailed information on the individual methods.