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 bot_is_observing(): wait_hand_ends_when_observing(waiting_minutes=30) while True: if c.bot_status != 'OBSERVING': break shout("* bot_status == 'OBSERVING' *", color='on_green') reset_table_information() wait_new_hand_starts_when_observing(waiting_minutes=30) shout("-------- New Hand Started --------", color='on_green') if c.bot_status != 'OBSERVING': break # use this statement after waiting functions # which uses c.new_hand = hand_is_ended() if c.new_hand: continue determine_small_big_dealer_seats() if am_i_in_or_not(): if pm.player_cards_pixel(c.game_position, c.my_seat_number): read_and_save_my_cards() play_sound_for_good_starting_hands() read_and_save_banks_and_names() # Playing a whole hand in this loop observing_a_hand() if c.bot_status != 'OBSERVING': break if c.new_hand: continue if game_is_paused(): fix_game_disruption('game is unpaused') break
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 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: 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 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 wait_celebration_ends(waiting_seconds=10): global new_hand t1 = time.time() while True: new_hand = hand_is_ended() if not new_hand: break if time.time() - t1 > waiting_seconds: fix_game_disruption('game is stuck at celebration') break # sleep time so buttons and cards are dealt properly time.sleep(1)
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 wait_hand_ends(waiting_minutes = 5): t1 = time.time() while True: c.new_hand = hand_is_ended() if c.new_hand: declare_the_winners() wait_celebration_ends(waiting_seconds = 10) break if time.time() - t1 > 60 * waiting_minutes : shout('This hand is played manually more than %s minutes' %waiting_minutes) break if game_is_paused(): fix_game_disruption('game is unpaused') break
def wait_for_my_new_hand(waiting_minutes=10): global new_hand shout("Looking for my cards in 'I_AM_PLAYING' Section...", color='light_magenta') t1 = time.time() while True: if pm.player_cards_pixel(config.game_position, config.my_seat_number): shout("My cards are founded", color='light_magenta') config.preflop_stage = True break new_hand = hand_is_ended() if not new_hand: break if time.time() - t1 > 60 * waiting_minutes: fix_game_disruption('buttons are not founded') break
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 wait_new_hand_starts_when_observing(waiting_minutes=30): shout('waiting new hand starts by looking for dealer button...') t1 = time.time() fixing_retry = 1 while True: if sb_b_d_buttons_are_founded(): break if (time.time() - t1) > ( (60 * waiting_minutes) / 4) and fixing_retry <= 1: fixing_retry += 1 fix_game_disruption() if time.time() - t1 > 60 * waiting_minutes: c.bot_status = 'ON_MAIN_MENU' shout("No one join the table after %s minutes, "\ "call operator to go to main menu" %waiting_minutes) break 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')
def observing_a_hand(): """Use wait_hand_ends_when_observing() before all breaks, except one which ended without any problem. """ set_seats_not_folded_dictionary() acted_players = 0 t1 = time.time() while True: if shifted_to_next_stage(): acted_players = 0 read_board_cards() if not stages_are_sequenced(): shout("Stages are not sequenced", color='on_light_red') screenshot_error('stages are not sequenced') wait_hand_ends_when_observing(waiting_minutes=30) break # new line seat_to_report = find_seat_to_report(acted_players) if ready_to_report(seat_to_report): acted_players += 1 report_the_player(seat_to_report) #🗺️ 💎♣💎♠💎♦💎♥💎 🗺️ #update_betting_rounds() #read_and_save_bets() if t1 - time.time() > 5 * 60: c.bot_status = 'WAITING_FOR_FIRST_HAND' fix_game_disruption('This hand last more than 5 minutes') wait_hand_ends_when_observing(waiting_minutes=30) break # new line c.new_hand = hand_is_ended() if c.new_hand: declare_the_winners() wait_celebration_ends(waiting_seconds=10) # Hand is ended without any problem. Save statistical data here. shout('I should save statistical data here later.', 'rainbow') shout("-------- Hand ended --------", color='on_green') break if c.bot_status != 'OBSERVING': # will not be used break if game_is_paused(): fix_game_disruption('game is unpaused') if c.bot_status == 'OBSERVING': wait_hand_ends_when_observing(waiting_minutes=30) break
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 bot_is_playing(): while True: config.new_hand = hand_is_ended() if config.new_hand: declare_the_winners() wait_celebration_ends(waiting_seconds = 10) reset_table_information() shout("* bot_status == 'I_AM_PLAYING' *") 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() 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') t1 = time.time() # 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(): input("press Enter to start again...") fix_game_disruption('game is unpaused') break
def bot_is_waiting_till_next_hand(): """ Bot is suspended automatically from decide.py module for a hand so operator can play that hand manually. This situation should happen when decision_making package is *under construction* and can not play some scenarios. The bot_status is change to 'OPERATOR_IS_PLAYING_THE_HAND' in decide.py module so that the operator plays the hand. In this bot_status, the bot will not look for buttons and will not run fix_game_disruption() anymore. The bot just waits for the next hand. #IMPORTANT# If this bot_status is added to decide function at decide.py, bot will acts like a copilot and operator must always beware and plays some hands beside the bot. """ shout("* bot_status == 'OPERATOR_SHOULD_PLAY_THE_HAND' *", color='on_green') sound('Play yourself') shout('OPERATOR MUST PLAY THIS HAND!', color='rainbow', save=False) wait_hand_ends(waiting_minutes=5) config.bot_status = 'WAITING_FOR_FIRST_HAND' fix_game_disruption("Game was played manually for a hand")
def wait_hand_ends_when_observing(waiting_minutes=5): shout('waiting till current hand ends...') t1 = time.time() fixing_retry = 1 while True: c.new_hand = hand_is_ended() if c.new_hand: declare_the_winners() wait_celebration_ends(waiting_seconds=10) shout("-------- Hand ended --------", color='on_green') break if (time.time() - t1) > ( (60 * waiting_minutes) / 4) and fixing_retry <= 1: fixing_retry += 1 fix_game_disruption() if time.time() - t1 > 60 * waiting_minutes: c.bot_status = 'ON_MAIN_MENU' shout("No hand ending after %s minutes, "\ "call operator to go to main menu" %waiting_minutes) break if game_is_paused(): fix_game_disruption('game is unpaused') break
def wait_for_my_new_hand(waiting_minutes = 10): shout("Looking for my cards in 'I_AM_PLAYING' Section..." , color = 'light_magenta') t1 = time.time() while True: if pm.player_cards_pixel(c.game_position, c.my_seat_number): shout("My cards are founded", color = 'light_magenta') c.preflop_stage = True break # 2021: It's not reasonable to break here at all. # So I comment these 3 lines: #c.new_hand = hand_is_ended() #if not c.new_hand: # break if time.time() - t1 > 60*waiting_minutes: fix_game_disruption('My cards are not founded for new hand '\ 'after %s minutes wating'%waiting_minutes) if not pm.player_cards_pixel(c.game_position, c.my_seat_number): c.bot_status = 'WAITING_FOR_FIRST_HAND' break if game_is_paused(): fix_game_disruption('game is unpaused') break
def wait_for_my_first_hand(waiting_minutes = 5): """Don't break this waiting function if c.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(c.game_position, c.my_seat_number): shout("My cards are founded", color = 'light_magenta') c.bot_status = 'I_AM_PLAYING' 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 : c.bot_status = 'ON_MAIN_MENU' shout("No one join the table, call operator to go to main menu") break if game_is_paused(): fix_game_disruption('game is unpaused') 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")
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 else: # Develop 'OBSERVING' status for bot_status later. # 'OBSERVING' status can be used to test screen monitoring or to # get opponents playing styles or to gather statistical data. raise Exception("bot_status is can be only 'ON_MAIN_MENU' or "\ "'WAITING_FOR_FIRST_HAND' or 'I_AM_PLAYING'")