def get_chess(self,x,y): #得到(x,y)位置处的棋子状态 postion_x, postion_y = self.get_chess_postion(x, y) chess_color=self._screen.get_color(postion_x,postion_y) # mouse.smooth_move(postion_x, postion_y) # print (x,y,chess_color) rgb_color=color.hex_to_rgb(chess_color) chess=NO_CHESS if rgb_color[0]<100: chess=BLACK_CHESS elif rgb_color[0]==rgb_color[1] and rgb_color[1]==rgb_color[2]: chess=WHITE_CHESS return chess
def get_drops(self, i, j): #pos_list数组存放4、3、2、1滴水的位置相对坐标 pos_list = [(35, 55), (30, 5), (48, 25), (30, 25)] #计算第j行第i列的格子原点(格子左上角的屏幕坐标) grid_x = self.offset_x + self.grid_length * i grid_y = self.offset_y + self.grid_length * j for index, (x, y) in enumerate(pos_list): #获取格子原点加上相对坐标后的点的颜色值 color_value = self.screen.get_color(grid_x + x, grid_y + y) r, g, b = color.hex_to_rgb(color_value) #如果该点是水滴的颜色就返回水滴数 if r < 0x70 and g > 0xA0: return 4 - index return 0
def getGem(self, bmp, point): absPt = self.boardToAbsPt(point) halfSize = 5 total = 0 totalColor = RGB() for x in range(absPt.x - halfSize, absPt.x + halfSize): for y in range(absPt.y - halfSize, absPt.y + halfSize): hexColor = bmp.get_color(x, y) r, g, b = color.hex_to_rgb(hexColor) rgb = RGB(r, g, b) totalColor += rgb total += 1 avgRGB = totalColor / total gemColor = self.RGBToGem(avgRGB) return Gem(gemColor, 'status', point)
def pixel(self, x, y): from autopy import color, screen response = color.hex_to_rgb(screen.get_color(x, y)) return response