






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007
Spring 2006 Programming Assignment 1
Due: Monday, 23 January 2006
Sudoku is a Japanese logic-puzzle that has recently become quite popular. The aim of the puzzle is to enter a numerical digit from 1 through 9 in each cell of a 9×9 grid made up of 3×3 subgrids (called "regions"), starting with various digits given in some cells (the "givens"). The digits must be assigned in such a way that no row, no column, and no region has more than one instance of any digit. Figure 1 shows a Sudoku puzzle (givens are shown as dark gray cells):
 Figure 1: A Sudoku Puzzle |  Figure 2: The Solution |
Figure 2 shows the same puzzle as Figure 1, but it is solved. Both 1 and 2 were created with the Squeak Sudoku, available below. For programming assignment 1, you are to extend the Squeak Sudoku to make it easier to solve as follows:
- Show visually whether a cell is invalid. A cell is invalid if some other cell in its row, column, or region has the same value. These should update automatically whenever a new value is entered.
- Complete the score function. In the original version, there is a placeholder <updating score> for the score. The score should display how many cells are blank and how many cells are invalid. When no cells are blank or invalid, inform the user that they have won.
- Complete the AutoScan mode. In the normal mode, blank cells are empty and clicking on the cell changes its value to the next value (blank, 1, 2, 3, 4, 5, 6, 7, 8, 9, blank). In AutoScan mode, the row, column, and region scans are done automatically. Blank cells display (in grayed text) the values that wouldn't make any of its neighbors (in column, row, or region) invalid. Clicking on the cell changes its value to the next valid value, based on those scans.
Figure 3 shows how these changes might look. Invalid cells are highlighted in yellow. The score is red as there are invalid cells. In AutoScan mode, the possible valid numbers for each blank are shown as grayed out.
 Figure 3: The Goal of Assignment 1 |
The Squeak Sudoku
To use the Squeak Sudoku, first download the code and install it. To file in the code, open a file list (World Menu::open...::file list), find and select the Sudoku-initial.st file; click the filein button to install the code. Next, open a new SudokuMorph. You can either execute SudokuMorph new openInWorld or go through the menus (World Menu::new morph...::from alphabetical list::S-S::SudokuMorph). Then, you can open one of the example puzzles available below. Download the puzzle(s) to your Squeak directory; when you click on the central dot on the SudokuMorph, a menu will come up that allows you to open the puzzles (and even create new ones).
Dealing with MVC (Model-View-Controller)
The Sudoku version provided uses the MV paradigm of MVC—it separates the model from the view. SudokuPuzzle and SudokuCell form the model. SudokuMorph and SudokuCellMorph form the view. To see how this works, check out these methods:
- SudokuCellMorph cell: In this method, the SudokuCellMorph adds itself as a dependent of the SudokuCell that it is the view for. That means it will get update messages.
- SudokuCell value: This method gets called to change the value of the cell. It then performs self changed: #value to update its dependents (the SudokuCellMorph in this case).
- SudokuCellMorph update: This method gets called because of the changed call in the above method. If the symbol is #value, it updates the label.
You can use a similar mechanism to do all of the other communication for this programming assignment. For instance, when the validity changed, call self changed: #valid and deal with it.
Grading Criteria
- Highlight Invalid Cells (25)
- Functions properly - 10
- Automatically updates with changes - 10
- Different highlighting for givens and normal cells - 5
- Updating Score (30)
- Shows correct number of blanks and invalid cells - 15
- Automatically updates with changes - 10
- There is a different message when the puzzle is solved - 5
- AutoScan Mode (45)
- Blank cells show the valid values for that cell - 20
- Automatically updates with changes - 15
- Clicking on the cell moves it to the next valid value - 10
Collaboration Policy
You are not allowed to share your code with others in this class. You can give or receive incidental help (but not code) from others. This is an individal assignment; you turn in your own code. The only exception to this rule is if you want to complete this assignment using pair programming (read this page if you are interested).
Links to this Page