The sudoku board has 9 rows and 9 columns. The board is further broken down into 3×3 regions. The goal of the game is to populate the board with numbers from 1 to 9 so that no duplicate numbers exist in any row, column or region.
More information on sudoku rules
We need to be able to read in values one at a time and determine if they need to be placed in the board and if so, where. We cannot rely on carriage returns or spaces, as the lab states that they may or may not be present. So, the input could look like the sample input given in the lab description, or it could be a single line of numbers and dashes, or something in between.
Also, we may want to convert the numbers into integers for further manipulation (although this is not necessary).
So, here is a snippet of code that might help with reading in the values In this I am ultimately storing the values in a 2d array.
The istringstream class creates a stream from a string. Allowing us to treat it as a stream and read in different values from it. More information about string stream
You would need to include the sstream library and string library to use this method
Here is a link to the C++ FAQ which indicates that string streams are the better way to convert strings to integers. Also has a lot of other good information on C++
ddd might be useful to debug your program and see how the system executes.
Again, to use ddd, add the ‘-g’ flag to the g++ statements of your makefile
After compiling your lab you can open it in ddd with
ddd ./lab04
See the Introduction Notes for a overview of the basics of ddd.
For this project, and most projects in eecs 268, you need to read in an input file from the command line (via argv[1]). To add this line in ddd:
Click on Program and then Run…
Type in the filename in the Run with Arguments pane.
Click “Run”
When you want to watch the value of a variable, this can be easily done inside ddd.
If you just want to see the value of a variable once, you can hover over the name of that variable and it will appear (Remember, your program has to be ‘running’ inside ddd for anything to work)
If you want to watch the value over an extended period of time you can:
Right-click on the variable name
Select Display
Another pane will appear above your source code with a box containing the value of the variable you are displaying. This box can be moved around to allow multiple variables to be viewed.
After a few recursive calls, it would be nice to see how any particular call was entered and the variable values during that recursion. Here the backtrace can be very useful.
Click on the “Status” Dropdown menu
Click on “Backtrace”
You can now move up and down the stack, using the Up and Down buttons. At each level of the backtrace, you can see the variable values by hovering over them or displaying them as described above