(AI-TANK)迭代的方法打击走直线的机器人

来源:互联网 发布:维多利亚时代 知乎 编辑:程序博客网 时间:2024/05/05 15:48
//这个机器人演示了如何用迭代的方法打击走直线的机器人#include <airobot/c/SimpleRobot.h>//开火时的炮弹能量#define POWER 0.5void 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);}

原创粉丝点击