def case(cls, c: Case, full) -> Case: assert c.shape[0] > 2 and c.shape[1] > 2 new_case = c.copy() if c.color_delete is None: new_values = cls.array(c.repr_values(), c.background_color, full) else: new_values = cls.array(c.repr_values(), c.color_delete, full) new_case.matter_list = [ Matter(new_values, background_color=c.background_color, new=True) ] return new_case
def case_col(cls, c: Case) -> Case: new_case = c.copy() if c.color_delete is None: new_values = cls.auto_fill_symmetry_col_background(c.repr_values()) else: new_values = cls.auto_fill_symmetry_col(c.repr_values(), c.color_delete) new_case.matter_list = [ Matter(new_values, background_color=c.background_color, new=True) ] return new_case
def case_assert(cls, c_x: Case, c_y: Case, color=False): # color if color: color_x = c_x.color_count() color_y = c_y.color_count() flag_color = True for color_ in range(10): if color_ == c_x.background_color: continue if color_x[color_] != color_y[color_] != 0: flag_color = False if flag_color: return True, True # simply keep y_values = c_y.repr_values() if c_x.shape == c_y.shape: for m in c_x.matter_list: if (m.values == y_values[m.x0:m.x0 + m.shape[0], m.y0:m.y0 + m.shape[1]]).min(): pass elif (c_x.background_color == y_values[m.x0:m.x0 + m.shape[0], m.y0:m.y0 + m.shape[1]]).min(): pass else: return False, False return True, False return False, False
def case_row_col(cls, c: Case) -> Case: new_case = c.copy() new_values = cls.auto_fill_row_col(c.repr_values(), c.background_color) new_case.matter_list = [ Matter(new_values, background_color=c.background_color, new=True) ] return new_case
def case_assert(cls, c_x: Case, c_y: Case): assert len(c_x.matter_list) > 1 res_values = c_y.repr_values() for m in c_x.matter_list: if m.shape == res_values.shape: if (m.values == res_values).min(): return True return False
def case(cls, c_x: Case, pattern_arr: np.array) -> Case: x_values = c_x.repr_values() if c_x.color_delete is None: new_x_values = cls.array(x_values, pattern_arr, c_x.background_color) else: new_x_values = cls.array(x_values, pattern_arr, c_x.color_delete) new_case: Case = c_x.copy() new_case.matter_list = [Matter(new_x_values, new=True)] return new_case
def case_create_flag(cls, c_x: Case, c_y: Case): res_list = [] res_values = c_y.repr_values() for m in c_x.matter_list: if m.shape == res_values.shape: if (m.values == res_values).min(): res_list.append(True) else: res_list.append(False) else: res_list.append(False) return res_list
def case(cls, c: Case) -> Case: if c.color_delete is not None: new_case = c.copy() new_values = fill_somewhere(c.repr_values(), c.color_delete) new_case.matter_list = [ Matter(new_values, background_color=c.background_color, new=True) ] return new_case else: return c
def case_xy(cls, c_x: Case, c_y: Case) -> dict: temp_c_x = c_x.copy() temp_c_x.matter_list = [cls.matter_temp(m) for m in c_x.matter_list] x_repr = temp_c_x.repr_values() y_repr = c_y.repr_values() assert x_repr.shape == y_repr.shape res_dict = dict() for v in np.unique(x_repr): if v >= 10: new_w = np.unique(y_repr[x_repr == v]) # print(x_repr, y_repr, new_w) assert new_w.shape[0] == 1 res_dict[v - 10] = new_w[0] return res_dict
def case_create_flag(cls, c_x: Case, c_y: Case, color=False): res_list = [] # color if color: color_y = c_y.color_count() for m in c_x.matter_list: if color_y[m.max_color()] > 0: res_list.append(True) else: res_list.append(False) return res_list # normal else: y_values = c_y.repr_values() for m in c_x.matter_list: if (m.values == y_values[m.x0:m.x0 + m.shape[0], m.y0:m.y0 + m.shape[1]]).min(): res_list.append(True) elif (c_x.background_color == y_values[m.x0:m.x0 + m.shape[0], m.y0:m.y0 + m.shape[1]]).min(): res_list.append(False) return res_list