本文整理汇总了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
示例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