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 declare_the_winners(): """May differs for Cheet""" for seat in [1, 2, 3, 4, 5]: if pm.my_seat_won_pixel(config.game_position, seat) == True: shout("I won the game!", color='on_light_magenta') if pm.other_seat_won_pixel(config.game_position, seat) == True: shout("Seat %s won the game!" % seat)
def first_round_at_preflop(): """ This function is created to help handling the bot after the game is unpaused in 'I_AM_PLAYING' bot status. If I've resume the game, set c.bot_status = 'WAITING_FOR_FIRST_HAND' inside resume function. Even at preflop (betting_round = 0) (first_round_at_preflop() is True) I can resume the game without doing set_just_do_check_fold_to_true(). """ def is_there_any_raiser(): """ Except me """ for seat in range(1, c.TOTAL_SEATS+1): if seat == c.my_seat_number: continue elif red_chips(seat): return True return False if not pm.pre_flop_pixel(c.game_position): return False if is_there_any_raiser(): shout('doing some ocr to check if it is first_round_at_preflop or not') if c.my_seat_number in (c.big_blind_seat, c.big_blind_seat): if ocr_bet(c.my_seat_number) > c.BLIND_VALUE: return False else: if pm.player_chips_pixel(c.game_position, c.my_seat_number): return False return True
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 determine_small_blind_seat(): #global game_position, small_blind_seat for seat in [1, 2, 3, 4, 5]: if pm.small_blind_pixel(config.game_position, seat): shout("Seat %s is at Small Blind Seat" % seat) config.small_blind_seat = seat break
def play_sound_for_good_starting_hands(): def sound(string_name): try: pygame.mixer.init() pygame.mixer.music.load( os.path.join('Sounds', "%s.wav" % string_name)) return pygame.mixer.music.play() except: pass if config.preflop_stage == True and config.flop_stage == False: if hand_ranking.hand1(): sound("Michel") shout("Playing Music: 'Michel'", color='light_cyan') elif hand_ranking.hand2(): sound("Alan Walker") shout("Playing Music: 'Alan Walker'", color='light_cyan') elif hand_ranking.hand3(): sound("Alan Walker") shout("Playing Music: 'Alan Walker'", color='light_cyan') elif hand_ranking.hand4(): sound("Pocket low pairs") shout("Playing Music: 'Pocket low pairs'", color='light_cyan') elif hand_ranking.hand5(): sound("Bob Marley") shout("Playing Music: 'Bob Marley'", color='light_cyan')
def hold_click(name, seconds=10): x, y = click_coordinates.click_coordinates(config.game_position, name) pyautogui.mouseDown(x=x, y=y) time.sleep(seconds) pyautogui.mouseUp() shout("%s button is hold for %s seconds" % (name, seconds), color='light_cyan')
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 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 declare_the_winners(): """May differs for Cheet""" for seat in range(1, c.TOTAL_SEATS+1): if pm.my_seat_won_pixel(c.game_position, seat) == True: shout("I won the game!", color = 'on_light_magenta') if pm.other_seat_won_pixel(c.game_position, seat) == True : shout("Seat %s won the game!" %seat)
def determine_big_blind_seat(): #global game_position, big_blind_seat for seat in [1, 2, 3, 4, 5]: if pm.big_blind_pixel(config.game_position, seat): shout("Seat %s is at Big Blind Seat" % seat) config.big_blind_seat = seat break
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 play_full_house(): # Study and complete River_Deside for this function if Pre_Flop_Deside() or Any_raiser_sofar() or not Me_full_house() : return False elif Flop_Deside() : shout("check and raise strategy") # whether i've had raised at pre flop or not i check and raise return ("check") elif Turn_Deside() : if not did_i_raise_sofar() or Max_raise_sofar() <= 1 : return ("raise", 4) else : return ("raise", (3 * Max_raise_sofar()) // c.BLIND_VALUE) elif River_Deside() : if Me_full_house_Ranking() == 4 : if am_i_last_player_by_seat_order() or not did_i_raise_at("Turn")\ or Max_raise_sofar() >= 5 * c.BLIND_VALUE : return ("check") else : shout("Anti bluff raise") return ("raise", (Max_raise_sofar()) // c.BLIND_VALUE) elif not did_i_raise_sofar()\ or Max_raise_sofar() <= 3 * c.BLIND_VALUE: return ("raise", 9) else : return ("raise", (2 * Max_raise_sofar()) // c.BLIND_VALUE)
def determine_dealer_seat(): #global game_position, dealer_seat for seat in [1, 2, 3, 4, 5]: if pm.dealer_pixel(config.game_position, seat): shout("Seat %s is at Dealer Seat" % seat) config.dealer_seat = seat break
def screenshot_error(type_of_error): #type_of_error in string #global REPORTS_DIRECTORY t = datetime.now().strftime("%Y-%m-%d %H-%M-%S.%f") t = t[:-4] shout("Screenshot Error: %s" %type_of_error, color = 'on_light_blue') pyautogui.screenshot( '%s/Error %s %s.png' %(config.REPORTS_DIRECTORY, t, type_of_error) )
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 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 bot_is_on_main_menu(): shout("* bot_status == 'ON_MAIN_MENU' *", color='on_green') raise Exception("5.This can not happen IN FUTURE because main "\ "menu automation is built " \ "( fix_game_disruption --> Sit_In --> "\ "table is full --> exit --> "\ "config.bot_status = 'ON_MAIN_MENU' --> main menu "\ "--> config.bot_status = 'WAITING_FOR_FIRST_HAND' )")
def set_just_do_check_fold_to_true(string = None) : #global just_do_check_fold config.just_do_check_fold = True if string == None : shout("just_do_check_fold is On", color = 'on_yellow') elif type(string) == str : shout("just_do_check_fold is On: %s" %string, color = 'on_yellow')
def bot_is_waiting_for_first_hand(): """ Why do we need to have 'WAITING_FOR_FIRST_HAND' status? Answer: Because we may need to wait for several hands before we start our first hand and wait_for_my_first_hand() will not break by new hands. """ shout("* bot_status == 'WAITING_FOR_FIRST_HAND' *", color='on_green') rebuy_if_bank_is_low(min_blinds=15) wait_for_my_first_hand(waiting_minutes=5)
def click(name): x, y = click_coordinates.click_coordinates(config.game_position, name) pyautogui.click(x, y) if name in ('available_seat_1', 'available_seat_2', 'available_seat_3', 'available_seat_4', 'available_seat_5', 'exit_probable_advertisement', 'close_update_window'): shout("%s is clicked" %name, color = 'light_cyan') else: shout("%s button is clicked" %name, color = 'light_cyan')
def play_pre_flop(): # handbook and script are same if not Pre_Flop_Deside() or hand1() or hand2() or hand3() or hand4()\ or ( hand5() and not Any_raiser_sofar() ): return False elif not Any_raiser_sofar(): if c.small_blind_seat == c.my_seat_number : if hand7(): return ("fold") else: return ("call") elif c.big_blind_seat == c.my_seat_number : return ("check") else : if hand6(): return ("call") else: return ("fold") elif Any_raiser_sofar(): # 'AKs', 'AQs', 'AJs', 'AKo' if holdem_starting_hand_ranking() in (4, 6, 8, 12)\ and Max_raise_sofar <= 4 * c.BLIND_VALUE: return ("call") elif hand5(): if ( not did_i_raise_at("Pre_Flop") and Max_raise_sofar() > 3.5 * c.BLIND_VALUE )\ or ( did_i_raise_at("Pre_Flop") and Max_raise_sofar >= 5 * c.BLIND_VALUE ): return ("fold") else: return ("call") elif c.small_blind_seat == c.my_seat_number and hand9()\ and Max_raise_sofar() < 2.5 * c.BLIND_VALUE: shout("Anti Bluff call. Defending pre flop blind") return ("call") elif c.big_blind_seat == c.my_seat_number and hand8()\ and Max_raise_sofar() < 2.5 * c.BLIND_VALUE: shout("Anti Bluff call. Defending pre flop blind") return("call") else: return("fold")
def declare_the_winners(): global game_position load_variables() for seat in [1,2,3,4,5]: if pm.my_seat_won_pixel(game_position, seat) == True: shout("I won the game!", color = 'on_light_magenta') if pm.other_seat_won_pixel(game_position, seat) == True : shout("Seat %s won the game!" %seat)
def bluff_hand5_flop_table_2_cards(): # define it inside the function if Flop_Deside() and not Any_raiser_sofar() and hand5() \ and ( Table_1_pair() or Table_3_of_kinds() ) and Me_Individual() : shout("Bluffing hand5 flop table 2 cards") return True else : return False
def bluff_table_1_pair() : if not Pre_Flop_Deside() and Me_Individual() and Table_1_pair()\ and not Any_raiser_sofar(): shout("Bluffing table 1 pair") return True else : return False
def reset_table_information(): """ IT'S DONE: preflop_betting_round ,...,river_betting_round & preflop_stage ,...,river_stage dar loope while True baresi va be in func baraye reset shodan enteghal dade shavand """ #global players_name , players_bank ,\ # player_cards_cache , white_chips_cache , red_chips_cache , bets_cache ,\ # last_player_cards_cache , last_white_chips_cache , last_red_chips_cache , last_bets_cache,\ # did_i_raised_at , my_last_raise_at , preflop_betting_round , flop_betting_round , turn_betting_round , river_betting_round shout("Reseting table information") reset_just_do_check_fold_to_false() config.scenario_list = [] config.playing_seats = {} config.players_name = {} config.players_bank = {} for Seat in range(1, config.TOTAL_SEATS + 1): config.players_name[Seat] = None config.players_bank[Seat] = None config.player_cards_cache = {} config.white_chips_cache = {} config.red_chips_cache = {} config.bets_cache = {} config.last_player_cards_cache = {} config.last_white_chips_cache = {} config.last_red_chips_cache = {} config.last_bets_cache = {} # Make sure while starting the code did_i_raised_at is defined # by reset_table_information() before first deciding; # otherwise did_i_raise_sofar() at supporting funcs file will error config.did_i_raised_at = { "Pre_Flop": False, "Flop": False, "Turn": False, "River": False } config.my_last_raise_at = {} # (2018) Later make sure if all rounds are starting from 0 in # main While True loop (Round_... = 0 should be implemented in # read_and_save_bets() for all stages so for example # bets_cache dictionary surely will "have Round_... 0"). # For testing i have put a shout(bets_cache) at the end of # read_and_save_bets() function config.preflop_betting_round = -1 config.flop_betting_round = -1 config.turn_betting_round = -1 config.river_betting_round = -1 # if a stage is True, previous stages are also True config.preflop_stage = False config.flop_stage = False config.turn_stage = False config.river_stage = False
def play_4_of_kind(): if Pre_Flop_Deside() or Any_raiser_sofar() or not Me_4_of_kinds() : return False elif Flop_Deside() : if did_i_raise_sofar(): shout("Low bet and raise strategy") return ("raise", (Max_raise_sofar()) // c.BLIND_VALUE) else : shout("check and raise strategy") return ("check") elif Turn_Deside(): if did_i_raise_sofar() : shout("Low bet and raise strategy") return ("raise", (Max_raise_sofar()) // c.BLIND_VALUE) else : shout("Low bet and raise strategy") return ("raise", 2) elif River_Deside() : if did_i_raise_sofar() : return ("raise", (3 * Max_raise_sofar()) // c.BLIND_VALUE) else : return ("raise", 2)
def is_internet_disconnected(): REMOTE_SERVER = "www.google.com" try: # see if we can resolve the host name -- tells us if there is # a DNS listening host = socket.gethostbyname(REMOTE_SERVER) # connect to the host -- tells us if the host is actually # reachable s = socket.create_connection((host, 80), 2) shout('internet is connected') return False except: pass return True
def play_pocket_4_of_kinds(): # hand4() or hand3() or hand2() or hand1() if Flop_Deside(): shout("Check and raise strategy") return ("check") elif Turn_Deside(): return ("raise", (2 * Max_raise_sofar()) // c.BLIND_VALUE) elif River_Deside(): return ("raise", (2 * Max_raise_sofar()) // c.BLIND_VALUE)
def find_seat_to_report(acted_players): i = not_folded_count = 0 while True: i += 1 seat_to_report = turn_finder(first_player_seat(), i) if c.seats_not_folded[seat_to_report]: not_folded_count += 1 if not_folded_count == acted_players + 1: return seat_to_report # To make sure while True does not loop infinitively. if acted_players < 0: shout('A mistake must have happened') break