コード例 #1
0
    if sudoku.get(x, y) != 0:  # if cell is not empty
        return solve(sudoku, x + 1, y)  # go to next cell
    else:
        for nr in range(1, 10):  # go through all the options
            if sudoku.canPut(x, y, nr):  # if the nr can be put
                sudoku.set(x, y, nr)  # set value
                solved = solve(sudoku, x + 1, y)  # go to next cell
                if solved:  # if solved
                    return True  # sudoku is solved, return
                else:  # otherwise
                    sudoku.set(x, y, 0)  # make the cell empty again
    # if we went through all the values it's a dead end
    return False  # go back to previous cell


board.init()

help = TextBox(x=board.width + 2, y=1, width=16, height=board.height)
help.message("")

sudoku = readFromFile('test.sdk')
board.show(sudoku)

start = time()
solve(sudoku, 0, 0)
end = time()
board.show(sudoku)

board.end()
print("time = {0}".format(end - start))
コード例 #2
0
ファイル: main.py プロジェクト: peTheProgrammer/Sudoku
                    if display:
                        board.setValue(x, y, 0)
            i.increment()  # next value
            if i.get() == nr:
                break
    elif solve(sudoku, x + 1, y, display,
               getStart):  #if cell is not empty, go to next cell
        return True
    return False


interval = .01
board.init()

prompt = TextBox(x=0, y=board.height + 1, width=board.width)
prompt.message("Enter Command:")

help = TextBox(x=board.width + 2, y=1, width=16, height=board.height)
help.message(help_message)

info = TextBox(x=board.width + 2,
               y=help.y + help.height,
               width=help.width,
               height=3)

sudoku = Sudoku()
board.show(sudoku)

while 1:
    cursor.goto(prompt.x, prompt.y + 1)
    cursor.writeStringToCursorPos(" " * 20)