//这个机器人演示了如何用迭代的方法打击走直线的机器人
#include <airobot/c/SimpleRobot.h>
//开火时的炮弹能量
#define POWER 0.5
void onTick(struct TickAction* action)
{
double nextX, nextY, dis;
long time;
struct Bot* bot = getFirstOpponent();
if(bot==NULL) return;
time = 1;
while(1)
{
//计算在time时间后对手的位置
nextPoint(bot->x, bot->y, bot->heading, bot->velocity*time, &nextX, &nextY);
//判断子弹在time时间后能否打到在next位置的对手
dis = distance(nextX, nextY, getX(), getY());
if(dis/getBulletVelocity(POWER)<=time)
{
//能打到,迭代结束
fireOnPoint(nextX, nextY, POWER); //开火
return;
}
else time++; //进入下一次迭代
}
}
//启动机器人程序
int main(int argC, char* argV[])
{
tickHook = onTick;
return startup(argC, argV);
}
(AI-TANK)迭代的方法打击走直线的机器人
最新推荐文章于 2022-07-20 22:43:51 发布