def ocr_my_bank(): """ If ocr fails this function will uses: 1. fix_game_disruption() Will not uses: 1. set_just_do_check_fold_to_true() """ #global my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand , just_do_check_fold ocr_string = ocr.ocr_my_bank_to_string(config.game_position, config.my_seat_number) shout("my bank ocr string at seat %s is: %s" % (config.my_seat_number, ocr_string)) eval_string = replace_letters_comma_space_m_k(ocr_string) digit_string = eval_string.replace("*", "") if digit_string.isdigit(): return eval(eval_string) # else include digit_string like: '', 'c540!' else: fix_game_disruption("ocr_my_bank is not digit at seat %s" % config.my_seat_number) ocr_string = ocr.ocr_my_bank_to_string(config.game_position, config.my_seat_number) shout("my bank ocr string at seat %s is: %s" % (config.my_seat_number, ocr_string)) eval_string = replace_letters_comma_space_m_k(ocr_string) digit_string = eval_string.replace("*", "") if digit_string.isdigit(): return eval(eval_string) else: screenshot_error("ocr_my_bank is not digit at seat %s" % config.my_seat_number) return None
def read_and_global_flop_cards(): #global game_position, board_card_1th , board_card_2th , board_card_3th , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand config.board_card_1th, config.board_card_2th, config.board_card_3th =\ read_cards.read_flop_cards(config.game_position) if ( 'Unknown' in config.board_card_1th or 'Unknown' in config.board_card_2th or 'Unknown' in config.board_card_3th ): fix_game_disruption("Flop cards are read 'Unknown'") config.board_card_1th, config.board_card_2th, config.board_card_3th =\ read_cards.read_flop_cards(config.game_position) if ('Unknown' in config.board_card_1th or 'Unknown' in config.board_card_2th or 'Unknown' in config.board_card_3th or not pm.flop_pixel(config.game_position) or pm.turn_pixel(config.game_position) ): set_just_do_check_fold_to_true("Flop cards are read 'Unknown' again") shout("Flop cards are: %s %s, %s %s, %s %s" %(config.board_card_1th[0][0], config.board_card_1th[0][1], config.board_card_2th[1][0], config.board_card_2th[1][1], config.board_card_3th[1][0], config.board_card_3th[1][1]) , color = 'green')
def ocr_bet(seat): """ If ocr fails this function will uses: 1. fix_game_disruption() 2. set_just_do_check_fold_to_true() """ ocr_string = ocr.ocr_bet_to_string(config.game_position, seat) shout("bet ocr string at seat %s is: %s" % (seat, ocr_string)) eval_string = replace_letters_comma_space_m_k(ocr_string) digit_string = eval_string.replace("*", "") if digit_string.isdigit(): return eval(eval_string) # else include digit_string like: '', 'c540!' else: fix_game_disruption("ocr_bet is not digit at seat %s" % seat) ocr_string = ocr.ocr_bet_to_string(config.game_position, seat) shout("bet ocr string at seat %s is: %s" % (seat, ocr_string)) eval_string = replace_letters_comma_space_m_k(ocr_string) digit_string = eval_string.replace("*", "") if digit_string.isdigit(): return eval(eval_string) else: set_just_do_check_fold_to_true("ocr_bet is not digit") screenshot_error("ocr_bet is not digit at seat %s" % seat) 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 read_and_global_river_card(): #global game_position, board_card_5th , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand config.board_card_5th = read_cards.read_river_card(config.game_position) if 'Unknown' in config.board_card_5th: fix_game_disruption("River card is read 'Unknown'") config.board_card_5th = read_cards.read_river_card(config.game_position) if ('Unknown' in config.board_card_5th or not pm.river_pixel(config.game_position) ): set_just_do_check_fold_to_true("River card is read 'Unknown' again") shout("River card is: %s %s" %(config.board_card_5th[0], config.board_card_5th[1]) , color = 'green')
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 , waiting_for_first_hand if pm.button_pixel(config.game_position, button_name) : click(button_name) if button_name == 'exit': config.waiting_for_first_hand = None 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.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") 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.waiting_for_first_hand = None 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 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 read_and_global_my_cards(): #global game_position, my_1th_card , my_2th_card , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , waiting_for_first_hand config.my_1th_card, config.my_2th_card =\ read_cards.read_my_cards(config.game_position, config.my_seat_number) if ('Unknown' in config.my_1th_card or 'Unknown' in config.my_2th_card ): fix_game_disruption("my cards are read Unknown") config.my_1th_card, config.my_2th_card =\ read_cards.read_my_cards(config.game_position, config.my_seat_number) if ('Unknown' in config.my_1th_card or 'Unknown' in config.my_2th_card or pm.flop_pixel(config.game_position) ): set_just_do_check_fold_to_true("my cards are read Unknown again") shout("My cards are: %s %s, %s %s" %(my_1th_card[0][0], my_1th_card[0][1], my_2th_card[1][0], my_2th_card[1][1]) , color = 'green')
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")
time02 = 0 ; fo = 0 time1 = time.time() Cards1 = False shout("Looking for cards in waiting_for_first_hand == True Section..." , color = 'light_magenta') while Cards1 == False and time02 < 5 * 60 : #being alone time Cards1 = pm.player_cards_pixel(game_position, my_seat_number ) time2 = time.time() - time1 n60 = ( time2 - 120 ) // 60 if not time2 < 2 * 60 and n60 >= fo : fix_game_disruption("1") fo += 1 time02 = time.time() - time1 if not time02 < 5 * 60 : #being alone time raise Exception("0.1.No one join, time to exit. Or Game is locked, force to restart(will be build in future), waiting_for_first_hand == None") if Cards1 == True : if pm.pre_flop_pixel(game_position) == False or ( pm.pre_flop_pixel(game_position) == True and is_there_any_raiser() == True) : set_just_do_check_fold_to_true("this is Ok! Becuase i may start program from middle of the game")