示例#1
0
        static void Main(string[] args)
        {
            Board b = new Board(n);
            StreamReader inputPuzzles;
            Square[] firstThree = new Square[3];
            int sum = 0;
            inputPuzzles = new StreamReader("p096_sudoku.txt");
            String temp, puzzleString;
            for (int currentPuzzle = 0; !inputPuzzles.EndOfStream; currentPuzzle++)
            {
                puzzleString = "";
                temp = "";
                temp = inputPuzzles.ReadLine();
                while (!inputPuzzles.EndOfStream && !temp.StartsWith("G"))
                {
                    puzzleString = puzzleString + temp;
                    temp = inputPuzzles.ReadLine();
                }
                if (puzzleString.Length > n)
                {
                    b = new Board(3);
                    b.setupBoardFromString(puzzleString);

                    //b.showSquares();
                    b.completePuzzle();
                    Console.WriteLine(b.showSquares());
                    temp = "";
                    //Console.WriteLine(b.showSquares());
                    for (int index = 0; index < 3; index++)
                    {
                        if ((b.getSquares()[index].getValue() + 1) == 0)
                        {
                            Console.WriteLine(b.showSquares());
                            break;
                        }
                        temp = temp + (b.getSquares()[index].getValue() + 1);

                    }
                    //Console.WriteLine(temp);
                    sum += int.Parse(temp);
                    //Console.WriteLine(sum);
                    // Console.ReadLine();
                }

            }
            Console.WriteLine(sum);
            Console.ReadLine();
        }
示例#2
0
        private void Guess()
        {
            //find a square with two possible values
            Console.WriteLine("Guessing!");
            Square[] temp;
            Board branch;
            List<Square[]> permutations = new List<Square[]>();
            for (int i = 0; i < n4; i++)
            {
                if (allSquares[i].getValue() != Square.NULL_VALUE)
                {

                    foreach (int values in allSquares[i].GetPossibleValuesList())
                    {
                        temp = new Square[n4];
                        Array.Copy(allSquares, temp, n4);
                        temp[i].setValue(i);
                        permutations.Add(temp);
                    }
                }
            }
            foreach (Square[] sArr in permutations)
            {
                branch = new Board(n, sArr);
                branch.completePuzzle();
                if (branch.isLegal() && branch.isComplete())
                {
                    allSquares = branch.allSquares;
                    Console.WriteLine(showSquares() + "\n\n!!!!!!!");
                    Console.ReadLine();
                }

            }
        }