예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #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
예제 #5
0
 def find_in_list(self, cell_list):
     possible = has_size(cell_list, 2, self.level)
     found = []
     if len(possible) >= self.level:
         if self.level == 2:
             found = [(a,b) for i,a in enumerate(possible) for j,b in enumerate(possible) if j > i and len(a.c|b.c) == 2]
         if self.level == 3:
             found = [(a,b,c) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) if k > j > i and len(a.c|b.c|c.c) == 3]
         if self.level == 4:
             found = [(a,b,c,d) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) for l,d in enumerate(possible) if l > k > j > i and len(a.c|b.c|c.c|d.c) == 4]
         if self.level == 5:
             found = [(a,b,c,d,e) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) for l,d in enumerate(possible) for m,e in enumerate(possible) if m > l > k > j > i and len(a.c|b.c|c.c|d.c|e.c) == 5]
     return found
예제 #6
0
 def find_in_list(self, cell_list):
     possible = has_size(cell_list, 2, None)
     found = []
     if len(possible) >= self.level:
         if self.level == 1:
             found = [(a,) for i,a in enumerate(possible) if len(a.c - cell_union(cell_list, exceptions=(a,))) == 1]
         if self.level == 2:
             found = [(a,b) for i,a in enumerate(possible) for j,b in enumerate(possible) if j > i and len(a.c&b.c - cell_union(cell_list, exceptions=(a,b))) == 2]
         if self.level == 3:
             found = [(a,b,c) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) if k > j > i and len(a.c&b.c&c.c - cell_union(cell_list, exceptions=(a,b,c))) == 3]
         if self.level == 4:
             found = [(a,b,c,d) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) for l,d in enumerate(possible) if l > k > j > i and len(a.c&b.c&c.c&d.c - cell_union(cell_list, exceptions=(a,b,c,d))) == 4]
         if self.level == 5:
             found = [(a,b,c,d,e) for i,a in enumerate(possible) for j,b in enumerate(possible) for k,c in enumerate(possible) for l,d in enumerate(possible) for m,e in enumerate(possible) if m > l > k > j > i and len(a.c&b.c&c.c&d.c&e.c - cell_union(cell_list, exceptions=(a,b,c,d,e))) == 5]
     return found
예제 #7
0
 def find(self, board, do_all=False):
     solved_sets = []
     possible = has_size(board.as_list(), 2, 2)
     ywings = [
         (pivot, cell1, cell2)
         for i, cell1 in enumerate(possible)
         for j, cell2 in enumerate(possible)
         for pivot in visible_intersection(board, [cell1, cell2])
         if j > i and pivot.c == cell1.c ^ cell2.c and len(cell1.c & cell2.c) == 1
     ]
     for pivot, cell1, cell2 in ywings:
         remove = [
             cell
             for cell in visible_intersection(board, [cell1, cell2])
             if cell != pivot and cell.check_remove(cell1.c & cell2.c)
         ]
         if remove:
             solved_sets += [SolvedSet(self, [pivot, cell1, cell2], cell1.c & cell2.c, remove)]
             if not do_all:
                 return solved_sets
     return solved_sets