Robocode 超级机器人 “波”统计瞄准算法

获取当前帧的敌人的位置和自己的位置以及射击的角度,子弹的速度每一帧获取一次当有足够多的数据后,根据当前的位置和角度,获取之前最有可能打中地方的攻击方式。Robocode    模式匹配和随机移动波保存敌人的起始点、自己的起始点、与敌人的绝对夹角、敌人的距离、发现敌人的时间、射击角度、速度的水平分量、速度的垂直分量“波”统计瞄准算法进行模式匹配直线瞄准以及圆周瞄准算法都是全匹配算法我们将拥有超级机器...
摘要由CSDN通过智能技术生成
获取当前帧的敌人的位置和自己的位置以及射击的角度,子弹的速度
每一帧获取一次
当有足够多的数据后,根据当前的位置和角度,获取之前最有可能打中地方的攻击方式。

Robocode    模式匹配和随机移动
波保存敌人的起始点、自己的起始点、与敌人的绝对夹角、敌人的距离、发现敌人的时间、射击角度、速度的水平分量、速度的垂直分量

“波”统计瞄准算法进行模式匹配

直线瞄准以及圆周瞄准算法都是全匹配算法

我们将拥有超级机器人“波”统计瞄准算法与直线瞄准和圆周瞄准算法的机器人进行比拼

//传播波的算法
package com.xalead.superrobot;
import java.awt.geom.Point2D;
import robocode.AdvancedRobot ;
import robocode.Condition;
import robocode.Rules;
import robocode.util.Utils;
import com.xalead.superrobot.model.Battle;
public class Wave extends Condition{
        //自己的起始点坐标
        private Point2D.Double myStartPos = null ;
        //创建这个波时敌人的绝对夹角
        private double absBearing = 0;
        //发现敌人的时间
        private double startTime ;
        //敌人的距离
        private double dist ;
        //速度垂直分量
        private double adSeg ;
        //速度的水平分量
        private double velSeg ;
        //这个值只有当波碰到敌人时才能产生
        private double angle ;
        //战场模型的引用
        private Battle battle = null ;
        //执有机器人的引用
        private WaveSurfing robot = null ;
        public Wave(){}
        public Wave(Battle battle){
              this . battle = battle;
              robot = (WaveSurfing)battle.getRobot();
       }
        public Point2D.Double getMyStartPos() {
              return myStartPos ;
       }
        public void setMyStartPos(Point2D.Double myStartPos) {
              this . myStartPos = myStartPos;
       }
        public double getAbsBearing() {
              return absBearing ;
       }
        public void setAbsBearing( double absBearing) {
              this . absBearing = absBearing;
       }
        public double getStartTime() {
              return startTime ;
       }
        public void setStartTime( double startTime) {
              this . startTime = startTime;
       }
        public double getDist() {
              return dist ;
       }
        public void setDist( double dist) {
              this . dist = dist;
       }
        public double getAdSeg() {
              return adSeg ;
       }
        public void setAdSeg( double adSeg) {
              this . adSeg = adSeg;
       }
        public double getVelSeg() {
              return velSeg ;
       }
        public void
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package ms; import robocode.*; import java.util.*; //******************************************************************************************/ // GoodBot: determine, if a bot is a bastart or not // // needed: public void run() // GoodBot.Reset(); // public void onRobotDeath(RobotDeathEvent e) // GoodBot.BotDeath(e.getName(), this); // // example: public void onScannedRobot(ScannedRobotEvent e) // if (GoodBot.badBot(e.getName(), this)) //******************************************************************************************/ class GoodBot { static private Hashtable Bots = new Hashtable(); static private int GoodBots1 = 1; static private int GoodBots2 = 0; static private String bot; static public int KilledGoodBots1 = 0; static public int KilledGoodBots2 = 0; //******************************************************************************************/ // BadBot: is it a bad bot? //******************************************************************************************/ public static boolean badBot(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); int others = in_this.getOthers(); if ( (bot.compareTo("1") == 0) && (others >= GoodBots1 - KilledGoodBots1) ) return false; else if ( (bot.compareTo("2") == 0) && (others >= GoodBots1 - KilledGoodBots1 + GoodBots2 - KilledGoodBots2) ) return false; else return true; } public static void BotDeath(String Name, AdvancedRobot in_this) { bot = (String)Bots.get(Name); if (bot == null) classBot(Name, in_this); if ( bot.compareTo("1") == 0 ) KilledGoodBots1++; else if ( bot.compareTo("2") == 0 ) KilledGoodBots2++; } public static void Reset() { KilledGoodBots1 = 0; KilledGoodBots2 = 0; } private static void classBot(String Name, AdvancedRobot in_this) { int M_GoodBots = GoodBots1; String Gegnertyp = botTyp(Name); String Mytyp = botTyp(in_this.getName()); if (Gegnertyp.compareTo(Mytyp) == 0) { bot = "1"; if (GoodBots1 > M_GoodBots) in_this.out.println("I've found " + (GoodBots1 - 1) + " more " + Mytyp + "-Bot(s)."); } else { GoodBots1 = M_GoodBots; String Gegnerpack = botTyp2(Name); String Mypack = botTyp2(in_this.getName()); if (Gegnerpack.compareTo(Mypack) == 0) { bot = "2"; GoodBots2++; in_this.out.println("I've found " + (GoodBots2) + " more " + Mypack + "-Bot(s)."); } else bot = "0"; } Bots.put(Name, new String(bot)); } private static String botTyp(String BotName) { int k=BotName.indexOf("("); if (k != -1) { int Nr=Integer.parseInt(BotName.substring(k+1, BotName.indexOf(")")),10); if (GoodBots1 < Nr) GoodBots1 = Nr; return BotName.substring(0, k-1); } else return BotName; } private static String botTyp2(String BotName) { int k=BotName.indexOf("."); if (k != -1) { return BotName.substring(0, k); } else return BotName; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值