Beispiel #1
0
def create_sudoku(filename):
    """Create a sudoku with handicap and save it to filename.

    The handicap are the extra numbers given.

    Arguments:
    filename -- the file name

    """
    while True:
        print _(u"Creating sudoku..."),
        sys.stdout.flush()

        sudoku = Sudoku(Board((options.getint("sudoku", "region_width"),
                               options.getint("sudoku", "region_height"))),
                        difficulty=options.get("sudoku", "difficulty"))
        sudoku.create(options.getint("sudoku", "handicap"))

        if options.getboolean("sudoku", "force") and \
           (difficulty(sudoku.to_board()) != options.get("sudoku",
                                                       "difficulty")):
            print _(u"sudoku with wrong difficulty!")
        else:
            sudoku.to_board().save(filename)
            print _(u"success!")
            break

    draw_board(sudoku.to_board())

    return True
Beispiel #2
0
def test_difficulty(filename):
    """Open a sudoku located in filename and get its the difficulty.

    Arguments:
    filename -- the file name

    """
    print _(u"The difficulty of the sudoku is..."),
    sys.stdout.flush()

    d = difficulty(Board(filename=filename))
    if d:
        print d
    else:
        print "unknown"