/**
* Name:Avoid Wall
* Written by pt
* Compiler:Microsoft Visual C++
*/
#include <airobot/c/SimpleRobot.h>
//定义半径
#define RADIUS 100
//定义距离墙的距离
#define DIS_WALL 80
//定义迭代增量
#define GAP PI/12
int isValid(double nextX, double nextY)
{
//返回在距离为DIS_WALL的距离上的改点是否在战场内
return inCourt(nextX, nextY, DIS_WALL);
}
/**
* 每个单位时间都会触发
*/
void onTick(struct TickAction* action)
{
//目标点的x,y坐标
double nextX, nextY;
//方向增量初始化为0
double bearingAdd = 0;
//进入迭代
while (1)
{
//找目标点
nextPoint(getX(), getY(), getHeading()+bearingAdd, RADIUS, &nextX, &nextY);
//判断目标点是否有效
if (isValid(nextX, nextY))
{
//有效,移动到改点,停止迭代
moveTo(nextX, nextY);
return;
}
else//无效,迭代
bearingAdd += GAP;
}
}
/**
* 机器人程序入口
*/
int main(int argC, char* argV[])
{
tickHook = onTick;
return startup(argC, argV);
}
(AI-TANK)避墙,不撞墙,绕墙
最新推荐文章于 2019-12-06 14:32:19 发布