您的位置:首页 > 其它

直线提前量瞄准

2015-09-23 13:23 369 查看
import org.robochina.airobot.tank.*;
import org.robochina.math.*;
import java.awt.geom.*;
import java.util.*;

public class FireFirst extends SimpleRobot
{
private double opponentVelocity;//对手的速度
private double power = 1;//炮弹的能量
private double bulletVelocity;//炮弹的速度
private double headingAB;//连线AB的方向
private double headingAC;//连线AC的方向
private double bearingCAB;//求出<CAB
private double sinCAB;//cab的正弦值
private double angleACB;//acb的值
private double headingCB;//CB连线的方向角
/**
* 每个单位时间都会触发
*/
public void onTick(TickAction action){

//得到对手的信息
Bot opponent = this.getFirstOpponent();
//如果对手不存在就返回
if (opponent == null) {
return;
}
//得到对手的速度
opponentVelocity = opponent.getVelocity();
//求炮弹的速度
bulletVelocity = 20-3*power;
//求连线AB的方向角
headingAB = opponent.getHeading();
//求AC连线的方向角
headingAC = MathUtils.heading(opponent.getLocation(),getLocation());
//求角cab
bearingCAB = MathUtils.bearing(headingAB,headingAC);
//求角cab的正弦值
sinCAB = Math.sin(bearingCAB);
//求角acb的值
angleACB = Math.asin(opponentVelocity*sinCAB/bulletVelocity);
//cb连线的方向角
headingCB = headingAC+Math.PI-angleACB;
fire(headingCB,1);
}

/**
* 当开始一轮新的比赛时触发
*/
public void onRoundBegin(RoundBeginAction action){}

/**
* 当一轮比赛结束时触发
*/
public void onRoundFinish(RoundFinishAction action){}

/**
* 当开始一场新的比赛时触发
*/
public void onMatchBegin(MatchBeginAction action){}

/**
* 当整场比赛结束时触发
*/
public void onMatchFinish(MatchFinishAction action){}

/**
* 当有队友向自己发送消息时触发
*/
public void onMessageReceived(MessageReceivedAction action){}

/**
* 当撞到其它机器人时触发
*/
public void onHitRobot(HitRobotAction action){}

/**
* 当撞到墙时触发
*/
public void onHitWall(HitWallAction action){}

/**
* 当任意一个机器人开火时触发
*/
public void onFire(FireAction action){}

/**
* 当有机器人死亡时触发
*/
public void onRobotDeath(RobotDeathAction action){}

/**
* 当自己的子弹击中敌人时触发
*/
public void onBulletHit(BulletHitAction action){}

/**
* 当被别人的子弹击中时触发
*/
public void onHitedByBullet(HitedByBulletAction action){}

/**
* 机器人程序入口
* @param args
*/
public static void main(String[] args)
{
startup(args, new FireFirst());
}
}


    在这个算法中我们运用的是三角函数的算法来实现,这个也可以用迭代子弹的方法来实现瞄准的算法

    比如现在你在C点,敌人在A点,运动事件为t的情况下走到B点。这个时候我们需要朝着bc连线的方向打击敌人。



是不是一个图就搞定了。嗯是的有时候一直在那想不如自己画画,画画就出来了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: