def __init__(self, m: Matter, ind: int, hash_count: int): self.a_init = m.a self.n_color = m.n_color() self.n_cell = m.n_cell() self.size = m.shape[0] * m.shape[1] self.is_filled_rectangle = m.is_filled_rectangle() if m.is_filled_rectangle(): if m.is_square(): self.is_rectangle = 2 else: self.is_rectangle = 1 else: if m.a is not None: self.is_rectangle = 0 else: self.is_rectangle = None # assume trimmed x_arr = m.values # row res_row = 0 for i in range(x_arr.shape[0] // 2): res_row += (x_arr[i, :] != x_arr[x_arr.shape[0] - 1 - i, :]).sum() # col res_col = 0 for j in range(x_arr.shape[1] // 2): res_col += (x_arr[:, j] != x_arr[:, x_arr.shape[1] - 1 - j]).sum() res = 0 if res_row == 0: res += 1 if res_col == 0: res += 2 self.is_symmetry = res self.ind = ind self.hash = hash_count self.n_noise = (m.values != m.max_color()).sum() self.a = None self.y = None
def matter(cls, m: Matter, hole_type: str) -> Matter: if m.is_filled_rectangle() and min(m.shape) >= 3: new_matter = m.copy() new_values = m.values.copy() if hole_type == "simple": new_values[1:-1, 1:-1] = m.background_color elif hole_type == "mesh": new_values[1:-1:2, 1:-1:2] = m.background_color elif hole_type == "mesh_x": new_values[1:-1:2, 1:-1:2] = m.background_color new_values[2:-1:2, 2:-1:2] = m.background_color else: raise NotImplementedError new_matter.set_values(new_values) return new_matter else: return m
def matter(cls, m: Matter) -> bool: if m.is_filled_rectangle() and min(m.shape) >= 3: return True else: return False