Exemplo n.º 1
0
 def test_hint_can_reach_solution(self):
     s = SudokuPuzzle([['A', 'B', 'C', 'D'],
                       ['C', 'D', '', 'B'],
                       ['B', 'A', 'D', 'C'],
                       ['D', 'C', 'B', 'A']])
     for p in s.extensions():
         print(p)
     self.assertEqual(hint_by_depth(s, 10), '(1, 2) -> A')
Exemplo n.º 2
0
 def extensions(self) -> List[RandomizedSudokuPuzzle]:
     """
     Return a list of extensions of this sudoku puzzle.
     The order of the extensions is randomized.
     """
     exts = SudokuPuzzle.extensions(self)
     shuffle(exts)
     return exts
Exemplo n.º 3
0
                return [(puzzle.generate_hint(extension), True)]

            extension_hints = possible_hints(extension, n - 1)

            for hint in extension_hints:
                if hint[1]:  # if this hint will lead to a solution
                    return [(puzzle.generate_hint(extension), True)]

            # Else all the hints in extension do not lead to a solution
            # Only adds if lst is empty, since only one hint is necessary
            if len(lst) == 0 and len(extension_hints) > 0:
                lst.append((puzzle.generate_hint(extensions[0]), False))

    return lst


if __name__ == '__main__':
    from sudoku_puzzle import SudokuPuzzle
    from word_ladder_puzzle import WordLadderPuzzle
    s = SudokuPuzzle([['A', 'D', 'C', ''], ['B', 'C', '', ''],
                      ['C', 'B', 'A', 'D'], ['D', 'A', 'B', 'C']])
    print(s.extensions()[0])
    print('The puzzle:')
    print(s)
    print('SOLVE')
    solve(s, True)
    print('\nSOLVE-ALL')
    solve_complete(s, True)
    print('\nHINT 1')
    print(hint_by_depth(s, 1))
Exemplo n.º 4
0
 def test_hint_can_reach_solution(self):
     s = SudokuPuzzle([['A', 'B', 'C', 'D'], ['C', 'D', '', 'B'],
                       ['B', 'A', 'D', 'C'], ['D', 'C', 'B', 'A']])
     for p in s.extensions():
         print(p)
     self.assertEqual(hint_by_depth(s, 10), '(1, 2) -> A')