⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firecircle.c

📁 偶然收集到的一个C语言源码
💻 C
字号:
/**
 * 这个例子机器人演示了如何打击作圆周运动的机器人。
 * 这个机器人用的迭代算法与FireLine类似,不过它记录了对手上个单位时间的方向,
 * 然后利用这个方向与对手当前的方向作比较,推算出对手每个单位时间的转动度数,
 * 并以此来计算对手下个单位时间将出现的位置。
 * @author xiemin
 */
#include <airobot/c/SimpleRobot.h>

//开火时的炮弹能量
#define POWER 0.5
//对手上个单位时间的方向
double lastHeading;

void onTick(struct TickAction* action)
{
	double nextX, nextY, dis, bea, nextHeading;
	long time;
	struct Bot* bot = getFirstOpponent();
	if(bot==NULL) return;
	
	//计算机器人两个单位时间的方向的夹角
	bea = bearing(bot->heading, lastHeading);
	//初始化迭代
	nextHeading = bot->heading;
	nextX = bot->x; 
	nextY = bot->y;
	time = 0;
	
	//进入迭代
	while(1)
	{
		//判断子弹在time时间后能否打到在next位置的对手
		double dis = distance(nextX, nextY, getX(), getY());
		if(dis/getBulletVelocity(POWER)<=time)
		{
			//能打到,迭代结束
			fireOnPoint(nextX, nextY, POWER); //开火
			break;
		}
		//进入下一次迭代
		time ++;
		nextHeading += bea;
		//计算在下个时间对手的位置
		nextPoint(nextX, nextY, nextHeading, bot->velocity, &nextX, &nextY);
	}
	lastHeading = bot->heading;
}
		
//启动机器人程序
int main(int argC, char* argV[])
{
	tickHook = onTick;
	return startup(argC, argV);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -