コード例 #1
0
 public bool Equals(sudokCell obj)
 {
     if (!this.getPossibles().SequenceEqual(obj.getPossibles()) || this.getSolved() != obj.getSolved())
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public sudokCell Clone(sudokCell myCell)
        {
            if (myCell.solved)
            {
                return(new sudokCell(myCell.getVal()));
            }

            return(new sudokCell(myCell.getPossibles()));
        }
コード例 #3
0
 public SudokuGrid()
 {
     cells = new sudokCell[9, 9];
     for (int row = 0; row < 9; row++)
     {
         for (int column = 0; column < 9; column++)
         {
             this[row, column] = new sudokCell();
         }
     }
 }
コード例 #4
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void TestMethod1()
        {
            List <int> possibles = new List <int>();

            possibles.Add(10);
            possibles.RemoveAt(0);
            //var x = new SudokuLogic.Class1();
            //var y = x.HelloTest();
            //TestContext.WriteLine($"the value is {y}");
            ////Assert.Fail(y);
            SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell();
            sudokCell             newCell   = new sudokCell(0);

            newCell.RemoveAt(0);
        }
コード例 #5
0
 //checks two cells for the same possibilities
 public bool samePossible(sudokCell other)
 {
     if (this.possibles.Count != other.possibles.Count)
     {
         return(false);
     }
     for (int i = 0; i < this.possibles.Count; i++)
     {
         if (this.possibles[i] != other.possibles[i])
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void CheckAllStoredLogic()
        {
            bool solvedAll = true;

            //1 to 23, inclusive
            for (int i = 1; i <= NumStoredSudokus; i++)
            {
                SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver();
                SudokuLogic.sudokCell    sudokCell    = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                sudokuSolver.Solve(mySudoku, true);

                //bruteForceSolver(mySudoku);

                //if unsolved
                if (!sudokuSolver.IsSolved(mySudoku, false))
                {
                    solvedAll = false;
                    TestContext.WriteLine("More work on " + i);
                    TestContext.WriteLine("Num unsolved is " + sudokuSolver.numUnsolved(mySudoku));
                }
                //if there was a duplicate in row, column, or box
                if (sudokuSolver.InvalidMove(mySudoku))
                {
                    TestContext.WriteLine("Invalid move on " + i);
                }
            }
            if (solvedAll)
            {
                TestContext.WriteLine("All solved");
            }

            Assert.IsTrue(solvedAll, "Not all solved");
        }
コード例 #7
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void CheckIsValidMethod()
        {
            //1 to 23, inclusive
            //23 broke
            for (int i = 1; i <= 23; i++)
            {
                SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver();
                SudokuLogic.sudokCell    sudokCell    = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                Assert.IsTrue(mySudoku.IsValid(), $"{i} was said to be not valid");
            }

            SudokuGrid notValid1 = new SudokuGrid();

            //my sudoku to be worked with
            for (int row = 0; row < 9; row++)
            {
                for (int column = 0; column < 9; column++)
                {
                    notValid1[row, column] = new sudokCell();
                }
            }
            notValid1[1, 1].solve(2);
            Assert.IsFalse(notValid1.IsValid(), "IsValid said a nonValid Sudoku is validx");
        }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: TylerHsia/Sudoku2
        public void TestRateDifficulty()
        {
            SudokuSolver sudokuSolver = new SudokuSolver();

            for (int i = 1; i <= NumStoredSudokus; i++)
            {
                SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell();
                //inputted sudoku
                int[,] sudokuInputted = input(i);

                SudokuGrid mySudoku = new SudokuGrid();

                //my sudoku to be worked with
                for (int row = 0; row < 9; row++)
                {
                    for (int column = 0; column < 9; column++)
                    {
                        mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]);
                    }
                }

                TestContext.WriteLine($"the level of {i} is {sudokuSolver.RateDifficulty(mySudoku)}");
            }
        }
コード例 #9
0
 public sudokCell(sudokCell obj)
 {
     new sudokCell(obj.getPossibles(), obj.getSolved());
 }
コード例 #10
0
 public List <int> getPossibles(sudokCell obj)
 {
     return(obj.getPossibles());
 }