本文整理汇总了Python中solver.Solver.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.is_valid方法的具体用法?Python Solver.is_valid怎么用?Python Solver.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solver.Solver
的用法示例。
在下文中一共展示了Solver.is_valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_valid_return_false_when_two_of_same_number_in_block
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
def test_is_valid_return_false_when_two_of_same_number_in_block(self):
puzzle = [
[
Square(1,1,1,1),
Square(None,1,2,1),
Square(None,1,3,2),
Square(None,1,4,2)
],
[
Square(None,2,1,1),
Square(1,2,2,1),
Square(None,2,3,2),
Square(None,2,4,2)
],
[
Square(None,3,1,3),
Square(None,3,2,3),
Square(None,3,3,4),
Square(None,3,4,4)
],
[
Square(None,4,1,3),
Square(None,4,2,3),
Square(None,4,3,4),
Square(None,4,4,4)
]
]
solver = Solver()
self.assertFalse(solver.is_valid(puzzle))
示例2: test_is_valid
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
def test_is_valid(self):
puzzle = [
[
Square(1,1,1,1),
Square(4,1,2,1),
Square(3,1,3,2),
Square(2,1,4,2)
],
[
Square(3,2,1,1),
Square(2,2,2,1),
Square(4,2,3,2),
Square(1,2,4,2)
],
[
Square(4,3,1,3),
Square(1,3,2,3),
Square(2,3,3,4),
Square(3,3,4,4)
],
[
Square(2,4,1,3),
Square(3,4,2,3),
Square(1,4,3,4),
Square(4,4,4,4)
]
]
solver = Solver()
self.assertTrue(solver.is_valid(puzzle))
示例3: len
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import is_valid [as 别名]
import sys
from solver import Solver
from file_reader import FileReader
if len(sys.argv) != 2:
print("Please specify a puzzle file to solve.")
sys.exit(0)
filename = sys.argv[1]
file_reader = FileReader()
puzzle = file_reader.get_puzzle_from_file(filename)
solver = Solver()
if solver.is_valid(puzzle):
print('Okay, I can solve this.')
solution = solver.solve(puzzle)
for row in solution:
for square in row:
print(str(square.number) + ' ', end='')
print('\n', end='')
else:
print('This puzzle is invalid.')