Question

IN C#: C# ONLY Here is a program that I need to that involves doing a...

IN C#:

C# ONLY

Here is a program that I need to that involves doing a sudoko puzzle. I have included the instructions below.

INSTRUCTIONS:

A few years ago, a style of puzzle became pretty popular. The name most people know it by is Sudoku. If you’ve played it, you know the rules. I’ll give them here in a nutshell. The user starts with a 9x9 grid. That grid is split into nine 3x3 blocks. There are a handful of cells filled in. The goal of the game is to fill in all the cells such that the following three rules are true:

each column uses each digit (1-9) exactly once

each row uses each digit exactly once

each of the 3x3 blocks uses each digit exactly once

Here are examples of a starting grid and a solution (lifted from Wikipedia).

"Sudoku-by-L2G-20050714 solution" by en:User:Cburnett

Your mission, should you choose to accept it, is to determine whether a given Sudoku answer is correct. This means that you will need to validate the three rules above for the given puzzle answer.

The puzzle will be in a .txt file. It will have nine rows of nine digits. The digits will be separated by commas. You will need to place the digits into a 9x9 two dimensional array. Then you will need to check each of the rules on the array. The numbers used will be 1-9. You do not need to worry about numbers outside the range.

At the end, you need to output VALID or INVALID. If the answer is invalid, you should write where you found it to be invalid. You must continue on to find and report all invalid locations, e.g.

ROW 0

COL 4

BLK 1

The rows are numbered left to right, the columns top to bottom, the blocks left-to-right, top to bottom, all starting with zero,

To be clear the blocks are numbered:

0

1

2

3

4

5

6

7

8

There are a number of txt files attached to the assignment, one good solution and a number of bad ones. There are notes in the file that give the expected errors. You may find these useful for testing your program. You are encouraged to create other good (and bad) solutions for further testing. Also, feel free to use any data structures in addition to a two-dimensional array that will help you in your validation.

Use good programming practices as you solve this problem. As always, you will be graded on efficiency, maintainability, etc. as well as correctness. Do not do this all in one big loop. Write methods to test each portion, e.g. one to test rows, one to test columns, etc. If you do not, you will find it difficult to think through your program logically; it will also be harder to maintain when your employer wants to add a ‘killer Sudoku’ checker.

As always, you will be graded on good programming practices, efficiency, clarity, etc.

For a grade of ‘B:

Report all invalid Rows and Columns.

For a grade of ‘A’:

Also report all the invalid Blocks.

Below is the txt files that was sent with the instructions. I don't know how to even start this program so please help me complete this so that I can get an 'A' on this program.

Suduko-bad-1.txt:

2,1,5,6,4,7,3,9,8
3,6,8,9,5,2,1,7,4
7,9,4,3,8,1,6,5,2
5,8,6,2,7,4,9,3,1
1,4,2,5,8,3,8,6,7
9,7,3,8,1,6,4,2,5
8,2,1,7,3,9,5,4,6
6,5,9,4,2,8,7,1,3
4,3,7,1,6,5,2,8,9

INVALID
ROW: 4
COL: 4
BLK: 4

Suduko-bad-2.txt:

2,1,5,6,4,7,3,9,8
3,6,8,9,5,2,1,7,4
7,9,4,3,8,1,6,5,2
5,8,6,2,7,4,9,3,1
1,4,2,5,9,3,8,6,7
9,7,3,8,1,6,4,2,5
8,2,1,7,3,9,5,4,6
6,5,9,4,2,8,7,1,3
4,3,7,6,1,5,2,8,9

INVALID
COL: 3
COL: 4

Suduko-bad-3.txt:

2,1,5,6,4,3,7,9,8
3,6,8,9,5,1,2,7,4
7,9,4,3,8,6,1,5,2
5,8,6,2,7,9,4,3,1
1,4,2,5,9,8,3,6,7
9,7,3,8,1,4,6,2,5
8,2,1,7,3,5,9,4,6
6,5,9,4,2,7,8,1,3
4,3,7,1,6,2,5,8,9

INVALID
BLK: 1
BLK: 2
BLK: 4
BLK: 5
BLK: 7
BLK: 8

Suduko-bad-4.txt:

2,1,5,6,4,7,3,9,8
3,6,8,9,5,2,1,7,4
7,9,4,3,8,1,6,5,2
5,8,6,2,7,4,9,3,1
1,4,2,5,9,3,8,6,7
9,7,3,8,1,6,4,2,5
8,2,1,7,3,9,5,4,6
6,5,9,5,2,8,7,1,3
4,3,7,1,6,4,2,8,9

INVALID
ROW: 7
ROW: 8
COL: 3
COL: 5

Suduko-good.txt:

2,1,5,6,4,7,3,9,8
3,6,8,9,5,2,1,7,4
7,9,4,3,8,1,6,5,2
5,8,6,2,7,4,9,3,1
1,4,2,5,9,3,8,6,7
9,7,3,8,1,6,4,2,5
8,2,1,7,3,9,5,4,6
6,5,9,4,2,8,7,1,3
4,3,7,1,6,5,2,8,9

Like I said, I don't know what the text files are suppose to be used for but can you please help me figure out this program so that I can get an 'A' on it.

Homework Answers

Answer #1
// Method: GenerateGame
// Purpose: Generates game based on complexity level.
public void GenerateGame(GameLevel level)
{

    // InitialiseSet
    // This first creates answer set by using Game combinations
    InitialiseSet();
    int minPos,maxPos,noOfSets;
     
    // Now unmask positions and create problem set.
    switch(level)
    {
    
        case GameLevel.SIMPLE:
            minPos=4;
            maxPos=6;
            noOfSets=8;
            UnMask(minPos,maxPos,noOfSets);
            break;
        case GameLevel.MEDIUM:
            minPos=3;
            maxPos=5;
            noOfSets= 7;
            UnMask(minPos,maxPos,noOfSets);
            break;
        case GameLevel.COMPLEX:
             minPos=3;
             maxPos=5;
            noOfSets = 6;
            UnMask(minPos,maxPos,noOfSets);
             break;
        default:
             UnMask(3,6,7);
              break;
    }
// Property:GameSet
// Return Problem Set as DataSet

public DataSet ProblemSet
{
    get{ return FormDataSet();}
}

// Handler method for data validations.
private void CurrentSet_ColumnChanging(object sender,
                System.Data.DataColumnChangeEventArgs e)
{
    try
    {
        lblStatus.Text="";
        int rowPos = dataGrid1.CurrentCell.RowNumber;
        string currentNumber = e.ProposedValue as string;
      
        int number =Int32.Parse(currentNumber);
        if((number < 1)||(number >9))
        {
            string errorMessage=
                "Number should be between 1 and 9";
            e.Row.SetColumnError(e.Column,errorMessage);
        }
        else
        {
            int col =e.Column.Ordinal;
            bool answerChanged =
                _newGame.CheckForAnswerChange(rowPos,col,number);
          
            if(answerChanged)
            {
                lblStatus.Text="You can't change the answer";
                e.ProposedValue = e.Row[e.Column];

            }else if(_newGame.CheckForDuplicate(rowPos,col,number)){
               e.Row.SetColumnError(e.Column,"Number is Duplicate");
          
            }else
             {
                e.Row.ClearErrors();
                bool answerComplete= IsSolutionComplete();
                if(answerComplete)
                {
                  lblStatus.Text= "Great!!! You have done it";
                }
            }

        }
    }
    catch(Exception ex)
    {
        e.Row.SetColumnError(e.Column,
             "Enter valid Number between 1 & 9");
    }
}

/// DataGrid Paint overriden to paint border
private void DataGrid1_Paint(object sender,
            System.Windows.Forms.PaintEventArgs e)
{


    // Override this handler to do custom painting.
    Point currentPoint = new Point(0,0);
    Size size = new Size(PREFERRED_COLUMN_WIDTH*3,
                             PREFERRED_ROW_HEIGHT*3);
    Pen myPen = new Pen(Color.Red,3);
      
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            currentPoint.X = i*PREFERRED_ROW_HEIGHT*3;
            currentPoint.Y = j*PREFERRED_ROW_HEIGHT*3;
            Rectangle rect = new Rectangle(currentPoint,size);
            e.Graphics.DrawRectangle(myPen,rect);

        }
    }
}



// On edit, add scroll event handler, and display combobox
protected override void Edit(System.Windows.Forms.CurrencyManager
    source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly,
    string instantText, bool cellIsVisible)
{
    //Call base method which is important else
    //edit will not function properly
    base.Edit(source, rowNum, bounds, readOnly,
                     instantText, cellIsVisible);

    // Check if cell is not empty
    if(this.TextBox.Text.TrimEnd()!="")
    {
        // Get Column position

        int dataValue = Int32.Parse(this.TextBox.Text);
        int pos = this.MappingName.LastIndexOf("col");
        if(pos > -1)
        {
            string colIndex = this.MappingName.Substring(pos+3);
            int colPos = Int32.Parse(colIndex);
            // Check whether it is answer spot.
            _answerPostion=_game.CheckIfAnswerPosition(rowNum,
                                              colPos,dataValue);
        }
    }
    else
    {
         _answerPostion =false;
    }
    if (!readOnly && cellIsVisible)
    {
      
        // Save current row in the DataGrid and currency manager
        // associated with the data source for the DataGrid
        this._currentRow = rowNum;
        this.cm = source;

        if(!_answerPostion)
        {
            // Make parent of scrollbar same as parent.
            this.vsBar.Parent = this.TextBox.Parent;
            Rectangle rect =
                this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
            //Place this control to right.
            this.vsBar.Location =
                new Point(rect.Right-this.SpinnerWidth,rect.Top);
            this.vsBar.Size =
                new Size(this.SpinnerWidth,this.TextBox.Height);

            // Make the scrollbar visible and place on top textbox control
            this.vsBar.Show();
            // As textbox control also there let us bring this to front.
            this.vsBar.BringToFront();
          
            this.vsBar.Show();
            //    this.TextBox.Text= this.vsBar.Value.ToString();
            this.TextBox.ReadOnly=true;
            //Set text color properties different as we are editing cell.
            this.TextBox.BackColor = Color.Blue;
            this.TextBox.ForeColor=Color.White;
        }
        else
        {
            this.TextBox.ReadOnly=true;
            this.TextBox.BackColor=Color.White;
            this.TextBox.ForeColor =Color.Black;
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
I need a program written in C, not C+ or C++. I have no idea how...
I need a program written in C, not C+ or C++. I have no idea how to go about doing it. Basically, I need it to take in the following information and spit out the following for a number table. The operation should be able to take plus, minus, division or multiplication and the low/high row/column numbers should be able to go up to where ever. But I'm sure the following example is fine. Enter low row number: 1 Enter...
Please I need this to be done in PERL language only Write a program that prompts...
Please I need this to be done in PERL language only Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba AND Modify the previous script to use a die message if the...
I need to change an integer and put it into an array but in a way...
I need to change an integer and put it into an array but in a way that it is read correctly. Arrays are typically drawn to be read left to right with the 0 element on the left and the largest on the right. However, arrays are a completely made up concept and are not physical in nature. So you can draw them and think about them anyway you want. For this problem having the right side as the 0...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
Hello. for one of my assignment, I need to create any program using the C language...
Hello. for one of my assignment, I need to create any program using the C language and that must contain the following: - Error Checking - Use of Functions - Menu system - Array Processing It can be about anything, nothing specified but must contain the features mentioned above Thank you
Your C program will do the following : Must use at least 2 function prototypes &...
Your C program will do the following : Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays. 1. In your main program, create a array of size 7 X 7. 2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...