...
The Controller
is the only class that knows which view and which model are used for any given application.
Key Methods of GameFrame
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 thetoString()
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 callsvalidateCellSet
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 aHashSet<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 setWiki Markup {{reduceCellSet}} \-\- \[_Student implemented_\] perform a single reduction pass on every cell in a given cell set.
Wiki Markup {{reduceBoard}} \-\- \[_Student implemented_\] perform a single reduction pass on every cell in the board.
Wiki Markup {{solve}} \-\- \[_Student implemented_\] perform reduction passes on the board until the board is either shown to be solved or unsolvable. This method should be able to handle boards that are reducible, irreducible, or unsolvable.
Wiki Markup {{findMinChoiceCell}} \-\- \[_Student implemented_\] Use some heuristic to find the best choice for a cell whose values represent the fastest path to a solution. 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. If a board is solvable, on _any_ cell, at least one value choice in an unsolved cell will always lead towards a solution. Other choices may lead to unsolvable boards.
Wiki Markup .{{solveIrreducibleBoard}} \-\- \[_Student implemented_\] 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. Note that a particular value choice in a cell could lead to an irreducible board, so this is fundamentally a recursive process\!
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.
Puzzle Generation Utilities
...