📄 firefirst.cpp
字号:
#include <airobot/cpp/SimpleRobot.hpp>
/**
* 这个机器人演示了如何打击走直线的机器人
* @author xiemin
*/
class FireFirst : public SimpleRobot
{
private:
double opponentVelocity; /* 对手的速度 */
double power = 1; /* 炮弹的能量 */
double bulletVelocity; /* 炮弹的速度 */
double headingAB; /* 连线AB的方向角*/
double headingAC; /* 连线AC的方向角*/
double bearingCAB; /* ∠CAB */
double sinCAB; /* ∠CAB的正弦值*/
double angleACB; /* ∠ACB的值*/
double headingCB; /* CB连线的方向角*/
/**
* 每个单位时间都会触发
*/
public:
void onTick(TickAction action){
Bot* bot = getFirstOpponent();
if(bot==NULL) return;
opponentVelocity = bot->velocity;
bulletVelocity = 20 - 3*power; /*求炮弹的速度*/
headingAB = bot->heading;/*求连线AB的方向角*/
headingAC=heading(bot->x,box->y,getX(),getY());/*求连线AC的方向角*/
bearingCAB = bearing(headingAB, headingAC);/* 求∠CAB */
sinCAB = Math::sin(bearingCAB);/* 求∠CAB的正弦值*/
/* 求∠ACB的值*/
angleACB = asin(opponentVelocity * sinCAB / bulletVelocity); headingCB = headingAC + PI - angleACB;
fire(headingCB,power);
}
};
//启动机器人程序
int main(int argC, char* argV[])
{
Robot* robot = new FireFirst();
return startup(argC, argV, robot);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -