public void InvalidCell() { string puzzleString = "540070009000901000009460000050040020200000040910600785030590200000180006605200000"; SudokuPuzzle puzzle = new SudokuPuzzle(puzzleString); Cell cell = new UserCell(2) { Value = 5 }; bool res = m_Validator.ValidateCell(puzzle, cell); Assert.IsFalse(res); }
//TODO: Solve from front and back to see if multiple solutions exist (throw exception) public ISudokuPuzzle Solve() { if (!m_Validator.ValidateSudoku(m_Puzzle)) { throw new InvalidPuzzleException(); } int i = 0; Cell[] userCells = m_Puzzle.Cells.Where(c => c is UserCell).ToArray(); while (i < userCells.Length) { if (i < 0) { throw new UnsolvablePuzzleException(); } UserCell cell = userCells[i] as UserCell; int val = cell.Value + 1; if (val > 9) { cell.Value = 0; i--; continue; } cell.Value = val; if (m_Validator.ValidateCell(m_Puzzle, cell)) { i++; } } return(m_Puzzle); }