Пример #1
0
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
Пример #2
0
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
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
def determine_playing_seats():
    """
    playing_seats dictionary is used for calculating 
    my seat positioning ranking.
    Seated out players waiting for their first big blinds are not counted.
    """
    for seat in range(1, config.TOTAL_SEATS + 1):
        if (not pm.available_seat_pixel(config.game_position, seat)
                and pm.player_cards_pixel(config.game_position, seat)):
            config.playing_seats[seat] = True
        else:
            config.playing_seats[seat] = False

    shout("TEST. playing_seats dictionary is: %s" % config.playing_seats,
          color='on_light_red')
Пример #6
0
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 
Пример #7
0
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
Пример #8
0
def report_the_player(seat_to_report):
    #global seats_not_folded
    if not pm.player_cards_pixel(c.game_position, seat_to_report):
        c.seats_not_folded[seat] = False
        shout('Seat %s has folded' % seat_to_report, color='light_cyan')
    elif not pm.player_chips_pixel(c.game_position, seat_to_report):
        shout('Seat %s has checked' % seat_to_report, color='light_cyan')
    # It happens for big blind seat at preflop stage.
    elif (not pm.are_chips_white_or_red_pixel(c.game_position, seat_to_report)
          and seat_to_report == c.big_blind_seat):
        shout('Seat %s has checked' % seat_to_report, color='light_cyan')
    elif not pm.are_chips_white_or_red_pixel(c.game_position, seat_to_report):
        shout('Seat %s has called' % seat_to_report, color='light_cyan')
    elif pm.are_chips_white_or_red_pixel(c.game_position, seat_to_report):
        bet = ocr_bet(seat_to_report)
        shout('Seat %s has raised %s' % (seat_to_report, bet),
              color='light_cyan')
Пример #9
0
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 
Пример #10
0
def read_and_save_bets():
    #global game_position, player_cards_cache , white_chips_cache , red_chips_cache , bets_cache ,\
    #       last_white_chips_cache , last_red_chips_cache , last_player_cards_cache , last_bets_cache,\
    #       preflop_betting_round , flop_betting_round , turn_betting_round , river_betting_round ,\
    #       preflop_stage , flop_stage , turn_stage , river_stage

    if config.preflop_stage == True and config.flop_stage == False:
        stage = "Pre_Flop"
        betting_round = config.preflop_betting_round
    elif config.flop_stage == True and config.turn_stage == False:
        stage = "Flop"
        betting_round = config.flop_betting_round
    elif config.turn_stage == True and config.river_stage == False:
        stage = "Turn"
        betting_round = config.turn_betting_round
    elif config.river_stage == True:
        stage = "River"
        betting_round = config.river_betting_round

    config.player_cards_cache["%s %s" % (stage, betting_round)] = {}
    config.white_chips_cache["%s %s" % (stage, betting_round)] = {}
    config.red_chips_cache["%s %s" % (stage, betting_round)] = {}
    config.bets_cache["%s %s" % (stage, betting_round)] = {}
    config.last_player_cards_cache = {}
    config.last_white_chips_cache = {}
    config.last_red_chips_cache = {}
    config.last_bets_cache = {}

    for Seat in range(1, config.TOTAL_SEATS + 1):

        config.player_cards_cache["%s %s" %(stage, betting_round)][Seat] \
        = pm.player_cards_pixel(config.game_position, Seat)
        config.white_chips_cache["%s %s" %(stage, betting_round)][Seat] \
        = white_chips(Seat)
        config.red_chips_cache["%s %s" %(stage, betting_round)][Seat] \
        = red_chips(Seat)
        config.last_player_cards_cache[Seat] \
        = config.player_cards_cache["%s %s" %(stage, betting_round)][Seat]
        config.last_white_chips_cache[Seat] \
        = config.white_chips_cache["%s %s" %(stage, betting_round)][Seat]
        config.last_red_chips_cache[Seat] \
        = config.red_chips_cache["%s %s" %(stage, betting_round)][Seat]

        # Can replace with:
        # if pm.player_chips_pixel(config.game_position, seat):
        if (config.last_white_chips_cache[Seat] == True
                or config.last_red_chips_cache[Seat] == True):

            config.bets_cache["%s %s" %
                              (stage, betting_round)][Seat] = ocr_bet(Seat)

            if config.last_white_chips_cache[Seat] == True:
                shout("Seat%s Call: $%s" %
                      (Seat, config.bets_cache["%s %s" %
                                               (stage, betting_round)][Seat]),
                      color='light_green')

            elif config.last_red_chips_cache[Seat] == True:
                shout("Seat%s Raise: $%s" %
                      (Seat, config.bets_cache["%s %s" %
                                               (stage, betting_round)][Seat]),
                      color='light_green')
        else:

            config.bets_cache["%s %s" % (stage, betting_round)][Seat] = None
        config.last_bets_cache[Seat] \
        = config.bets_cache["%s %s" %(stage, betting_round)][Seat]

    # (2018) Delete this later. just for testing if rounds are
    # started from 0, esp at preflop stage
    shout("shouting from read_and_save_bets(), bets_cache is: %s" %
          config.bets_cache)
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)))
Пример #12
0
def set_seats_not_folded_dictionary():
    #global seats_not_folded
    c.seats_not_folded = {}
    for seat in range(1, c.TOTAL_SEATS + 1):
        c.seats_not_folded[seat] = pm.player_cards_pixel(c.game_position, seat)
Пример #13
0
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')
Пример #14
0
            and pm.notification_banner_pixel(game_position, my_seat_number) == True ):
            read_and_global_banks_and_names() 
        else :
            shout("Players Info is not Read", color = 'on_light_red')





        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")