Professional Documents
Culture Documents
Write a program to allow the user to play Sudoku. For details on the rules of the game, see: http://en.wikipedia.org/wiki/Sudoku The program will prompt the user for the filename of the game he or she is currently working on and display the board on the screen. The user will then be allowed to interact with the game by selecting which square he or she wishes to change. While the program will not solve the game for the user, it will ensure that the user has not selected an invalid number. If the user types ? in the field, then the program will show the user the possible valid numbers for a given square. When the user is finished, then the program will save the board to a given filename and exit.
Interface Design
Consider a game saved as myGame.txt:
7 6 8 0 0 0 5 4 9 2 0 0 7 0 5 0 0 3 3 0 0 0 4 0 0 0 2 0 3 0 6 2 9 0 1 0 0 0 1 5 0 3 7 0 0 0 2 0 4 7 1 0 3 0 1 0 0 0 3 0 0 0 7 5 0 0 2 0 4 0 0 1 9 8 2 0 0 0 3 6 4
Note that 0 corresponds to an unknown value. The following is an example run of the program. Please see the following program for an example of how this works:
/home/cs124/prj4
Program starts
An example of input is underlined.
Where is your board located? myGame.txt
With the filename specified, the program will display a menu of options:
Options: ? Show these instructions D Display the board E Edit one square S Show the possible values for a square Q Save and quit
After this, the board as read from the file will be displayed:
Project 4: Sudoku
Page 333
Section 4
1 2 3 4 5 6 7 8 9
Here, the user will be prompted for a command (the main prompt).
> Z
Please note that you will need a newline, a carat ('>'), and a space before the prompt. The next action of the program will depend on the users command. If the user types an invalid command, then the following message will be displayed and the options will be redisplayed:
ERROR: Invalid command
Show Instructions
If the user types ?, then the menu of options will be displayed again. These are the same instructions that are displayed when the program is first run.
Section 4
If the value is invalid or if the square is already filled, then the program will display one of the following message and return to the main prompt:
ERROR: Square 'zz' is invalid ERROR: Square 'A1' is filled.
Page 334
Project 4: Sudoku
With a valid coordinate, then the program next prompts the user for the value
What is the value at 'A1': 9
If the user types a value that is outside the accepted range (1 value 9) or does not follow the rules of Sudoku, then a message appears and the program returns to the main prompt:
ERROR: Value '9' in square 'A1' is invalid
The same parsing logic applies here as for the Edit One Square case. Once the user has selected a valid coordinate, then the program will display the possible values:
The possible values for 'A1' are: 1, 5, 8, 9
After the message appears, the program returns to the main prompt.
Extra Credit
You can earn extra credit with the following:
"Robust" error checking. Every possible input or board configuration is handled. For example, the user could type e5 or 5E to specify a square. Also, the board is validated on open to ensure it is a valid board This means ensuring that there is no more than one instance of each value in a given row, column, or inside square. 10% Differentiate read-only values (the ones provided by the board that the user cannot change) and read/write values (the ones the user entered). Read-only text will be rendered in green. The following example outputs green text for the word "green"
cout << "This text is \E[22;32m green \E[0m but not the rest.\n";
To get 10% credit, you must preserve the number through a file save. Submit extra credit attempts to Project Extra instead of Project 4 and use cs124/extraCredit for the Test-Bed.
Solution to board
/home/cs124/prjFinal85Solution.txt /home/cs124/prjFinal90Solution.txt /home/cs124/prjFinal100Solution.txt
Project 4: Sudoku
Page 335
Section 4
computeValues. This function will take as parameters coordinates (row and column) for a given square on the board and calculate the possible values for the square. To do this, computeValues must be aware of all the rules of Sudoku. Make sure to include both the logic for the rules of the game (only one of each number on a row, column, and inside square), but also to display the values. 2. Write the pseudocode for the function interact. This function will prompt the user for his option (ex: D for Display the board or S for Show the possible values for a square) and call the appropriate function to carry out the users request. Note that the program will continue to play the game until the user has indicated he is finished (with the Q option). 3. Create a Structure Chart describing the entire Sudoku program
Good 90%
All the rules are correctly represented in the pseudocode All possible values will be listed for a given square on the board The function will allow the user to interact with the game
Acceptable 70%
A bug exists or not all the rules are enforced
Developing 50%
Missing 0%
No rule logic in the
computeValues
20%
Pseudocode insufficient quality to help in the design process A bug exists in the Pseudocode not algorithm or does detailed enough not solve all the to tell if the problems problem has been solved. The design fails to Pseudocode do one of the insufficient following: quality to help in Select an option the design process Execute the option specified Continue looping until the user is finished The Structure Structure chart Chart is not showing the incomplete or has connection a serious defect between the making the functions, name solution of the functions, unworkable. or the data passed between the functions
function
Section 4
Page 336 |
No structure chart
You are required to attach the above rubric to your design document. Please self-grade.
Project 4: Sudoku
Assignment: Code
Please:
Good 90%
One minor cohesion or coupling error
Acceptable 70%
One bug calling a function or unnecessary data passed between functions A board can be read from a file or written to a file correctly One edit is correctly handled
Developing 50%
Multiple functions exist in the project
Missing 0%
Only one function used
Files 20% Edits 10% Rules 20% Display 20% Style 10%
Able to roundtrip data through the file All edits are perfectly handled Able to enforce all the rules of the game
Some data is read to a file or read from a file Program is interactive Attempts were made to enforce game rules Data from the board is rendered on screen Misleading variable names or gross style errors
No UI
Project 4: Sudoku
Page 337
Section 4
Looks correct on screen but there are cosmetic test bed errors A few style checker errors