def stop(state): if state['last_command'] == 'retreat': move_to_ancient(state) time.sleep(0.1) # approx time to 180 if state['last_command'] != 'stop': toggle('s') state['last_command'] = 'stop' center_camera_on_hero() log_action(state)
def stop(state): # time_last_hit is a form of stop, so no need to repeat command if state['last_command'] == 'time_last_hit': state['last_command'] = 'stop' return if state['last_command'] == 'retreat': move_to_ancient(state) time.sleep(0.1) # approx time to 180 if state['last_command'] != 'stop': toggle('s') state['last_command'] = 'stop' center_camera_on_hero() log_action(state)
def qf_retreat(state, image): ''' move if haven't moved from original position otherwise, stop when no nearby enemies ''' center_camera_on_hero() new_minimap_position = get_minimap_position(image) if np.all(np.isclose(old_minimap_position,new_minimap_position,atol=1)): move_to_mid_t3(state) return True dire_creeps = find_dire_creeps(image, middle_area) if not dire_creeps: stop(state) return dire_creeps
def midgame_iterate(state, code_interact=False): state['counter'] += 1 if state['last_command'] != 'time_last_hit': if state['counter'] % 8 == 0 or state['last_command'] == 'retreat': center_camera_on_hero() # time.sleep(0.2) # time it takes after command to center camera image = get_image() # if state['save_counter'] == 200: # save_image(image, '100.png') # if state['counter'] % 20 = 0: # Below "A or B" means "A unless A == 0 then B instead" state['hero_damage'] = get_attack_dmg(image) or state['hero_damage'] state['levels_in_e'] = 1 #get_levels_in_e(image) state['minimap_position'] = 'todo' #get_minimap_position(image) at_t2_5 = False #is_at_t2_5(image) update_dire_creeps(state, get_dire_creeps(image, middle_area)) update_rad_creeps(state, get_radiant_creeps(image, middle_area)) # if state['hero_damage'] > 100: # show_image(image) # save_image(image, 'error.png') # code.interact(local=dict(globals(), **locals())) reposition(state, state['rad_creeps'], state['dire_creeps'], at_t2_5) gold = get_gold(image) if gold - state[ 'gold'] > 30: #melee bounty 36-40, ranged 42-48, siege 66-80 if state['lh_creeps_history'] != []: state['lh_creeps_history'][-1].last_hit_success = True state['gold'] = gold # low priority actions if state['last_command'] == 'attack': if state['gold'] > 820: buy_item('phase boots') time.sleep(0.05) toggle('f3') # if state['last_command'] == 'last_hit': # save_image(image, "last_hit_%s.png" % state['counter']) if code_interact: code.interact(local=dict(globals(), **locals()))
def startup(state): '''run once at beginning of program to force application into desired state for iteration ''' buy_item('animal courier') time.sleep(0.1) toggle('z') time.sleep(1) buy_item('blades of attack') #('boots of speed') time.sleep(0.1) level_up('e') time.sleep(0.1) # toggle('a') # left_click(96, 1358) # right_click(796, 758) # time.sleep(2) right_click(96, 1348) time.sleep(10) center_camera_on_hero() time.sleep(0.1) say_in_chat(['-startgame']) time.sleep(3) state['start_time'] = time.time()
def midgame_iterate(state): state['counter'] += 1 if not state['quick_fire_funs'] and ( state['counter'] % 4 == 0 or state['last_command'] == 'retreat'): center_camera_on_hero() # time.sleep(0.2) # time it takes after command to center camera image = get_image() if state['quick_fire_funs']: execute_quickfire_functions(state, image) return # if state['save_counter'] == 200: # save_image(image, '100.png') # if state['counter'] % 20 = 0: state['hero_damage'] = get_attack_dmg(image) state['levels_in_e'] = get_levels_in_e(image) state['minimap_position'] = get_minimap_position(image) if state['levels_in_e'] == 4: dire_creeps = find_dire_creeps(image, middle_area) else: dire_creeps = find_dire_creeps(image, top_right_area) # if get_num_backstab_creeps(dire_creeps): # when pushing t4s/ancient # move_to_mid_t3(state) # # Can't add qf function because breaks too many unittests :( # state['quick_fire_funs'].append( # gen_retreat_quickfire(state['minimap_position'])) # # time.sleep(2) # return at_t2_5 = is_at_t2_5(image) # if not dire_creeps: # bad_iterate(state) # return # elif levels_in_e > 2 and not in_range(dire_creeps): # bad_iterate(state) # return rad_creeps = find_radiant_creeps(image, top_right_area) reposition(state, rad_creeps, dire_creeps, at_t2_5)
def hold_position(state): '''note: not actually used''' toggle('h') state['last_command'] = 'hold' center_camera_on_hero() log_action(state)