Esempio n. 1
0
def solve_puzzle():
    print(request.json)
    print(request.json['board'])
    # params = request.json.to_dict()
    # print(params)
    board = request.json['board']
    sp = SudokuPuzzle(board)
    ss = SudokuSolver(sp)
    ss.do_work()
    log = ss.sudoku_logger.sudoku_log
    try:
        return jsonify({'board': ss.sudoku_puzzle.get_board(), 'steps_log': log})
    except Exception as e:
        print(e)
Esempio n. 2
0
def main():
    # board = save_and_get_new_board(4)
    # print(board)
    # board = read_saved_board(11)
    board = [
        [None, None, 7, 4, None, None, 3, None, None],
        [None, None, None, None, 7, None, None, None, 8],
        [9, 2, None, None, None, None, None, None, None],
        [6, None, None, 9, 1, 3, 8, None, 2],
        [None, 8, 3, None, None, 4, 6, None, None],
        [2, None, None, 8, None, None, None, None, None],
        [3, None, 8, 1, None, None, None, None, None],
        [None, 9, None, 3, None, None, None, None, 4],
        [1, None, None, None, None, 6, None, None, None]
    ]
    sp = SudokuPuzzle(board)
    # sp.print_board()

    ss = SudokuSolver(sp)
    ss.do_work()
Esempio n. 3
0
def solve_puzzle():
    try:
        board = request.json['board']
        puzzle_name = request.json['puzzleName']
        # Check if the puzzle has a solution
        validate_puzzle(puzzle_name, board)

        sp = SudokuPuzzle(board)
        ss = SudokuSolver(sp)
        ss.do_work()
        log = ss.sudoku_logger.sudoku_log
        return jsonify({
            'success': True,
            'board': ss.sudoku_puzzle.get_board(),
            'steps_log': log
        })
    except Exception as e:
        print(e)
        return jsonify({
            'success': False
        })
Esempio n. 4
0
def get_solution(puzzle_name, board):
    print("ACTUALLY SOLVING")
    sp = SudokuPuzzle(board)
    ss = SudokuSolver(sp)
    ss.do_work()
    return ss.sudoku_puzzle.get_board()