def find(self, board, do_all = False):
        solved_sets = []
        possible = [has_count(has_size(board.get_row(i),2,None), 2, 4) for i in range(board.N) ]
        jellyfish = [(k1,v1+v2+v3+v4) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k,p3 in enumerate(possible) for l,p4 in enumerate(possible) \
                      for k1,v1 in p1.items() for k2,v2 in p2.items() for k3,v3 in p3.items() for k4,v4 in p4.items() if p1 and p2 and p3 and p4 and l > k > j > i \
                      and k1 == k2 == k3 == k4 and len(set([c1.j for c1 in v1] + [c2.j for c2 in v2] + [c3.j for c3 in v3] + [c4.j for c4 in v4])) == 4]
        for candidate, jellyfish_cells in jellyfish:
            removed = []
            for col in set([cell.j for cell in jellyfish_cells]):
                removed += [cell for cell in board.get_col(col) if cell not in jellyfish_cells and cell.check_remove(set([candidate]))]
            if removed:
                solved_sets += [SolvedSet(JellyFishSolver(0,1), jellyfish_cells, set([candidate]), removed)]
                if not do_all:
                    return solved_sets      

        possible = [has_count(has_size(board.get_col(i),2,None), 2, 4) for i in range(board.N) ]
        jellyfish = [(k1,v1+v2+v3+v4) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k,p3 in enumerate(possible) for l,p4 in enumerate(possible) \
                      for k1,v1 in p1.items() for k2,v2 in p2.items() for k3,v3 in p3.items() for k4,v4 in p4.items() if p1 and p2 and p3 and p4 and l > k > j > i \
                      and k1 == k2 == k3 == k4 and len(set([c1.i for c1 in v1] + [c2.i for c2 in v2] + [c3.i for c3 in v3] + [c4.i for c4 in v4])) == 4]
        for candidate, jellyfish_cells in jellyfish:
            removed = []
            for row in set([cell.i for cell in jellyfish_cells]):
                removed = [cell for cell in board.get_row(row) if cell not in jellyfish_cells and cell.check_remove(set([candidate]))]
            if removed:
                solved_sets += [SolvedSet(JellyFishSolver(0,2), jellyfish_cells, set([candidate]), removed)]
                if not do_all:
                    return solved_sets
        return solved_sets
    def find(self, board, do_all=False):
        solved_sets = []
        for i in range(board.N):
            possible = has_size(board.get_box(i), 2, None)
            for candidate, cells in has_count(possible, self.level, self.level).items():
                if all([cell.i == cells[0].i for cell in cells]):
                    removed_cells = [
                        cell
                        for cell in board.get_row(cells[0].i)
                        if not cell.answer and cell not in cells and cell.check_remove(set([candidate]))
                    ]
                    if removed_cells:
                        solved_sets += [
                            SolvedSet(PointingSolver(self.level, 1), cells, set([candidate]), removed_cells)
                        ]
                        if not do_all:
                            return solved_sets

                if all([cell.j == cells[0].j for cell in cells]):
                    removed_cells = [
                        cell
                        for cell in board.get_col(cells[0].j)
                        if not cell.answer and cell not in cells and cell.check_remove(set([candidate]))
                    ]
                    if removed_cells:
                        solved_sets += [
                            SolvedSet(PointingSolver(self.level, 2), cells, set([candidate]), removed_cells)
                        ]
                        if not do_all:
                            return solved_sets

        return solved_sets
    def find(self, board, do_all = False):
        solved_sets = []
        possible = [has_count(has_size(board.get_row(i),2,None), 2, 3) for i in range(board.N) ]
        swordfish = [(k1,v1+v2+v3) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k,p3 in enumerate(possible) for k1,v1 in p1.items() for k2,v2 in p2.items() for k3,v3 in p3.items() if p1 and p2 and p3 and k > j > i and k1 == k2 == k3 and len(set([c1.j for c1 in v1])|set([c2.j for c2 in v2])|set([c3.j for c3 in v3])) == 3]
        for candidate, swordfish_cells in swordfish:
            for col in set([cell.j for cell in swordfish_cells]):
                removed = [cell for cell in board.get_col(col) if cell not in swordfish_cells and cell.check_remove(set([candidate]))]
                if removed:
                    solved_sets += [SolvedSet(SwordFishSolver(0,1), swordfish_cells, set([candidate]), removed)]
                    if not do_all:
                        return solved_sets

        possible = [has_count(has_size(board.get_col(j),2,None), 2, 3) for j in range(board.N) ]
        swordfish = [(k1,v1+v2+v3) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k,p3 in enumerate(possible) for k1,v1 in p1.items() for k2,v2 in p2.items() for k3,v3 in p3.items() if p1 and p2 and p3 and k > j > i and k1 == k2 == k3 and len(set([c1.i for c1 in v1])|set([c2.i for c2 in v2])|set([c3.i for c3 in v3])) == 3]
        for candidate, swordfish_cells in swordfish:
            for row in set([cell.i for cell in swordfish_cells]):
                removed = [cell for cell in board.get_row(row) if cell not in swordfish_cells and cell.check_remove(set([candidate]))]
                if removed:
                    solved_sets += [SolvedSet(SwordFishSolver(0,2), swordfish_cells, set([candidate]), removed)]
                    if not do_all:
                        return solved_sets
        return solved_sets
Exemple #4
0
 def find(self, board, do_all = False):
     solved_sets = []
     possible = [has_count(has_size(board.get_row(i),2,None), 2, 2) for i in range(board.N) ]
     xwings = [(k1,v1+v2) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k1,v1 in p1.items() for k2,v2 in p2.items() if p1 and p2 and j > i and k1 == k2 and len(set([c1.j for c1 in v1])|set([c2.j for c2 in v2])) == 2]
     for candidate, xwing_cells in xwings:
         for col in set([cell.j for cell in xwing_cells]):
             removed = [cell for cell in board.get_col(col) if cell not in xwing_cells and cell.check_remove(set([candidate]))]
             if removed:
                 solved_sets += [SolvedSet(XWingSolver(0,1), xwing_cells, set([candidate]), removed)]
                 if not do_all:
                     return solved_sets
                 
     possible = [has_count(has_size(board.get_col(j),2,None), 2, 2) for j in range(board.N) ]
     xwings = [(k1,v1+v2) for i,p1 in enumerate(possible) for j,p2 in enumerate(possible) for k1,v1 in p1.items() for k2,v2 in p2.items() if p1 and p2 and j > i and k1 == k2 and all([c2.j in set([c1.j for c1 in v1]) for c2 in v2])]
     for candidate, xwing_cells in xwings:
         for row in set([cell.i for cell in xwing_cells]):
             removed = [cell for cell in board.get_row(row) if cell not in xwing_cells and cell.check_remove(set([candidate]))]
             if removed:
                 solved_sets += [SolvedSet(XWingSolver(0,2), xwing_cells, set([candidate]), removed)]
                 if not do_all:
                     return solved_sets
     return solved_sets