Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to implement a Sudoku game, i have been able to populate the game control with values, but i have a challenge validating input fields, i want to be able to validate and display to the user when it gets it wrong or right.

the rule of the game is that, number one to 4 must not appear more than once in a row, column and block.

Any assistance would be appreciated.

What I have tried:

private void Populate()
    {
        List<string> num = new List<string>();

        foreach (string line in File.ReadLines("Sudoku Text File.txt"))
        {
            num.Add(line);
        }
        Random rnd = new Random();
        rand = rnd.Next(1, 5);
        var number = num[rand];
        listBox1.Items.Add(number);

        for (int i = 0; i < number.Length; i++)
        {

            if (number[i] == '0')
            {
                panel1.Controls[i].Text = "";
            }
            else
            {
                panel1.Controls[i].Text = number[i].ToString();
                panel1.Controls[i].Enabled = false;
            }               
        }

    }



the Sudoku text file has these values:

4000001002004021
0200002030204001
0040010220000423
4000000220041400
0200103201200001
Posted
Updated 19-Nov-19 11:55am

 
Share this answer
 
v2
Quote:
i want to be able to validate and display to the user when it gets it wrong or right.

The only way I know is to solve the Sudoku.
You have basically 2 methods
- Brute force: try mechanically to fill cells until something go wrong or you solve it. Always find a solution if one is possible.
- try to solve with human like methods. Can be unable to solve the problem if inpit is really complicated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900