def test_cycosat_simple(): sat = CoSAT() problem = [[1, -4], [1, -2], [1, 4], [-4, -2], [-4, 4], [-2, 4], [-1, 4, 2, -4]] sat.add_clauses(problem) assert sat.solve() == [1, -1, -1, -1]
def solve_step(self): rows, cols, numbers = capture_board() sat = CoSAT() vars_index = self.variables[rows, cols] self.opened = set(vars_index) for idx, num in zip(vars_index, numbers): sat.add_clauses(self.get_clauses(idx, num)) failed_assumes = sat.get_failed_assumes() vars_set = set(vars_index) to_click = [] self.mines.clear() for v in failed_assumes: if v > 0 and v not in vars_set: to_click.append(v) if v < 0: self.mines.add(-v) return to_click
def solve(self, cells): sat = CoSAT() sat.add_clauses(self.conditions) assumes = [self.bools[r, c, v-1] for (r, c), v in cells.iteritems()] solution = sat.assume_solve(assumes) if isinstance(solution, list): res = np.array(sat.solve()) mask = (res > 0).reshape(9, 9, 9) return (np.where(mask)[2]+1).reshape(9, 9) else: return None