Sudoku is a puzzle that has been found in most newspapers since it gained popularity in 2005. Typically, the puzzle is played with a 9x9 grid that is subdivided into nine 3x3 boxes. The object of the puzzle is to fill the grid such that the digits 1 to 9 are contained (without repeats) in each row, each column, and each box. Seed digits are initially placed in the grid to define the puzzle and to limit where additional digits can be added by the person solving the puzzle. For this assignment, you are going to make a simple, digital version of a Sudoku game.
Create a directory assignment1 under assignments in your cs120 directory. All code for the assignment should be stored in this directory.
cd ~/cs170/assignments mkdir assignment1 cd assignment1
You are going to be using the Tkinter module to create a graphical version of the Sudoku game. Your program will read a text file that encodes the initial seed values for the Sudoku puzzle, and allow users to change the non-seed values by clicking on the appropriate cells. You do not need to worry about whether the user has won the game, just allowing them to play the game is fine.
The text file will contains 9 lines of 9 characters each. Each character specifies the value of a given cell in a Sudoku puzzle. Values in the range [1,9] specify that cell contains a "seed" value for the puzzle, while a value of 0 specifies that cell is initially empty. For example, the following text file represents the Sudoku puzzle shown above.
002300050 010040000 900005020 800760030 700000004 060034005 050200006 000010070 070009800
When the user clicks on a cell of the puzzle that was not originally a "seed" value, the value of the cell should be incremented by 1. For example, an empty cell would get assigned the value of 1, while a cell with a value of 5 gets the new value of 6. Cells with a value of 9 should become empty. Nothing should happen if the user clicks on a "seed" value.
Graphical programs are inherently difficult to test, because most involve some interaction with the user. This program is no different. However, they are typically pieces of the program that are much easier to test. For example, you will likely have a function that reads in the initial state from a file.
For Monday, January 20th, write the Pre and Post conditions for this function, as well as at least 3 test cases that you could use to validate this function. These should be written on paper, and brought to class on Monday. You do not need to have written the function by then, just the Pre and Post conditions as well as the test cases.
These are worth 10 points of your assignment grade. It does not sound like a lot, but they should be 10 easy points to get each week. Do not neglect them.
You are required to submit a tar file to http://cseval.roanoke.edu/. On cseval, there is a link for Assignment 1. You can create a tar file by issuing the following commands:
cd ~/cs170/assignments tar czvf assignment1.tgz assignment1/
Each week, additional exercises related to the assignment will be provided at the end. These exercises are typically more challenging than the regular assignment. Bonus points will be provided to students who complete any of the "Hacker" level assignments.
Conflicts: The rules for Sudoku are very clear. Yet, most people still end up trying to write invalid moves to the board. Even if the conflict already exists. It would be advantageous to the users for you to notify them of a conflict in some way.
You should highlight all cells that are currently in conflict with some other cell.
Winning: The standard portion of this assignment does not require you to notify the user if they won. Presumably your users are intelligent enough to notice if they won, but not all users will be able to.
Modify your program so that it displays a text message to the user indicating that they successfully completed the puzzle.
Saving and Loading: Some people take a long time to solve a single Sudoku puzzle. Long enough that it would be advantageous for them to be able to save the current state of the puzzle, to load their progress later.
Bind the 'S' key to save the current state to a file. Bind the 'L' key which loads that state to the game. This should be a specifically named file, so only one save will be active at any given time.
Don't forget to make sure that the values the user enters into the game are not loaded as seed values!