Ejemplo n.º 1
0
def main(args):
    args = format_args()
    if args.dotabuff:
        pull_dotabuff()
    if args.sort:
        if (args.sort in SORT_INPUTS):
            save_obj(args.sort, SORTING_PICKLE_NAME)
        else:
            print("Invalid sorting value, '" + args.sort +
                  "'. Continuing with previous value.")
            print("Acceptable sorting values are as follows: ")
            for entry in SORT_INPUTS:
                print(entry)
    if args.percent:
        save_obj(args.percent, THRESHOLD_PICKLE_NAME)
    if args.addshorthand:
        add_to_shorthands(args.addshorthand, load_obj(SORTING_PICKLE_NAME))
    if args.reset:
        save_obj(2.0, THRESHOLD_PICKLE_NAME)
        save_obj(SORT_INPUTS[-1], SORTING_PICKLE_NAME)
        form_shorthands()
    if args.meta:
        get_meta()
        meta_to_prune = load_obj(BRACKET_PICKLE_NAME)
        #Each desired skill bracket will go one beyond in each direction, to account for border games
        args.meta = args.meta.replace('overall', '6')
        args.meta = args.meta.replace('all', '6')
        args.meta = args.meta.replace('ns', '1,2,3')
        args.meta = args.meta.replace('vhs', '3')
        args.meta = args.meta.replace('hs', '4,5')
        desired_brackets = args.meta.split(',')
        brackets_to_remove = [1, 2, 3, 4, 5, 6]
        for entry in desired_brackets:
            brackets_to_remove.remove(int(entry))
        for hero in meta_to_prune:
            cur_hero = meta_to_prune[hero]
            pop_shift = 1
            for entry in brackets_to_remove:
                cur_hero.pop(entry - pop_shift)
                pop_shift += 1
        save_obj(meta_to_prune, BRACKET_PICKLE_NAME)
    else:
        save_obj({}, BRACKET_PICKLE_NAME)
    if args.zeta:
        return
    elif args.captain:
        captains_mode(args.captain)
    else:
        start_picks()
Ejemplo n.º 2
0
def reset_shorthands(factory_zero=False):
    if factory_zero:
        short_dict = {}
        save_obj(short_dict, SHORTHAND_PICKLE_NAME)
    else:
        form_shorthands()
        short_dict = load_obj(SHORTHAND_PICKLE_NAME)
    return short_dict
Ejemplo n.º 3
0
def pull_dotabuff(make_new_shorthand_list=False):
    hero_len = len(HEROES_LIST)
    hero_adv_dict = {}
    hero_winrate_dict = {}
    data_start = "<table class=\"sortable\">"
    data_end = "</table>"
    adv_start = "<td class=\"cell-xlarge\">"
    adv_cutoff = "<div class=\"bar bar-default\"><div class=\"segment segment-advantage\""
    winrate_start = "</dt></dl><dl><dd>"
    winrate_end = "</span></dd>"
    i = 1
    for hero in HEROES_LIST:
        url = hero.replace(" ", "-")
        url = url.lower()
        url = url.replace("'", "")
        url = "http://www.dotabuff.com/heroes/" + url
        response = requests.get(url + "/matchups",
                                headers={'User-agent': 'your bot 0.1'})
        url_text = response.text
        search_block = html_searcher(data_start, data_end, url_text, False,
                                     True)[0]
        advantages = html_search_all(adv_start, adv_cutoff, search_block)
        adv_block = []
        for entry in advantages:
            entry_name = entry[:-5]
            entry_name = entry_name.replace("1", "")
            entry_percent = entry[-5:-1]
            if (entry_name[-1] == '-'):
                entry_name = entry_name[:-1]
                entry_percent = '-' + entry_percent
            entry_tuple = (entry_name, entry_percent)
            adv_block.append(entry_tuple)
        hero_adv_dict[hero] = adv_block

        response = requests.get(url, headers={'User-agent': 'your bot 0.1'})
        url_text = response.text
        winrate = html_searcher(winrate_start, winrate_end, url_text, False,
                                False)[0]
        hero_winrate_dict[hero] = float(winrate[:-1])
        print('{:<20}'.format(hero) + "\t" + str(i) + "/" + str(hero_len))
        i += 1
    save_obj(hero_adv_dict, ADV_PICKLE_NAME)
    save_obj(hero_winrate_dict, OVERALL_PICKLE_NAME)
    if (load_obj(SHORTHAND_PICKLE_NAME) == {}):
        form_shorthands()
    print('\n\n\n')
Ejemplo n.º 4
0
def start_picks():
    percent_threshold = load_obj(THRESHOLD_PICKLE_NAME)
    sort_option = load_obj(SORTING_PICKLE_NAME)
    hero_advantage_dict = load_obj(ADV_PICKLE_NAME)
    short_dict = load_obj(SHORTHAND_PICKLE_NAME)
    picked_heroes = []
    hero_adv_map, heroes_left = init_hero_advs()
    meta_trends = load_obj(BRACKET_PICKLE_NAME)
    for entry in meta_trends:
        brackets_of_hero = meta_trends[entry]
        for val in brackets_of_hero:
            if (val <= UNPLAYABLE_WINRATE):
                heroes_left.remove(entry)
                break
    suppress_hero_list = False
    perform_sort(heroes_left, hero_adv_map, picked_heroes, sort_option)
    while (True):
        print("\n")
        commands = input("Enter commmand: ").lower()
        commands = commands.split(",")
        for command in commands:
            output_done = False
            command = command.strip()
            if (command != ''):
                if (command == KILL_COMMAND):
                    return
                elif (command == INTERNAL_COMMANDS[0]):
                    internal_help()
                    output_done = True
                elif (command[:4] == INTERNAL_COMMANDS[1]):
                    if (len(picked_heroes) != 0):
                        picked_heroes, heroes_left, hero_adv_map = undo_pick(
                            command.split(" "), short_dict, picked_heroes,
                            heroes_left, hero_advantage_dict, hero_adv_map,
                            percent_threshold)
                elif (command[:6] == INTERNAL_COMMANDS[2]):
                    picked_heroes, heroes_left, hero_adv_map, short_dict = repick(
                        command.split(" "), short_dict, picked_heroes,
                        heroes_left, hero_advantage_dict, hero_adv_map,
                        percent_threshold)
                elif (command[:4] == INTERNAL_COMMANDS[3]):
                    proper_hero, short_dict = find_hero(
                        command[4:].strip(), short_dict, heroes_left)
                    if (proper_hero is not None):
                        print("Finding " + proper_hero)
                        perform_sort([proper_hero], hero_adv_map,
                                     picked_heroes, sort_option)
                        print(str(len(heroes_left)) + " heroes remaining.")
                        output_done = True
                    else:
                        print("Hero not left in remaining hero pool. \
                               Ill advised to pick.")
                elif (command in SORT_INPUTS):
                    perform_sort(heroes_left, hero_adv_map, picked_heroes,
                                 command)
                    print(str(len(heroes_left)) + " heroes remaining.")
                    output_done = True
                elif (command[:5] == INTERNAL_COMMANDS[4]):
                    focus_tokens = command.split(" ")
                    if (len(focus_tokens) > 1) and (focus_tokens[1]
                                                    in ROLES_NAMES):
                        heroes_left = focus_remaining_hero_pool(
                            focus_tokens[1], heroes_left, hero_adv_map,
                            picked_heroes)
                elif ((command[:3].lower() == INTERNAL_COMMANDS[5])
                      and (command[3].lower() != 'e')):
                    not_banned = [
                        hero for hero in HEROES_LIST
                        if hero not in picked_heroes
                    ]
                    heroes_left = ban_hero(command, short_dict, heroes_left,
                                           not_banned)
                elif (len(picked_heroes) < 5):
                    picked_heroes, heroes_left, hero_adv_map, short_dict = pick_hero(
                        command, short_dict, picked_heroes, heroes_left,
                        hero_advantage_dict, hero_adv_map, percent_threshold)
                else:
                    if (len(picked_heroes) == 5):
                        str_append = "The maximum number of heroes have \
                                      been picked"

                    else:
                        str_append = "Invalid user input."
                    print("COMMAND BLOCKED: " + str_append)
                if (len(picked_heroes) > 0):
                    if (output_done is False):
                        perform_sort(heroes_left, hero_adv_map, picked_heroes,
                                     sort_option)
                        print(str(len(heroes_left)) + " heroes remaining.")
                    print("\n\nPicked heroes:")
                    for hero in picked_heroes:
                        print(hero)
                    print("\n**********\n")
Ejemplo n.º 5
0
def captains_mode(starter):
    #may need a ban list
    first_actor = starter
    if (starter == 'Radiant'):
        second_actor = 'Dire'
    else:
        second_actor = 'Radiant'
    percent_threshold = load_obj(THRESHOLD_PICKLE_NAME)
    sort_option = load_obj(SORTING_PICKLE_NAME)
    hero_adv_dict = load_obj(ADV_PICKLE_NAME)
    short_dict = load_obj(SHORTHAND_PICKLE_NAME)
    banned_heroes = []
    heroes_picked_first = []
    heroes_picked_second = []
    hero_adv_map_first, heroes_left_first = init_hero_advs()
    hero_adv_map_second, heroes_left_second = init_hero_advs()

    for hero in CAPTAINS_UNALLOWED_HEROES:
        heroes_left_first.remove(hero)
        heroes_left_second.remove(hero)
    for action in PICK_BAN_ORDER:
        #add typo/nothing picked or banned handler
        #add repick support? probably not
        actor = action % 2
        if (actor == 0):
            actor_str = first_actor
        else:
            actor_str = second_actor  #add 'already banned' handler
        if (action <= 1):
            hero = input(actor_str + "'s ban: ")
            to_check = [
                hero for hero in HEROES_LIST if hero not in heroes_picked_first
            ]
            to_check = [
                hero for hero in to_check if hero not in heroes_picked_second
            ]
            heroes_left_first = ban_hero(hero, short_dict, heroes_left_first,
                                         to_check, True)
            heroes_left_second = ban_hero(hero, short_dict, heroes_left_second,
                                          to_check, True)
            banned_heroes.append(hero)  #need a checker...
        else:
            hero = input(actor_str + "'s pick: ")
            picked_heroes = heroes_picked_first + heroes_picked_second
            if (action == 2):
                heroes_left = heroes_left_second
                adv_map = hero_adv_map_second
            else:
                heroes_left = heroes_left_first
                adv_map = hero_adv_map_first
            if hero not in picked_heroes:
                picked_heroes_both, heroes_left_second, adv_map, short_dict = pick_hero(
                    hero, short_dict, picked_heroes, heroes_left,
                    hero_adv_dict, adv_map, percent_threshold)
            if (action == 2):
                heroes_left_second = heroes_left
                hero_adv_map_second = adv_map
                heroes_picked_first = [
                    hero for hero in picked_heroes
                    if hero not in heroes_picked_second
                ]
            else:
                heroes_left_first = heroes_left
                hero_adv_map_first = adv_map
                heroes_picked_second = [
                    hero for hero in picked_heroes
                    if hero not in heroes_picked_first
                ]
        if (actor == 0):
            heroes_left = heroes_left_second
            advs = hero_adv_map_second
            picked = heroes_picked_first
        else:
            heroes_left = heroes_left_first
            advs = hero_adv_map_first
            picked = heroes_picked_second
        perform_sort(heroes_left, advs, picked, sort_option)
        print(str(len(heroes_left)) + " heroes remaining.")
        print("\n\n" + actor_str + " picked heroes:")
        for hero in picked:
            print(hero)
        print("\n\nAll banned heroes:")
        for hero in banned_heroes:
            print(hero)
        print("\n**********\n")
Ejemplo n.º 6
0
import sys
from pickleSerializers import save_obj, load_obj

CLOSED = 0
OPEN = 1
#DRAWERS = {1: CLOSED, 2: CLOSED, 3: CLOSED}
#ITEM_MAPS = {}

DRAWER_STATUS_PICKLE_NAME = 'drawermappings'
ITEM_MAP_PICKLE_NAME = 'itemmappings'
try:
    DRAWERS = load_obj(DRAWER_STATUS_PICKLE_NAME)
    ITEM_MAPS = load_obj(ITEM_MAP_PICKLE_NAME)
except:
    DRAWERS = {1: CLOSED, 2: CLOSED, 3: CLOSED}
    ITEM_MAPS = {}


def main(args):
    print("Drawer initialized")
    while (True):  #open drawer, close drawer, add item drawer, remove item
        print("\n")
        print(DRAWERS)
        print(ITEM_MAPS)
        commands = input("Enter commmand: ").lower()
        commands = commands.split(" ")
        if (commands[0] == 'open'):
            if (int(commands[1]) in DRAWERS):
                open_drawer(int(commands[1]))
        elif (commands[0] == 'close'):
            if (int(commands[1]) in DRAWERS):