def test_basic_detection(self): bitmap = autopy.bitmap.Bitmap.open("sample_images/board1.png") x, y = get_position(bitmap) # throws board.NotVisible if no position # since the board positioning is imprecise, we just assert a range self.assertGreater(x, 268) self.assertLess(x, 272) self.assertGreater(y, 100) self.assertLess(y, 105)
def move_to_jewel(bitmap, x, y): """Move the cursor to the centre of a jewel on the Bejeweled grid. # e.g. put mouse in the centre of the top-left jewel: >>> move_to_jewel(0, 0) """ board_x, board_y = board.get_position(bitmap) target_x = int(board_x + (x + 0.5) * board.ELEMENT_WIDTH_PX) target_y = int(board_y + (y + 0.5) * board.ELEMENT_HEIGHT_PX) autopy.mouse.move(target_x, target_y)
def get_jewel_bitmaps(screen_bitmap): x, y = board.get_position(screen_bitmap) rows = [] # every row for i in range(board.SIZE): row = [] # every jewel in that row for j in range(board.SIZE): jewel_position = (x + board.ELEMENT_WIDTH_PX * j, y + board.ELEMENT_HEIGHT_PX * i) jewel_bitmap = screen_bitmap.get_portion( jewel_position, (board.ELEMENT_WIDTH_PX, board.ELEMENT_HEIGHT_PX)) row.append(jewel_bitmap) rows.append(row) return rows
def test_snow_board_detection(self): bitmap = autopy.bitmap.Bitmap.open("sample_images/board_snow.png") get_position(bitmap) # throws board.NotVisible if no position
def test_darker_board_detection(self): bitmap = autopy.bitmap.Bitmap.open("sample_images/board_dark_background.png") get_position(bitmap) # throws board.NotVisible if no position