def test_players_in_game5(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open(os.path.join(os.environ['test_src'], '5.png')) t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/players_in_game.png') t.get_players_in_game() t.get_dealer_position2() assert t.players_in_game == [0, 2, 5] assert t.dealer_position == 3
def test_table_and_my_cards11(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_src'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=1) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'QS', '8C', '5H', '8D'} # Miss 6H -> 8C
def test_preflop_nodelist9(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open(os.path.join(os.environ['test_src'], '19.png')) t.crop_from_top_left_corner2(select_table=2) if is_debug: t.screenshot.save('log/pics/active_player2.png') preflop_state_Zenith = CurrentHandPreflopStateZenith() h = History() preflop_state_Zenith.get_players_status(t) pytest.assume(preflop_state_Zenith.active_player_rel == None)
def test_table_and_my_cards58(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_src'], '20.png')) table_scraper.crop_from_top_left_corner2(select_table=4) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'7D', 'QC', 'JH', '7S', 'AH'} # Passed
def test_miss_player3(): # Not pass mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open( r"C:\Users\jinyi\source\repos\Project1\x64\Debug\screenshots\miss_player\sitting_out2.png" ) # t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/miss_player2.png') t.get_miss_player() assert t.miss_player == [4]
def test_table_and_my_cards10(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_src'], '1.png')) table_scraper.crop_from_top_left_corner2(select_table=2) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'QD', '6S', '3H', 'AD'} # Additional 8S
def test_table_and_my_cards24(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_test'], '4.png')) table_scraper.crop_from_top_left_corner2(select_table=1) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'KS', '3D', '4S', 'AS' } # Miss AS => Passed by resize
def test_table_and_my_cards30(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_test'], '5.png')) table_scraper.crop_from_top_left_corner2(select_table=4) table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == { '3C', '5C', '7S', '2D' } # Miss 3C, 5C => FIXED BY UPDATE SIZE
def test_ocr_pp2(): mongo = MongoManager() table_dict = mongo.get_table("PartyPoker 6 Players Fast Forward $1-$2 NL Hold'em") table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(get_dir('tests', 'screenshots'), '238170361_River_0.png')) table_scraper.crop_from_top_left_corner() result = ocr(table_scraper.screenshot, 'total_pot_area', table_scraper.table_dict) assert result == 0.05 result = ocr(table_scraper.screenshot, 'raise_value', table_scraper.table_dict) assert result == 0.02 result = ocr(table_scraper.screenshot, 'player_funds_area', table_scraper.table_dict, player='0') assert result == 1.44
def test_players_in_game11(): mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') t = TableScraper(table_dict) t.screenshot = Image.open( get_dir(os.path.join('log', 'pics', 'table_c_2.png'))) # t.crop_from_top_left_corner2(select_table=0) if is_debug: t.screenshot.save('log/pics/players_in_game.png') t.get_players_in_game() t.get_dealer_position2() assert t.players_in_game == [0, 1, 2, 3, 4, 5] assert t.dealer_position == 3
def test_ocr_value(): # ok! for total pot log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_TEST') table_scraper = TableScraper(table_dict) test_src = os.environ['test_src'] table_scraper.screenshot = Image.open(os.path.join(test_src, 'jinyi 0006.PNG')) screenshot = table_scraper.crop_from_top_left_corner() # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # ok! # plt.show() # Total pots test # ok!!! search_area = table_dict['total_pot_area'] cropped_screenshot = screenshot.crop((search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) total_pot = get_ocr_float(cropped_screenshot, 'total_pot_area') log.info(f"Total pot {total_pot}") # Current pot test # ok !!! current_round_pot = 0 search_area = table_dict['current_round_pot'] cropped_screenshot = screenshot.crop((search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) current_round_pot = get_ocr_float(cropped_screenshot, 'current_round_pot') log.info(f"Current round pot {current_round_pot}") # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # ok! # plt.show() # Player funds test player_funds = [] player_pots = [] for i in range(6): search_area = table_dict['player_funds_area'][str(i)] cropped_screenshot = screenshot.crop( (search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) funds = get_ocr_float(cropped_screenshot, 'player_funds_area') player_funds.append(funds) log.info(f"Player funds: {player_funds}") # Player pots test for i in range(6): search_area = table_dict['player_pot_area'][str(i)] cropped_screenshot = screenshot.crop( (search_area['x1'], search_area['y1'], search_area['x2'], search_area['y2'])) funds = get_ocr_float(cropped_screenshot, 'player_pot_area') player_pots.append(funds) # plt.imshow(cropped_screenshot, cmap='gray', interpolation='bicubic') # plt.show() log.info(f"Player pot: {player_pots}")
def test_label_pos0(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) prefix = 'b_16' table_scraper.screenshot = Image.open(get_dir(os.path.join('log', 'pics', 'table_' + prefix + '.png'))) for i in [0]: for j in [0]: # table_scraper.crop_from_top_left_corner2(select_table=0) if is_debug: file_name = get_dir(os.path.join('log', 'pics', 'table_label_pos_' + str(i) + '_' + str(j) + '.png')) """ Move table by delta_x = -8 , delta_y = -5 from config.ini """ save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name) return True
def test_table_and_my_cards64(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_4table'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=0) # config = get_config() # table_size = config['DEFAULT']['table_size'] # log.info(f'table_size:{table_size}') # scale_m = scale_cal(table_size, 'table_cards_area') # log.info(f'scale_m:{scale_m}') table_scraper.get_table_cards3() print(table_scraper.table_cards) assert set(table_scraper.table_cards) == {'4C', '6S', '4H', '7C', 'QD'}
def test_table_scraper(): mongo = MongoManager() table_dict = mongo.get_table("PartyPoker 6 Players Fast Forward $1-$2 NL Hold'em") table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(get_dir('tests', 'screenshots'), '173280759_PreFlop_0.png')) table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_table_scraper(): log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_TEST') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open(os.path.join(os.environ['test_src'], 'Capture6.PNG')) table_scraper.crop_from_top_left_corner() log.info(f"Is my turn?{table_scraper.is_my_turn()}") table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() # table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_all(self): """Test table button""" self.table_name = self.ui.table_name.currentText() from poker.scraper.recognize_table import TableScraper table_dict = mongo.get_table(table_name=self.table_name) table_scraper = TableScraper(table_dict) table_scraper.screenshot = self.original_screenshot table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button()
def test_table_scraper(): mongo = MongoManager() table_dict = mongo.get_table('default') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(get_dir('tests', 'screenshots'), 'screenshot1.png')) table_scraper.crop_from_top_left_corner() table_scraper.is_my_turn() table_scraper.lost_everything() table_scraper.get_my_cards2() table_scraper.get_table_cards2() table_scraper.get_dealer_position2() table_scraper.get_players_in_game() table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_call_value() table_scraper.get_raise_value() table_scraper.has_all_in_call_button() table_scraper.has_call_button() table_scraper.has_raise_button() table_scraper.get_game_number_on_screen2()
def test_ocr_value1(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_src'], '1.png')) table_scraper.crop_from_top_left_corner2(select_table=0) if is_debug: # table_scraper.screenshot.save('log/pics/table1.png') file_name = get_dir(os.path.join('log', 'pics', 'table_label.png')) save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name) table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_player_pots() assert table_scraper.total_pot == 12.5 assert table_scraper.player_funds == [23.0, 100.0, 42.0, 23.0, 97.5, 102.0] assert table_scraper.player_pots == [-1.0, -1.0, 6.0, -1.0, -1.0, -1.0]
def test_ocr_valu13(): # ok log = logging.getLogger(__name__) mongo = MongoManager() table_dict = mongo.get_table('GG_6TABLE') table_scraper = TableScraper(table_dict) table_scraper.screenshot = Image.open( os.path.join(os.environ['test_src'], '2.png')) table_scraper.crop_from_top_left_corner2(select_table=2) if is_debug: # table_scraper.screenshot.save('log/pics/table1.png') file_name = get_dir(os.path.join('log', 'pics', 'table_label.png')) save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name) table_scraper.get_pots() table_scraper.get_players_funds() table_scraper.get_player_pots() pytest.assume(table_scraper.total_pot == 48.0) pytest.assume( table_scraper.player_funds == [25.0, 11.0, 100.0, 184.0, 51.5, 64.0]) pytest.assume( table_scraper.player_pots == [-1.0, -1.0, -1.0, -1.0, -1.0, 24.0])