Example #1
0
def start_game(browser,size):
    if type(browser) == webdriver.Firefox:
        browser_str = "Firefox"
    if type(browser) == webdriver.Chrome:
        browser_str = "Chrome"
    mouse = Mouse(browser=browser_str)
    mouse.set_center(size[0]/2,size[1]/2)
    mouse.set_position(0,0)
    browser.get('http://agar.io')
    element = 0
    while not element:
        try:
            element = browser.find_element_by_id("nick")
            #element.send_keys("Bad Bot")
            browser.find_element_by_class_name('btn-settings').click()
            box_list = browser.find_elements_by_xpath("//input[@type='checkbox']")
            i = 0
            for box in box_list:
                if i != 3:
                    box_list[i].click()
                i += 1
            browser.find_element_by_class_name('btn-play-guest').click()
        except:
            continue
        play_game(browser,size)
Example #2
0
def play_game(browser, size):
    i = 0
    while True:
        mouse = Mouse()
        mouse.set_center(size[0]/2, size[1]/2)
        angle = None
        safe = True
        image = get_image(browser)
        #cv2.imwrite(home + "/AgarBot/images/image"+str(i)+".png",image)
        blobs = find_blobs(image,size)
        if not blobs:
            continue
        me = find_me(blobs,size)
        remove_name(blobs,me)
        threats, food = classify(blobs,me)
        #if menu(image):
            #print("menu")
        if threats:
            angle = avoid(threats,size)
            safe = False
        wall_list = walls(blobs, me)
        angle = avoid_walls(wall_list, angle)
        angle = eat(food, size, angle, safe)
        if angle:
            mouse.set_angle(angle)
        i+=1