// Get the board randomly filled private Board GetRandomBoard(string hash) { var result = _boardHash.LoadFromHash(hash); var possibilityCalculator = new PossibilityCalculator(_boardHash.LoadFromHash(hash)); for (var line = 0; line < result.Lines; line++) { for (var column = 0; column < result.Columns; column++) { var value = result.GetBoardValue(line, column); if (!value.IsProvided) { var possibilities = possibilityCalculator.PossibilitiesFor(line, column); var rnd = _random.Next(possibilities.Count); var newValue = possibilities[rnd]; result.SetBoardValue(line, column, new BoardValue(newValue)); } } } return(result); }
static void Main(string[] args) { System.Console.WriteLine("Insert the board hash as 1 long line:"); var hash = System.Console.ReadLine(); var boardHash = new BoardHash(); var stats = new BoardStatistics(boardHash.LoadFromHash(hash), new PossibilityCalculator(boardHash.LoadFromHash(hash))); System.Console.WriteLine($"\n\nStarting solving. There are {stats.GetPossibilities()} possibilities.."); var solver = new BruteForceSolver(); var result = solver.Solve((new BoardHash()).LoadFromHash(hash)); System.Console.WriteLine($"Solved in {solver.Attempts} attempts.\n\n"); OutputBoard(result); }
public void TestLoadBoardFromHash() { var hashGenerator = new BoardHash(); var hash = String.Empty; for (int line = 0; line < 9; line++) { for (int column = 0; column < 9; column++) { hash += column + 1; } } var board = hashGenerator.LoadFromHash(hash); Assert.AreEqual(hash, hashGenerator.GetHash(board)); }
public void PossibilitiesFor_EmptyFields() { // Arrange var boardHash = new BoardHash(); var testSet = GetTestSet(); foreach (var assert in testSet) { // Act var board = boardHash.LoadFromHash(assert.Hash); var possibilityCalculator = new PossibilityCalculator(board); var actual = possibilityCalculator.PossibilitiesFor(assert.Line, assert.Column); // Assert CollectionAssert.AreEqual(assert.ExpectedResult, actual); } }