• 分享下自己的EmpireofCode进攻策略 https://empireofcode.com/ https://empireofcode.com/game/#


    # 没什么用,该游戏的模块调用不友好,取数据难
    import queue
    from battle import commander # import math unit_client = commander.Client() doing_last_order = True towerid = [] towerrg = [] towerfr = [] towerps = [] tower_id = 0 towers = [] safe_posi=[40,40] center1 = [[40,0],[20,0]] center2 = [[20,7],[20,17]] center3 = [[20,7],[20,18]] # START Possible orders: def get_time(*args, **kawargs): my_time = unit_client.ask_cur_time() unit_client.when_time(my_time, get_to) def get_to(*args, **kawargs): global safe_posi unit_posi = unit_client.ask_units() safe_posi = [int(unit_posi[0]['coordinates'][0]/2+unit_posi[1]['coordinates'][0]/2), int(unit_posi[0]['coordinates'][1]/2+unit_posi[1]['coordinates'][1]/2)] unit_client.do_move(safe_posi) def gather(*args, **kawargs): unit_client.do_message_to_craft(get_to) def attack_center(*args, **kawargs): center = unit_client.ask_center() unit_client.do_attack(center['id']) def attack_nearest(data=None, *args, **kawargs): enemy = unit_client.ask_nearest_enemy() unit_client.do_attack(enemy['id']) def go_to_center1(*args, **kwargs): global safe_posi unit_client.do_moves(center1) safe_posi = center1[1] return safe_posi def go_to_center2(*args, **kwargs): global safe_posi unit_client.do_moves(center2) safe_posi = center2[1] return safe_posi def go_to_center3(*args, **kwargs): global safe_posi unit_client.do_moves(center3) safe_posi = center3[1] return safe_posi def go_to_center_safe(*args, **kwargs): unit_client.do_move(safe_posi) def info_get(*args, **kwargs): global safe_posi global tower_id global towerid global towerrg global towerfr global towers global towerps towers = unit_client.ask_towers() for i in range(len(towers)): towerid.append(towers[i]["id"]) towerfr.append(towers[i]["firing_range"]) towerps.append(towers[i]["coordinates"]) x, y = towers[i]["coordinates"] lenth = pow((x-safe_posi[0])**2+(y-safe_posi[1])**2,0.5) towerrg.append(int(lenth)) def attack_posi(*args, **kwargs): global towerid global towers global safe_posi global tower_id global towerrg global towerfr # global towers # towers = unit_client.ask_towers() first = towerrg.index(min(towerrg)) attac_posi = towerrg[first]-towerfr[first]-1 percent = attac_posi/towerrg[first] safe_posi = (towerps[first][0] - safe_posi[0])*percent, (towerps[first][1] - safe_posi[1])*percent unit_client.do_move(safe_posi) tower_id = towerid[first] unit_client.do_attack(tower_id) my_info = unit_client.ask_my_info() safe_posi = my_info["coordinates"] towerid.pop(first) towerrg.pop(first) towerfr.pop(first) towerps.pop(first) ## END ## START Orders, captain! orders = queue.Queue() # orders.put_nowait(gather) orders.put_nowait(go_to_center1) orders.put_nowait(go_to_center2) # orders.put_nowait(attack_nearest) orders.put_nowait(get_to) orders.put_nowait(info_get) # orders.put_nowait(get_time) # orders.put_nowait(attack_nearest) # orders.put_nowait(attack_nearest) # orders.put_nowait(attack_posi) # orders.put_nowait(go_to_center3) # orders.put_nowait(attack_posi) # orders.put_nowait(attack_posi) # orders.put_nowait(attack_posi) # orders.put_nowait(attack_posi) orders.put_nowait(attack_center) # orders.put_nowait(attack_nearest) # orders.put_nowait(attack_nearest) # orders.put_nowait(attack_nearest) # orders.put_nowait(attack_nearest) #Loop engine: def mark_as_idle(*args, **kwargs): global doing_last_order doing_last_order = False # print('ORDERS DOING: Is now', doing_last_order) unit_client.when_idle(global_scheduler) def mark_as_doing(*args, **kwargs): global doing_last_order doing_last_order = True # print('ORDERS DOING: Is now', doing_last_order) def global_scheduler(*args, **kwargs): global doing_last_order # print('LOOP: scheduler woke') # print('ORDERS COUNT:', orders.qsize()) # print('DOING ORDER ?:', doing_last_order) # needed only if coding async while not doing_last_order and not orders.empty(): mark_as_doing() next_order = orders.get() # print('ORDERS: next is "%s"' % next_order.__name__) next_order() # print('ORDERS: doing "%s"' % next_order.__name__) unit_client.when_idle(mark_as_idle) # print('LOOP: scheduler set') print ('ORDERS START COUNT:', orders.qsize()) mark_as_idle()
  • 相关阅读:
    C++ 数字、string 简便互转
    【C语言】递归函数DigitSum(n)
    UVALIVE 4287 Proving Equivalences (强连通分量+缩点)
    【linux驱动分析】misc设备驱动
    C++ auto 与 register、static keyword 浅析
    spring 计时器
    Spring注解配置定时任务<task:annotation-driven/>
    去除ckeditor上传图片预览中的英文字母
    编码规范
    git 手动操作
  • 原文地址:https://www.cnblogs.com/fengbo1113/p/8047858.html
Copyright © 2020-2023  润新知