Ejemplo n.º 1
0
def solve():
    """
    Operation to attempt to solve the sudoku puzzle that the GUI represents.

    If there are any error within the sudoku or the puzzle cannot be solved an
    alert pops up, otherwise the GUI is updated with the solved sudoku puzzle.
    """
    # Converts GUI puzzle to Sudoku instance
    if validate_inputs():
        sudoku = Sudoku(SUDOKU)
        if sudoku.is_valid():
            if sudoku.solve():
                update_gui(sudoku)
            else:
                messagebox.showerror(title="Error", message="Cannot solve.")
                update_gui(sudoku)
        else:
            messagebox.showerror(title="Error",
                                 message="This sudoku is invalid.")
Ejemplo n.º 2
0
from sudoku.sudoku import Sudoku

puzzle = open("fichiers/puzzles.sdk", 'r')
res_puzzle = open("fichiers/puzzle_result.sdk", 'a')

i = 0
for line in puzzle:
    i += 1
    line = line.replace('\n', '')
    sudo = Sudoku(line)
    if sudo.solve():
        res_puzzle.write("{}\n".format(sudo))
        print(i)
puzzle.close()
res_puzzle.close()
Ejemplo n.º 3
0
from sudoku.sudoku import Sudoku

print("Test avec grille de sudoku")

file = open("fichiers/puzzles.sdk", 'r')
board = file.readline().replace('\n', '')
file.close()
#sudoku = Sudoku("029405006640082000000000000908060200000000000005040803000000000000530021500109430")
sudoku = Sudoku(
    "100000000000010000000000000000000001000000000000000000000000000000000000000000100"
)
#sudoku = Sudoku(board)
sudoku.display()
if sudoku.solve():
    sudoku.display()