From 8d0d94ad0a5f59b334e322cd7356f432790e3ef7 Mon Sep 17 00:00:00 2001 From: Jack Grahl Date: Sat, 11 Nov 2023 17:31:10 +0000 Subject: [PATCH] Catch NoSolution - exact_cover now throws. --- polyomino/problem.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/polyomino/problem.py b/polyomino/problem.py index 9c40c4a..5e4c9e2 100644 --- a/polyomino/problem.py +++ b/polyomino/problem.py @@ -1,6 +1,7 @@ import numpy as np from exact_cover import get_exact_cover +from exact_cover.error import NoSolution from .error import CantPlaceSinglePiece from .solution import Solution @@ -60,7 +61,10 @@ def make_problem(self): def solve(self): self.make_problem() - solution = get_exact_cover(self.array) + try: + solution = get_exact_cover(self.array) + except NoSolution: + return None tiling = [self.key[s] for s in solution] if tiling: return Solution(tiling, self.board)