当前位置: 首页>>代码示例>>Python>>正文


Python Sudoku.to_board方法代码示例

本文整理汇总了Python中sudoku.Sudoku.to_board方法的典型用法代码示例。如果您正苦于以下问题:Python Sudoku.to_board方法的具体用法?Python Sudoku.to_board怎么用?Python Sudoku.to_board使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sudoku.Sudoku的用法示例。


在下文中一共展示了Sudoku.to_board方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: solve_sudoku

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import to_board [as 别名]
def solve_sudoku(filename, filename_out=None):
    """Open a sudoku located in filename and solve it.

    If filename_out is not None, the solved sudoku is saved.

    Arguments:
    filename -- the file name

    Keyword arguments:
    filename_out -- the output file name (default None)

    """
    board = Board(filename=filename)
    draw_board(board)

    print _(u"Solving sudoku..."),
    sys.stdout.flush()

    # Use all the algos
    sudoku = Sudoku(board, difficulty="hard")
    success = False
    if sudoku.solve():
        print _(u"success!")
        success = True
    else:
        print _(u"can't be solved!")

    draw_board(sudoku.to_board())

    if filename_out:
        sudoku.to_board().save(filename_out)

    return success
开发者ID:ternus,项目名称:arcnet,代码行数:35,代码来源:text.py

示例2: create_sudoku

# 需要导入模块: from sudoku import Sudoku [as 别名]
# 或者: from sudoku.Sudoku import to_board [as 别名]
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
开发者ID:ternus,项目名称:arcnet,代码行数:32,代码来源:text.py


注:本文中的sudoku.Sudoku.to_board方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。