def play_a_hand(): t1 = time.time() while True: if shifted_to_next_stage(): read_board_cards() if not stages_are_sequenced(): set_just_do_check_fold_to_true('stages are not sequenced') screenshot_error('stages are not sequenced') if its_my_turn(): update_betting_rounds() read_and_save_bets() if config.bot_status == 'I_AM_PLAYING': click_decision() #🌏🌱♣♠♦♥🌱🌏 if t1 - time.time() > 5 * 60: config.bot_status = 'WAITING_FOR_FIRST_HAND' fix_game_disruption('This hand last more than 5 minutes') config.new_hand = hand_is_ended() if config.new_hand: shout("appending hand data to csv file", color='on_green') append_new_line_to_csv(config.csv_path) shout("-------- Hand ended --------", color='on_green') break if game_is_paused(): fix_game_disruption('game is unpaused') break if config.bot_status != 'I_AM_PLAYING': break
def wait_for_my_first_hand(waiting_minutes=5): """Don't break this waiting function if new_hand is True, because I'm waiting for first hand and maybe several hands are played without me. """ shout("Looking for cards in 'WAITING_FOR_FIRST_HAND' Section...", color='light_magenta') t1 = time.time() fixing_retry = 1 while True: if pm.player_cards_pixel(config.game_position, config.my_seat_number): shout("My cards are founded", color='light_magenta') config.bot_status = 'I_AM_PLAYING' # If I've resume the game, set # config.bot_status = 'WAITING_FOR_FIRST_HAND' inside resume function. # Even at preflop (betting_round = 0) I can resume the game without # doing set_just_do_check_fold_to_true(). if (not pm.pre_flop_pixel(config.game_position) or (pm.pre_flop_pixel(config.game_position) and is_there_any_raiser())): set_just_do_check_fold_to_true("program is started again "\ "from middle of the game") break if (time.time() - t1) > ( (60 * waiting_minutes) / 3) and fixing_retry <= 1: fixing_retry += 1 fix_game_disruption() if time.time() - t1 > 60 * waiting_minutes: config.bot_status = 'ON_MAIN_MENU' shout("No one join the table, call operator to go to main menu") break
def read_and_save_flop_cards(): #global game_position, board_card_1th , board_card_2th , board_card_3th , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , bot_status 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" % (config.board_card_1th, config.board_card_2th, config.board_card_3th), color='green')
def play_a_hand(): t1 = time.time() while True: if shifted_to_next_stage(): read_board_cards() if not stages_are_sequenced(): set_just_do_check_fold_to_true('stages are not sequenced') screenshot_error('stages are not sequenced') if its_my_turn(): update_betting_rounds() read_and_save_bets() if config.bot_status == 'I_AM_PLAYING': click_decision() #🌏🌱♣♠♦♥🌱🌏 if t1 - time.time() > 5 * 60: fix_game_disruption('This hand last more than 5 minutes') config.new_hand = hand_is_ended() if config.new_hand: shout("-------- Hand ended --------", color='on_green') break if config.bot_status != 'I_AM_PLAYING': break if game_is_paused(): input("press Enter to start again...") fix_game_disruption('game is unpaused') break
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 , bot_status 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.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") 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 wait_for_sb_b_d_buttons(waiting_seconds=5): """5 seconds waiting does not need new_hand to break it""" t1 = time.time() while True: if sb_b_d_buttons_are_founded(): break if time.time() - t1 > waiting_seconds: fix_game_disruption('buttons are not founded') if not sb_b_d_buttons_are_founded(): set_just_do_check_fold_to_true('buttons are not founded') break
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 read_and_save_turn_card(): #global game_position, board_card_4th , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , bot_status config.board_card_4th = read_cards.read_turn_card(config.game_position) if 'Unknown' in config.board_card_4th: fix_game_disruption("Turn card is read 'Unknown'") config.board_card_4th = read_cards.read_turn_card(config.game_position) if ('Unknown' in config.board_card_4th or not pm.turn_pixel(config.game_position) or pm.river_pixel(config.game_position)): set_just_do_check_fold_to_true("Turn card is read 'Unknown' again") shout("Turn card is: %s" % (config.board_card_4th[0]), color='green')
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 bot_is_playing(): while True: config.new_hand = hand_is_ended() if config.new_hand: declare_the_winners() wait_celebration_ends(waiting_seconds=10) config.hand_number += 1 reset_table_information() shout("* bot_status == 'I_AM_PLAYING' *", color='on_green') wait_for_my_new_hand(waiting_minutes=10) # use this statement after functions which use fix_game_disruption() if config.bot_status != 'I_AM_PLAYING': break # use this statement after waiting functions # which uses config.new_hand = hand_is_ended() if config.new_hand: continue shout("-------- New Hand Started --------", color='on_green') wait_for_sb_b_d_buttons(waiting_seconds=5) if config.bot_status != 'I_AM_PLAYING': break determine_small_big_dealer_seats() determine_playing_seats() # In case bot is resumed: if not first_round_at_preflop(): set_just_do_check_fold_to_true("program must've started "\ "again from middle of the game") read_and_save_my_cards() rebuy_if_bank_is_low(min_blinds=15) read_and_save_banks_and_names() if config.bot_status != 'I_AM_PLAYING': break play_sound_for_good_starting_hands() shout("Waiting for my turn at preflop_stage...", 'light_magenta') # Playing a whole hand in this loop play_a_hand() if config.bot_status != 'I_AM_PLAYING': break if config.new_hand: continue if game_is_paused(): fix_game_disruption('game is unpaused') break
def read_and_save_my_cards(): #global game_position, my_1th_card , my_2th_card , just_do_check_fold , my_seat_number , MY_PROFILE_NAME , bot_status 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" % (config.my_1th_card, config.my_2th_card), color='green')
determine_small_big_dealer_seats() read_and_save_my_cards() rebuy_if_bank_is_low(min_blinds=15) read_and_save_banks_and_names() if config.bot_status != 'I_AM_PLAYING': continue play_sound_for_good_starting_hands() shout("Waiting for my turn at preflop_stage...", 'light_magenta') t1 = time.time() # Playing a whole hand in this loop while True: if shifted_to_next_stage(): read_board_cards() if not stages_are_sequenced(): set_just_do_check_fold_to_true('stages are not sequenced') screenshot_error('stages are not sequenced') if its_my_turn(): update_betting_rounds() read_and_save_bets() if config.bot_status == 'I_AM_PLAYING': click_decision() if t1 - time.time() > 5 * 60: fix_game_disruption('This hand last more than 5 minutes') new_hand = hand_is_ended() if new_hand: shout("-------- Hand ended --------", color='on_green') break if config.bot_status != 'I_AM_PLAYING': break
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 , bot_status,\ #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, config.TOTAL_SEATS + 1) 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")