1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
| def cal_all_x(self, End=False, action=False): if End: return else: End=True for x_len in range(1, 16): for y_len in range(1, 10): for begin_x in range(0, 16-x_len+1): for begin_y in range(0, 10-y_len+1): _sum = np.sum(self.cal_matrix[begin_x:begin_x+x_len,begin_y: begin_y + y_len]) if _sum == 10: self.cal_matrix[begin_x:begin_x+x_len,begin_y: begin_y + y_len] = 0 if action: self.action(begin_x, begin_x+x_len, begin_y, begin_y + y_len) End = False self.cal_all_x(End=End, action=action) def cal_all_y(self, End=False, action=False): if End: return else: End=True for y_len in range(1, 10): for x_len in range(1, 16): for begin_x in range(0, 16-x_len+1): for begin_y in range(0, 10-y_len+1): _sum = np.sum(self.cal_matrix[begin_x:begin_x+x_len,begin_y: begin_y + y_len]) if _sum == 10: self.cal_matrix[begin_x:begin_x+x_len,begin_y: begin_y + y_len] = 0 if action: self.action(begin_x, begin_x+x_len, begin_y, begin_y + y_len) End = False self.cal_all_y(End=End, action=action)
def cal_two_x(self, End=False, action=False): if End: return else: End=True for begin_x in range(0, 16): for begin_y in range(0, 10): # 搜索右边 if self.cal_matrix[begin_x, begin_y] ==0: continue if len(self.s1list) >0 and self.cal_matrix[begin_x, begin_y] not in self.s1list: continue for x in range(begin_x+1, 16): if self.cal_matrix[x, begin_y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[x, begin_y] ==10: self.cal_matrix[x, begin_y] = 0 self.cal_matrix[begin_x, begin_y] = 0 if action: self.action(begin_x, x+1, begin_y, begin_y+1) End = False break else: break # 搜索左边 for x in range(begin_x-1, -1, -1): if x < 0: break if self.cal_matrix[x, begin_y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[x, begin_y] ==10: self.cal_matrix[x, begin_y] = 0 self.cal_matrix[begin_x, begin_y] = 0 if action: self.action(x, begin_x+1, begin_y, begin_y+1) End = False break else: break # 搜索下面 for y in range(begin_y+1, 10): if self.cal_matrix[begin_x, y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[begin_x, y] ==10: self.cal_matrix[begin_x, begin_y] = 0 self.cal_matrix[begin_x, y] = 0 if action: self.action(begin_x, begin_x+1, begin_y, y+1) End = False break else: break # 搜索上面 for y in range(begin_y-1, -1, -1): if y < 0: break if self.cal_matrix[begin_x, y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[begin_x, y] ==10: self.cal_matrix[begin_x, begin_y] = 0 self.cal_matrix[begin_x, y] = 0 if action: self.action(begin_x, begin_x+1, y, begin_y+1) End = False break else: break self.cal_two_x(End=End, action=action) def cal_two_y(self, End=False, action=False): if End: return else: End=True for begin_y in range(0, 10): for begin_x in range(0, 16): # 搜索右边 if self.cal_matrix[begin_x, begin_y] ==0: continue if len(self.s1list) >0 and self.cal_matrix[begin_x, begin_y] not in self.s1list: continue for x in range(begin_x+1, 16): if self.cal_matrix[x, begin_y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[x, begin_y] ==10: self.cal_matrix[x, begin_y] = 0 self.cal_matrix[begin_x, begin_y] = 0 if action: self.action(begin_x, x+1, begin_y, begin_y+1) End = False break else: break # 搜索左边 for x in range(begin_x-1, -1, -1): if x < 0: break if self.cal_matrix[x, begin_y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[x, begin_y] ==10: self.cal_matrix[x, begin_y] = 0 self.cal_matrix[begin_x, begin_y] = 0 if action: self.action(x, begin_x+1, begin_y, begin_y+1) End = False break else: break # 搜索下面 for y in range(begin_y+1, 10): if self.cal_matrix[begin_x, y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[begin_x, y] ==10: self.cal_matrix[begin_x, begin_y] = 0 self.cal_matrix[begin_x, y] = 0 if action: self.action(begin_x, begin_x+1, begin_y, y+1) End = False break else: break # 搜索上面 for y in range(begin_y-1, -1, -1): if y < 0: break if self.cal_matrix[begin_x, y] ==0: continue elif self.cal_matrix[begin_x, begin_y]+self.cal_matrix[begin_x, y] ==10: self.cal_matrix[begin_x, begin_y] = 0 self.cal_matrix[begin_x, y] = 0 if action: self.action(begin_x, begin_x+1, y, begin_y+1) End = False break else: break self.cal_two_y(End=End, action=action)
|