import api
import math
info = {"flag": -1}
def update(context):
me = context.me
if info["flag"] == -1:
if context.me.y > context.get_env_height() / 2:
info["flag"] = 0 # 出生在左上角
else:
info["flag"] = 1 # 出生在右下角
time = context.step / 30
# 开局一把梭
if 0.05 < time < 0.1:
print(0)
return api.a2r(180) + math.pi * info["flag"]
elif 0 < time < 0.15:
print(1)
return api.a2r(300) + math.pi * info["flag"]
elif 0.1 < time < 0.25:
print(2)
return api.a2r(235) + math.pi * info["flag"]
elif 0.4 < time < 0.45:
return api.a2r(180) + math.pi * info["flag"]
elif 1 <= time < 1.25:
return api.a2r(90) + math.pi * info["flag"]
elif 8.5 <= time < 8.8:
#pass
return api.a2r(20) + math.pi * info["flag"]
elif 10.5 <= time < 10.7:
#pass
return api.a2r(45) + math.pi * info["flag"]
elif 14 < time < 14.4:
return api.a2r(190) + math.pi * info["flag"]
elif 17 < time < 17.3:
print(17,me.mass)
return api.a2r(315) + math.pi * info["flag"]
elif 26 <= time < 26.3:
print(23)
#return api.a2r(45) + math.pi * info["flag"]
elif time > 6:
print(4)
# 获取所有非子弹类的星体列表
enemies_list = []
for i in context.enemies:
if not i.is_bullet:
enemies_list.append(i)
# 对星体列表由近到远进行排序
enemies_list.sort(key=lambda x: me.get_atom_surface_dist(x))
# 躲避策略
for i in enemies_list:
if i.mass > me.mass and me.whether_collide(i) and me.get_atom_surface_dist(i) < 30:
return me.shoot_atom_radian(i)
# 吞噬策略
enemies_selected_list = []
# 检测目标路径上是否有其他危险星体
for i in enemies_list:
better_list = api.raycast(colliders = enemies_list, origin = (me.x, me.y), direction = api.relative_radian(me.x, me.y, i.x, i.y))
if len(better_list):
if better_list[0].id != i.id and i.mass > me.mass:
continue
enemies_selected_list.append(i)
hs = abs((me.vx + me.vy)/2)
for i in enemies_selected_list:
if not me.whether_collide(i) and me.radius > i.radius > me.radius * 0.4: # 距离玩家最近的背景星体与玩家星体没有相撞趋势,同时玩家星体的半径大于距离最近的背景星体
distance = me.get_atom_surface_dist(i)
if hs < 10 and distance < 500 and me.whether_collide(i):
if context.step % 30 == 0:
return me.shoot_atom_radian(i) + math.pi
elif distance < 200 and me.whether_collide(i) :
if context.step % 10 == 0:
return me.shoot_atom_radian(i) + math.pi
elif hs < 8 and distance < 80 and me.radius > i.radius > me.radius * 0.6:
if context.step % 5 == 0:
return me.shoot_atom_radian(i) + math.pi
elif hs < 5 and me.radius > i.radius > me.radius * 0.6:
if context.step % 5 == 0:
return me.shoot_atom_radian(i) + math.pi
print(hs)
return None
打赏微信扫一扫,打赏作者吧~