예제 #1
0
def find_hinged_quads(pboard, max_length):
    ''' written to support any length hinged match... I will only call it for size 4 though '''
    keys = find_keys(pboard, max_length)
    for key in keys:
        #log(0, "the key is " + str(key))
        key_seen_coords = seen_coords(pboard, key)
        corners = []
        for coord in key_seen_coords:
            y, x = coord[0], coord[1]
            if 2 <= len(pboard[y][x]) <= max_length:
                corners.append(coord)
        if len(corners) >= max_length - 1:
            cornersets = create_set_iterable(max_length - 1, len(corners))
            for cornerset in cornersets:
                #log(0, cornerset)
                possibilities = set()
                real_corners = [key]
                for i in cornerset:
                    real_corners.append(corners[i])
                #log(0, real_corners)
                for corner in real_corners:
                    for num in pboard[corner[0]][corner[1]]:
                        possibilities.add(num)
                if len(possibilities) == max_length:
                    #log(0, possibilities)
                    not_restricted_nums = find_non_restricted_nums(
                        pboard, possibilities, real_corners)
                    if not_restricted_nums:
                        things_to_trim = find_common_coord(
                            pboard, not_restricted_nums)
                        if things_to_trim:
                            trim_and_report(pboard, things_to_trim,
                                            real_corners, max_length, key)
                            return True
    return False
예제 #2
0
def find_hinged_quads(pboard, max_length):
    ''' written to support any length hinged match... I will only call it for size 4 though '''
    keys = find_keys(pboard, max_length)
    for key in keys:
        #log(0, "the key is " + str(key))
        key_seen_coords = seen_coords(pboard, key)
        corners = []
        for coord in key_seen_coords:
            y, x = coord[0], coord[1]
            if 2 <= len(pboard[y][x]) <= max_length:
                corners.append(coord)
        if len(corners) >= max_length - 1:
            cornersets = create_set_iterable(max_length - 1, len(corners))
            for cornerset in cornersets:
                #log(0, cornerset)
                possibilities = set()
                real_corners = [key]
                for i in cornerset:
                    real_corners.append(corners[i])
                #log(0, real_corners)
                for corner in real_corners:
                    for num in pboard[corner[0]][corner[1]]:
                        possibilities.add(num)
                if len(possibilities) == max_length:
                    #log(0, possibilities)
                    not_restricted_nums = find_non_restricted_nums(pboard, possibilities, real_corners)
                    if not_restricted_nums:
                        things_to_trim = find_common_coord(pboard, not_restricted_nums)
                        if things_to_trim:
                            trim_and_report(pboard, things_to_trim, real_corners, max_length, key)
                            return True
    return False
예제 #3
0
def hinged_match(board, pboard):
    keys = find_keys(pboard)
    if keys:
        for key in keys:
            corners = find_corners(pboard, key)
            if corners:
                unique_sets = create_set_iterable(2, len(corners))
                for unique_set in unique_sets:
                    real_corners = []
                    for num in unique_set:
                        real_corners.append(corners[num])
                    shared_nums = validate_corners(pboard, key, real_corners)
                    if shared_nums:
                        corner1seen = seen_coords(pboard, real_corners[0])
                        corner2seen = seen_coords(pboard, real_corners[1])
                        keyseen = seen_coords(pboard, key)
                        allseen = corner1seen & corner2seen & keyseen
                        trimmed = []
                        for shared_num in shared_nums[0]:
                            for coord in allseen:
                                if shared_num in pboard[coord[0]][coord[1]]:
                                    pboard[coord[0]][coord[1]].remove(shared_num)
                                    trimmed.append((coord, shared_num))
                                    # log(0, key)
                                    # log(0, real_corners)
                                    # log(0, coord)
                                    #return
                        if trimmed:
                            msg = " because its seen by every member of the hinged match"
                            trim_cleanup(pboard, key, real_corners, shared_nums[1], trimmed, msg)
                            return True
    return False
예제 #4
0
def hinged_match(board, pboard):
    keys = find_keys(pboard)
    if keys:
        for key in keys:
            corners = find_corners(pboard, key)
            if corners:
                unique_sets = create_set_iterable(2, len(corners))
                for unique_set in unique_sets:
                    real_corners = []
                    for num in unique_set:
                        real_corners.append(corners[num])
                    shared_nums = validate_corners(pboard, key, real_corners)
                    if shared_nums:
                        corner1seen = seen_coords(pboard, real_corners[0])
                        corner2seen = seen_coords(pboard, real_corners[1])
                        keyseen = seen_coords(pboard, key)
                        allseen = corner1seen & corner2seen & keyseen
                        trimmed = []
                        for shared_num in shared_nums[0]:
                            for coord in allseen:
                                if shared_num in pboard[coord[0]][coord[1]]:
                                    pboard[coord[0]][coord[1]].remove(
                                        shared_num)
                                    trimmed.append((coord, shared_num))
                                    # log(0, key)
                                    # log(0, real_corners)
                                    # log(0, coord)
                                    #return
                        if trimmed:
                            msg = " because its seen by every member of the hinged match"
                            trim_cleanup(pboard, key, real_corners,
                                         shared_nums[1], trimmed, msg)
                            return True
    return False
예제 #5
0
def related_trips(board, pboard):
    any_trim = False
    for x_type in range(3):
        for line in LINES[x_type]:
            proper_len_cells = []
            full_line_coords = get_coord_list(line, x_type)
            for coord in full_line_coords:
                y, x = coord[0], coord[1]
                if 2 <= len(pboard[y][x]) <= 3:
                    proper_len_cells.append(coord)
            if len(proper_len_cells) >= 3:
                unique_sets = create_set_iterable(3, len(proper_len_cells))
                for unique_set in unique_sets:
                    poss_set = set()
                    matched_coords = []
                    for num in unique_set:
                        y, x = proper_len_cells[num][0], proper_len_cells[num][
                            1]
                        for poss in pboard[y][x]:
                            poss_set.add(poss)
                            matched_coords.append((y, x))
                    # I found a naked triplicate
                    if len(poss_set) == 3:
                        trimmed = []
                        #cleanup the current line
                        line_trim(pboard, full_line_coords, matched_coords,
                                  trimmed, poss_set)
                        #check if all matched coords are in the same square
                        if x_type == 0 or x_type == 1:
                            square_coords = get_coord_list(
                                matched_coords[0], 2)
                            is_same_square = True
                            for coord in matched_coords:
                                if coord not in square_coords:
                                    is_same_square = False
                            #cleanup the rest of the square
                            if is_same_square:
                                line_trim(pboard, square_coords,
                                          matched_coords, trimmed, poss_set)
                        if trimmed:
                            trim_cleanup(pboard, matched_coords, trimmed)
                            return True
    return any_trim
예제 #6
0
def related_trips(board, pboard):
    any_trim = False
    for x_type in range(3):
        for line in LINES[x_type]:
            proper_len_cells = []
            full_line_coords = get_coord_list(line, x_type)
            for coord in full_line_coords:
                y, x = coord[0], coord[1]
                if 2 <= len(pboard[y][x]) <= 3:
                    proper_len_cells.append(coord)
            if len(proper_len_cells) >= 3:
                unique_sets = create_set_iterable(3, len(proper_len_cells))
                for unique_set in unique_sets:
                    poss_set = set()
                    matched_coords = []
                    for num in unique_set:
                        y, x = proper_len_cells[num][0], proper_len_cells[num][1]
                        for poss in pboard[y][x]:
                            poss_set.add(poss)
                            matched_coords.append((y, x))
                    # I found a naked triplicate
                    if len(poss_set) == 3:
                        trimmed = []
                        #cleanup the current line
                        line_trim(pboard, full_line_coords, matched_coords, trimmed, poss_set)
                        #check if all matched coords are in the same square
                        if x_type == 0 or x_type == 1:
                            square_coords = get_coord_list(matched_coords[0], 2)
                            is_same_square = True
                            for coord in matched_coords:
                                if coord not in square_coords:
                                    is_same_square = False
                            #cleanup the rest of the square
                            if is_same_square:
                                line_trim(pboard, square_coords, matched_coords, trimmed, poss_set)
                        if trimmed:
                            trim_cleanup(pboard, matched_coords, trimmed)
                            return True
    return any_trim
예제 #7
0
def look_for_matches_from_dict(coord_dict, x_length):
    ''' returns a list of numbers that constitute a hidden match '''
    possible_list = []
    matches = []
    for entry in coord_dict:
        if 2 <= len(coord_dict[entry]) <= x_length:
            possible_list.append(entry)
    if len(possible_list) >= x_length:
        unique_sets = create_set_iterable(x_length, len(possible_list))
        for unique_set in unique_sets:
            # make a list of my hidden match for easier lookup later
            hidden_match = []
            hidden_match_coord_set = set()
            for i in unique_set:
                hidden_match.append(possible_list[i])
            for number in hidden_match:
                for d_coord in coord_dict[number]:
                    hidden_match_coord_set.add(d_coord)
            if len(hidden_match_coord_set) == x_length:
                matches.append([hidden_match_coord_set, hidden_match])
    if len(matches) > 0:
        return matches
    else:
        return False
예제 #8
0
def look_for_matches_from_dict(coord_dict, x_length):
    ''' returns a list of numbers that constitute a hidden match '''
    possible_list = []
    matches = []
    for entry in coord_dict:
        if 2 <= len(coord_dict[entry]) <= x_length:
            possible_list.append(entry)
    if len(possible_list) >= x_length:
        unique_sets  = create_set_iterable(x_length, len(possible_list))
        for unique_set in unique_sets:
            # make a list of my hidden match for easier lookup later
            hidden_match = []
            hidden_match_coord_set = set()
            for i in unique_set:
                hidden_match.append(possible_list[i])
            for number in hidden_match:
                for d_coord in coord_dict[number]:
                    hidden_match_coord_set.add(d_coord)
            if len(hidden_match_coord_set) == x_length:
                matches.append([hidden_match_coord_set, hidden_match])
    if len(matches) > 0:
        return matches
    else:
        return False