def find_and_click_on_reconnect_button(): #global game_position shout('looking for reconnect button') x1 = pyautogui.locateCenterOnScreen( 'screen_monitoring/find_game_position/reconnect button.png') if x1 != None: pyautogui.click(x1) shout('reconnect button founded and clicked', color='yellow') time.sleep(5) if pm.button_pixel(config.game_position, 'i_am_back') == True: click('i_am_back') return x1 x2 = pyautogui.locateCenterOnScreen( 'screen_monitoring/find_game_position/reconnect button.png') if x2 != None: pyautogui.click(x2) shout('reconnect button founded and clicked', color='yellow') time.sleep(5) if pm.button_pixel(config.game_position, 'i_am_back') == True: click('i_am_back') return x1 else: return None
def number_of_clicks_on_button(button_name, number): # Number of clicks # for plus and minus buttons #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand number = int(number) if pm.button_pixel(config.game_position, button_name) : for i in range (number): click(button_name) else : time0 = time.time() fix_game_disruption("button %s is not visible" %button_name) time1 = time.time() - time0 if config.waiting_for_first_hand == True: return None elif config.just_do_check_fold == True: if pm.button_pixel(config.game_position, 'check') : click('check') elif pm.button_pixel(config.game_position, 'fold') : click('fold') else: screenshot_error("check and fold buttons are not visible") if pm.player_cards_pixel(config.game_position, config.my_seat_number ) \ and pm.button_pixel(config.game_position, button_name) and time1 <= 10 : for i in range (number): click(button_name) else : set_just_do_check_fold_to_true("There is problem on clicking on button %s" %button_name)
def all_in(): #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand if pm.button_pixel(config.game_position, 'all_in') == False and pm.button_pixel(config.game_position, 'call') == True \ and pm.button_pixel(config.game_position, 'bet') == False and pm.button_pixel(config.game_position, 'raise') == False : return click('call') click_on_button('all_in') if pm.button_pixel(config.game_position, 'bet') == True : return click('bet') else : return click_on_button('raise')
def hold_click_on_button(button_name, seconds = 10): # for buy_in_plus and buy_in_minus and re_buy_plus and re_buy_minus buttons # It holds left click for 10s #global game_position if pm.button_pixel(config.game_position, button_name) : hold_click(button_name ,seconds = seconds) else : time.sleep(2) if pm.button_pixel(config.game_position, button_name) : hold_click(button_name ,seconds = seconds) else : raise_exception_the_problem("button %s is not visible" %button_name)
def click_on_button(button_name): # for call, check, fold, bet, raise, # exit, menu, rebuy_menu, # exit_yes, leave_next_hand_ok, buy_in, and re_buy buttons. #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , bot_status if pm.button_pixel(config.game_position, button_name): click(button_name) if button_name == 'exit': config.bot_status = 'ON_MAIN_MENU' else: if button_name in ('call', 'check', 'fold', 'bet', 'raise'): time0 = time.time() fix_game_disruption("button %s is not visible" % button_name) time1 = time.time() - time0 if config.bot_status == 'WAITING_FOR_FIRST_HAND': return None elif config.just_do_check_fold == True: if pm.button_pixel(config.game_position, 'check'): click('check') elif pm.button_pixel(config.game_position, 'fold'): click('fold') else: screenshot_error("check and fold buttons are not visible") elif pm.player_cards_pixel(config.game_position, config.my_seat_number ) \ and pm.button_pixel(config.game_position, button_name) and time1 <= 10 : click(button_name) #new function else: set_just_do_check_fold_to_true( "There is problem on clicking on button %s" % button_name) elif button_name in ('exit', 'menu', 'rebuy_menu'): fix_game_disruption("button %s is not visible" % button_name) if pm.button_pixel(config.game_position, button_name): click(button_name) if button_name == 'exit': config.bot_status = 'ON_MAIN_MENU' else: raise_exception_the_problem("button %s is not visible" % button_name) elif button_name in ('exit_yes', 'leave_next_hand_ok', 'buy_in', 're_buy'): raise_exception_the_problem("button %s is not visible" % button_name)
def sit_in(chips): # "Min buy in" or "Max buy in" #global game_position, my_seat_number , waiting_for_first_hand shout("Searching for a seat to sit in", color = 'yellow') config.my_seat_number = None for i in range(1 ,6 ): if pm.available_seat_pixel(config.game_position,i) == True : click('available_seat_%s' %i) config.my_seat_number = i config.waiting_for_first_hand = True shout("Sit_In() --> waiting_for_first_hand is True." , color = 'yellow') break if config.my_seat_number == None : click_on_button('exit') raise Exception("Sit_In(chips):This can not happen IN FUTURE becuase main menu automation is built") else : x1 = time.time() time1 = 0 Buy_In = None while ( (time1 < 5) and Buy_In !=True ): Buy_In = pm.button_pixel(config.game_position, 'buy_in') x2 = time.time() time1 = x2-x1 if Buy_In != True : fix_game_disruption("Sit_In(chips):Buy_In != True") if (chips == "Min buy in" and config.my_seat_number != None) : hold_click_on_button('buy_in_minus', seconds = 10) if (chips == "Max buy in" and config.my_seat_number != None): hold_click_on_button('buy_in_plus', seconds = 10) if config.my_seat_number != None : click_on_button('buy_in') screenshot_error("Rebuyed")
def check_i_am_in_or_out(): #global game_position, my_seat_number , MY_PROFILE_NAME , just_do_check_fold if pm.button_pixel(config.game_position, 'i_am_back') == True: click('i_am_back') if ocr_my_name() == config.MY_PROFILE_NAME or ocr_my_name() == True: shout("I am In", color='yellow') return ("In") for i in range(1, 6): if pm.i_am_seated_pixel(config.game_position, i): if is_internet_disconnected( ) == False and find_and_click_on_reconnect_button() == None: if config.my_seat_number == i: shout("I am In not by OCR") return ("In") else: config.my_seat_number = i shout('I AM IN,BUT MY SEAT IS MANUALLY CHANGED TO: %s' % config.my_seat_number) set_just_do_check_fold_to_true( "My seat is manually changed!") return ("In") shout("I am Out", color='yellow') return ("Out")
def check_fold(): #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand if pm.button_pixel(config.game_position, 'check') : click('check') elif pm.button_pixel(config.game_position, 'fold') : click('fold') else : fix_game_disruption("check_fold()") if config.waiting_for_first_hand != False: return None elif pm.button_pixel(config.game_position, 'check') : click('check') elif pm.button_pixel(config.game_position, 'fold') : click('fold') else: set_just_do_check_fold_to_true("check_fold()(It's already True)") screenshot_error("check and fold buttons are not visible")
def check_fold(): #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , bot_status if pm.button_pixel(config.game_position, 'check'): click('check') elif pm.button_pixel(config.game_position, 'fold'): click('fold') else: fix_game_disruption("check_fold()") if config.bot_status != 'I_AM_PLAYING': return None elif pm.button_pixel(config.game_position, 'check'): click('check') elif pm.button_pixel(config.game_position, 'fold'): click('fold') else: set_just_do_check_fold_to_true("check_fold()(It's already True)") screenshot_error("check and fold buttons are not visible")
def all_in_old(Minus_Blinds = 0): #not completed on did_i_raised_at and my_last_raise_at. i won't use this fuction anymore """ if 0 : all_in everything """ global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand if pm.button_pixel(config.game_position, 'all_in') == False and pm.button_pixel(config.game_position, 'call') == True \ and pm.button_pixel(config.game_position, 'bet') == False and pm.button_pixel(config.game_position, 'raise') == False : return click_on_button('call') if Minus_Blinds == 0 : click_on_button('all_in') if pm.button_pixel(config.game_position, 'bet') == True : return click_on_button('bet') else : return click_on_button('raise') else : click_on_button('all_in') number_of_clicks_on_button('minus', Minus_Blinds) if pm.button_pixel(config.game_position, 'bet') == True : return click_on_button('bet') else : return click_on_button('raise')
def test_pixel_matching(): # This list may differ for other websites ALL_CLICK_NAMES = [ 'fold', 'check', 'call', 'bet', 'raise', 'plus', 'minus', 'all_in', #'available_seat_1', 'available_seat_2', 'available_seat_3', #'available_seat_4', 'available_seat_5', 'exit', 'exit_yes', 'menu', 'rebuy_menu', 'leave_next_hand_ok', 'buy_in', 'buy_in_plus', 'buy_in_minus', 're_buy', 're_buy_plus', 're_buy_minus', 'i_am_back', #'exit_probable_advertisement', 'close_update_window', ] print('\n***testing pixel matching for buttons:***') for button_name in ALL_CLICK_NAMES: print('%s button pixel is: %s' % (button_name, pm.button_pixel(game_position, button_name))) for seat in range(1, TOTAL_SEATS + 1): print('available_seat_%s button pixel is: %s' % (seat, pm.available_seat_pixel(game_position, seat))) print('\n***testing pixel matching for non buttons:***') print('pre_flop_pixel is: %s' % pm.pre_flop_pixel(game_position)) print('flop_pixel is: %s' % pm.flop_pixel(game_position)) print('turn_pixel is: %s' % pm.turn_pixel(game_position)) print('river_pixel is: %s' % pm.river_pixel(game_position)) for seat in range(1, TOTAL_SEATS + 1): print('small_blind_pixel at seat %s is: %s' % (seat, pm.small_blind_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('big_blind_pixel at seat %s is: %s' % (seat, pm.big_blind_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('dealer_pixel at seat %s is: %s' % (seat, pm.dealer_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('player_chips_pixel at seat %s is: %s' % (seat, pm.player_chips_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('player_cards_pixel at seat %s is: %s' % (seat, pm.player_cards_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('other_player_seated_pixel at seat %s is: %s' % (seat, pm.other_player_seated_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('i_am_seated_pixel at seat %s is: %s' % (seat, pm.i_am_seated_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('active_player_pixel at seat %s is: %s' % (seat, pm.active_player_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('my_seat_won_pixel at seat %s is: %s' % (seat, pm.my_seat_won_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('other_seat_won_pixel at seat %s is: %s' % (seat, pm.other_seat_won_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('notification_banner_pixel at seat %s is: %s' % (seat, pm.notification_banner_pixel(game_position, seat))) for seat in range(1, TOTAL_SEATS + 1): print('are_chips_white_or_red_pixel at seat %s is: %s' % (seat, pm.are_chips_white_or_red_pixel(game_position, seat)))
def fix_game_disruption(String = None): #if find_game_reference_point() == None or ... #global game_position , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand , just_do_check_fold shout( 7*"-" , color = 'yellow') if String == None : shout("fix_game_disruption() is running....", color = 'yellow') elif type(String) == str : shout("fix_game_disruption() <-- %s is running...." %String , color = 'yellow') if is_internet_disconnected() : shout('Internet is Disconnected, waiting to reconect...') while is_internet_disconnected() : continue shout('Internet is Connected Back!') time.sleep(15) if find_and_click_on_reconnect_button() == None : screenshot_error('No reconnect button founded') click('exit_probable_advertisement') # click to Exit probable Advertisement shout("Position (0,720) is clicked", color = 'yellow') pyautogui.press('esc') config.game_position = pyautogui.locateOnScreen( 'screen_monitoring/find_game_position/reference image.png') if config.game_position == None: config.alternative_game_position = pyautogui.locateOnScreen( 'screen_monitoring/find_game_position/alternative reference image.png') if config.alternative_game_position != None: config.game_position = ( alternative_game_position[0]+328 , alternative_game_position[1]-245 ) if config.game_position != None : config.game_position = (int(config.game_position[0]),int(config.game_position[1])) else: for process in wmi.WMI().Win32_Process (): if process.Name == 'SystemSettings.exe' : shout("SystemSettings Update is on desktop") shout("closing Windows Update program") screenshot_error('right before closing windows update program') click('close_update_window') break if config.game_position == None : config.game_position = find_game_position.find_game_reference_point() if config.game_position != None : shout("Game region refounded after fix_game_disruption()" , color = 'yellow') if pm.button_pixel(config.game_position, 'i_am_back') == True : click('i_am_back') if pm.player_cards_pixel(config.game_position, config.my_seat_number ) == True : config.just_do_check_fold = True shout("After fix_game_disruption() --> just_do_check_fold is True." , color = 'yellow') else : config.waiting_for_first_hand = True shout("After fix_game_disruption() --> waiting_for_first_hand is True." , color = 'on_yellow') if check_i_am_in_or_out() == "Out": sit_in("Min buy in") shout( 7*"-" , color = 'yellow')
def raising(Blinds): """ Act for both raising and betting Blinds is the amount of money like in ocr; not the number of blinds if Blinds == BLIND_VALUE (or less): won't click on plus button """ #global game_position, just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand,\ #preflop_stage , flop_stage , turn_stage , river_stage , did_i_raised_at , my_last_raise_at , BLIND_VALUE if config.preflop_stage == True and config.flop_stage == False : stage = "Pre_Flop" elif config.flop_stage == True and config.turn_stage == False : stage = "Flop" elif config.turn_stage == True and config.river_stage == False : stage = "Turn" elif config.river_stage == True : stage = "River" config.did_i_raised_at[stage] = True Bets = [last_bets_cache[Seat] for Seat in range(1,6) if last_red_chips_cache[Seat] and last_bets_cache[Seat] != None ] if config.preflop_stage and not config.flop_stage : Bets.append(config.BLIND_VALUE) else : Bets.append(0) #That's why raising() algorithm can be use and act for betting too. Bets.sort(reverse = True ) Raise_base = max(Bets) Bets_difference = [ Bets[i] - Bets[i+1] for i in range(len(Bets)-1) ] if Bets_difference == []: Raise_add = config.BLIND_VALUE elif max(Bets_difference) <= config.BLIND_VALUE : Raise_add = config.BLIND_VALUE else : Raise_add = max(Bets_difference) if Blinds > Raise_base + Raise_add : config.my_last_raise_at[stage] = Blinds else : config.my_last_raise_at[stage] = Raise_base + Raise_add number_of_clicks_on_button('plus', ( Blinds - (Raise_base + Raise_add) ) // config.BLIND_VALUE) #Till here as same as raising() if pm.button_pixel(config.game_position, 'raise') : click('raise') elif pm.button_pixel(config.game_position, 'bet') : click('bet') else : fix_game_disruption("RAISE() Button, No Raise nor Bet Button founded") if pm.button_pixel(config.game_position, 'raise') : click('raise') elif pm.button_pixel(config.game_position, 'bet') : click('bet') else : set_just_do_check_fold_to_true("No raise nor bet button founded")
screenshot_error('6. pm.pre_flop_pixel() == False') elif Hand_End_Cheker1 == False and waiting_for_first_hand == False and just_do_check_fold != True : Pre_Flop1 = True #(2020: Pre_Flop1 has no usage) preflop_stage = True if Hand_End_Cheker1 == False and pm.player_cards_pixel(game_position, my_seat_number ) == True and waiting_for_first_hand == False : read_and_global_my_cards() # play_sound() # its_my_turn = False Gray1 = True ; fo = 0 time1 = time.time() shout("Looking for light...", color = 'light_magenta') while Hand_End_Cheker1 == False and (its_my_turn == False or Gray1 == True) and flop_stage == False and waiting_for_first_hand == False and time.time() - time1 < 5 * 60 : if pm.button_pixel(game_position, 'i_am_back') : fix_game_disruption("2.5 I am back Button is True") Hand_End_Cheker1 = hand_is_ended() its_my_turn = pm.active_player_pixel(game_position, my_seat_number ) Gray1 = pm.notification_banner_pixel(game_position, my_seat_number ) flop_stage = pm.flop_pixel(game_position) n20 = (time.time() - time1 - 60 ) // 20 if time.time() - time1 > 1 * 60 and n20 >= fo : fix_game_disruption("3") fo += 1 if not time.time() - time1 < 5 * 60 : raise Exception("5.1.Game is locked, force to restart, waiting_for_first_hand == None") if flop_stage == True : set_just_do_check_fold_to_true("1.5")