1、游戏规则:

生命规则:

​ 相撞损失:撞到墙时,生命点损伤度=Math.abs (velocity) * 0.5 -1。撞到另一个坦克时,移动停止,生命点损失6点,扣除积分1.2分。
​ 击中损失:当子弹能量为1时,我们生命点损失=4 * power,如果子弹能量大于1,那么我们的生命损失+= 2 * (power-1)。
​ 发射损失:如果我们的子弹打中别的坦克,我们可以从子弹那窃取到3*power的能量。

炮弹规则:

​ 子弹能量:子弹能量是通过凼数getPower()得到的。它大于等于0.1,小于等于3。
​ 子弹速度:每一颗子弹有着自身的速度,这在处理敌人向你开炮前的秱动策略可是很有帮助的。子弹的速度也和它的能量有关: speed = 20 - 3 * power。由于能量范围在0.1到3之间我们可求得子弹的速度范围:11 <= bullet speed <= 19.7。

炮管规则:

​ 旋转速率:炮管在每一个时间周期内旋转速率=20 度/帧(frame)
​ 炮管热量:当我们开火时,炮管产生的热量由子弹开火时的能量决定。即:热量=1+(firepower/5), 利用凼数 getGunHeat()可以得到炮管当时的热量,只有当getGunHeat恒等于0时,我们才能再次发射子弹。
​ 冷却度:有热度当然就有冷却度,丌冷却我们的炮管会永远丌会开火的。系统设定的默认冷却速度是0.1/tick(时间周期),我们可通过凼数 getGunCoolingRate()得到这个参数值。

雷达规则:

​ 旋转速度:雷达以每时间周期45度的速度旋转。也即45 degrees/frame.
​ 扫描面积: 雷达扫描是呈扇形的,它的开始位置到终止位置的长度大约为1200。只要我们放大屏幕可以通过眼睛估算出这个面积。
​ 扫描排列:扫描到的数据有墙,目标,子弹等等。这些是按扫描距离来排列,从离雷达最近的物体开始到最后扫描到的物体。

运行规则:

​ 前进速度:坦克最大的速度(Velocity)为8,凼数getVelocity()迒回了坦克当前的速度。
​ 加/减速度:加速度为 1 像素(pixel)/帧frame ,减速度为 2 pixel/frame。
​ 参考公式: 设s为距离,Vt为终速度,Vo为初速度,t为时间,a 为加速度:
​ 位秱公式 s=Vot+att/2
​ 速度公式 Vt =Vo +a
t
​ 平均速度公式 v=(Vt + Vo)/2=s/t
​ 加速度公式 a=(Vt - Vo)/t
​ (这些公式大家都学过吧?)

旋转规则:

​ 旋转速度:机器人的旋转速度和当前的速度有关即旋转速度=10 - 0.75 * getVelocity()。
​ 相互作用参数:雷达安装在炮上,炮安装在机器人上,它们会相互影响。如果我们向左转动炮管,而使雷达向右转动,那么雷达只会向右转动(45-20) =25度;如果两者都向右转动,雷达将向右转(45+20)=65度。同样的道理炮和机器人也是方向同相加,方向反相减。

积分规则:

​ Robot Name - 机器人的名字;
​ Total Scroe - 为这次比赛你的总共得分;
​ Survival - 是你存活率的得分;
​ Last Survivor Bonus:你是赢的次数相对对手的分红得分;
​ Bullet Dmg:是你的子弹损失得分也即发射的子弹数的得分;
​ Bonus:是子弹数的分红得分;
​ Ram Dmg *2是你的撞击得分;
​ Bonus:是你撞击得分分红;
​ 最后两项Survival 1sts,是你赢的次数,丌算做分数。

部分接口:

部分重要的接口函数介绍(全部函数参考安装文件夹下的Javadoc文件夹):坦克属性:double getBattleFieldHeight() 战场高度double getBattleFieldWidth() 战场宽度   double getHeight() 坦克高度String getName() 坦克名称double getWidth() 坦克宽度   double getGunHeading() 炮管角度double getHeading() 坦克角度double getRadarHeading() 雷达角度   double getX() 坐标Xdouble getY() 坐标Y   double getGunHeat() 炮管热量double getEnergy() 能量数值double getGunCoolingRate() 炮管冷却比例   double getVelocity() 坦克速度运行控制:void ahead(double distance) 前进void back(double distance) 后退void doNothing() 空void fire(double power) 开火   void setAdjustGunForRobotTurn(boolean independent) 炮/车同向void setAdjustRadarForGunTurn(boolean independent) 炮/雷达同向void setAdjustRadarForRobotTurn(boolean independent) 雷达/车同向   void turnRadarLeft(double degrees) 雷达左转角度void turnRadarRight(double degrees) 雷达右转角度void turnGunLeft(double degrees) 炮左转角度void turnGunRight(double degrees) 炮右转角度void turnLeft(double degrees) 车左转角度void turnRight(double degrees) 车右转角度战斗事件:void onBulletHit(BulletHitEvent event) 子弹击中坦克void onBulletHitBullet(BulletHitBulletEvent event) 子弹击中子弹void onBulletMissed(BulletMissedEvent event) 子弹没有击中目标void onDeath(DeathEvent event) 坦克被消灭的时候void onHitByBullet(HitByBulletEvent event) 被子弹击中void onHitRobot(HitRobotEvent event) 被坦克撞击void onHitWall(HitWallEvent event) 撞墙void onRobotDeath(RobotDeathEvent event) 坦克死亡void onScannedRobot(ScannedRobotEvent event) 扫描到坦克void onWin(WinEvent event) 胜利   void run() 运行 voidscan() 扫描ScannedRobotEvent –雷达扫描:double getBearing() 获得相对自己坦克方向的角度double getBearingRadians() 获得相对自己坦克方向的弧度double getDistance() 获得距离double getEnergy() 获得运行能量double getHeading() 获得方向角度double getHeadingRadians() 获得方向弧度String getName() 获得坦克名称double getVelocity() 获得运行速度构造坦克的方式:Robot (常用) –支持较为全面的简单控制逻辑;TeamRobot –支持团队作战模式;AdvancedRobot –支持自定义事件.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uDgVfsQd-1573645318604)(C:\Users\root\Desktop\assets\1573610781554.png)]

2、机器人Demo

import robocode.*;import java.awt.Color;/*** SnippetBot - a robot by Alisdair Owens* This bot includes all sorts of useful snippets.  It is not* designed to be a good fighter (although it does well 1v1),* just to show how certain things are done* Bits of code lifted from Nicator and Chrisbot* Conventions in this bot include: Use of radians throughout* Storing absolute positions of enemy bots rather than relative ones* Very little code in events* These are all good programming practices for robocode* There may also be methods that arent used; these might just be useful for you.*/public class SnippetBot extends AdvancedRobot{/*** run: SnippetBot's default behavior*/Enemy target;                   //our current enemy  代表对手,包括了对手的所有有用参数final double PI = Math.PI;          //just a constant int direction = 1;              //direction we are heading...1 = forward, -1 = backwards//我们坦克车头的方向double firePower;                   //the power of the shot we will be using - set by do firePower() 设置我们的火力public void run() {target = new Enemy();               //实例化Enemy()类target.distance = 100000;           //initialise the distance so that we can select a targetsetColors(Color.red,Color.blue,Color.green);    //sets the colours of the robot//the next two lines mean that the turns of the robot, gun and radar are independant//让gun,radar独立于坦克车setAdjustGunForRobotTurn(true);setAdjustRadarForGunTurn(true);turnRadarRightRadians(2*PI);            //turns the radar right around to get a view of the field 以弧度计算旋转一周while(true) {doMovement();               //Move the bot 移动机器人doFirePower();              //select the fire power to use 选择火力doScanner();                //Oscillate the scanner over the bot 扫描doGun();                    //move the gun to predict where the enemy will be 预测敌人,调整炮管out.println(target.distance);       fire(firePower);            //所有动作完成后,开火execute();              //execute all commands  上面使用的都为AdvancedRobot类中的非阻塞调用//控制权在我们,所有这里用阻塞方法返回控制给机器人}}/** This simple function calculates the fire power to use (from 0.1 to 3)* based on the distance from the target.  We will investigate the data structure* holding the target data later.*/void doFirePower() {firePower = 400/target.distance;//selects a bullet power based on our distance away from the target //根据敌人距离来选择火力,因为本身前进,后退为300,所以火力不会过大}/** This is the movememnt function.  It will cause us* to circle strafe the enemy (ie move back and forward,* circling the enemy.  if you don't know what strafing means* play more quake.* The direction variable is global to the class.  Passing a* negative number to setAhead causes the bot to go backwards* 以目标主中心来回摆动*/void doMovement() {if (getTime()%20 == 0)  //?过20的倍数时间就反转方向{//every twenty 'ticks'direction *= -1;        //reverse directionsetAhead(direction*300);    //move in that direction}setTurnRightRadians(target.bearing + (PI/2)); //every turn move to circle strafe the enemy //每一时间周期以敌人为中心绕圆运动}/** this scanner method allows us to make our scanner track our target.* it will track to where our target is at the moment, and some further* in case the target has moved.  This way we always get up to the minute* information on our target   雷达锁定目标*/void doScanner() {double radarOffset;  //雷达偏移量if (getTime() - target.ctime > 4) //???why来回扫了4个回合都没扫到意味失去了目标,再全扫一遍{//if we haven't seen anybody for a bit....radarOffset = 360;      //rotate the radar to find a target} else {//next is the amount we need to rotate the radar by to scan where the target is now//通过扫描决定雷达旋转的弧度,"见基本原理方向剖析及目标锁定www.robochina.org".雷达弧度-敌人角度得到两者相差为旋转值radarOffset = getRadarHeadingRadians() - absbearing(getX(),getY(),target.x,target.y);//this adds or subtracts small amounts from the bearing for the radar to produce the wobbling//and make sure we don't lose the target//在得到的角度中加或减一点角度,让雷达很小的范围内摆而不失去目标if (radarOffset < 0)radarOffset -= PI/8;  //(0.375)elseradarOffset += PI/8; }//turn the radarsetTurnRadarLeftRadians(NormaliseBearing(radarOffset)); //左转调整转动角度到PI内}/** This simple method moves the gun to the bearing that we predict the* enemy will be by the time our bullet will get there.* the 'absbearing' method can be found in the helper functions section* the nextX and nextY method can be found in the 'Enemy' class description*/void doGun() {//works out how long it would take a bullet to travel to where the enemy is *now*//this is the best estimation we have //计算子弹到达目标的时间长speed = 20 - 3 * power;有计算公式,距离除速度=时间long time = getTime() + (int)(target.distance/(20-(3*firePower)));//offsets the gun by the angle to the next shot based on linear targeting provided by the enemy class//以直线为目标,偏移子弹下一次发射的角度。(这样让子弹射空的几率减少。但对付不动的和做圆运动的机器人有问题)//target.guesssX(),target.guessY()为目标移动后的坐标double gunOffset = getGunHeadingRadians() - absbearing(getX(),getY(),target.guessX(time),target.guessY(time));setTurnGunLeftRadians(NormaliseBearing(gunOffset));  //调整相对角度到2PI内}/** This set of helper methods.  You may find several of these very useful* They include the ability to find the angle to a point.*///if a bearing is not within the -pi to pi range, alters it to provide the shortest angledouble NormaliseBearing(double ang) {if (ang > PI)ang -= 2*PI;if (ang < -PI)ang += 2*PI;return ang;}//if a heading is not within the 0 to 2pi range, alters it to provide the shortest angledouble NormaliseHeading(double ang) {if (ang > 2*PI)ang -= 2*PI;if (ang < 0)ang += 2*PI;return ang;}//returns the distance between two x,y coordinates '**'//以两边长求得与对手之间的距离public double getrange( double x1,double y1, double x2,double y2 ){double xo = x2-x1;double yo = y2-y1;double h = Math.sqrt( xo*xo + yo*yo ); return h;   }//gets the absolute bearing between to x,y coordinates//根据x,y的坐标求出绝对角度,见"坐标锁定"利用直角坐标系来反求出角度。???public double absbearing( double x1,double y1, double x2,double y2 ){double xo = x2-x1;double yo = y2-y1;double h = getrange( x1,y1, x2,y2 );if( xo > 0 && yo > 0 ){//反正弦定义,对边除斜边得弧度.以robocode中的绝对方向系及坐标系参照//x,y为正右上角为0-90,x正y负右下角为90-180,x,y负左下角180-270,x负,y正右上角270-360//此处要理解robocode中的绝对角度是上为0,下为180,如以中心为点划分象限则得到下面的结果return Math.asin( xo / h );}if( xo > 0 && yo < 0 ){return Math.PI - Math.asin( xo / h ); //x为正,y为负第二象限角}if( xo < 0 && yo < 0 ){return Math.PI + Math.asin( -xo / h ); //第三象限内180+角度}if( xo < 0 && yo > 0 ){return 2.0*Math.PI - Math.asin( -xo / h ); //四象限360-角度}return 0;}/*** onScannedRobot: What to do when you see another robot* 扫描事件,也是初始化目标数据的过程*/public void onScannedRobot(ScannedRobotEvent e) {//if we have found a closer robot....if ((e.getDistance() < target.distance)||(target.name == e.getName())) {//the next line gets the absolute bearing to the point where the bot is//求得对手的绝对弧度double absbearing_rad = (getHeadingRadians()+e.getBearingRadians())%(2*PI);//this section sets all the information about our targettarget.name = e.getName();//求得对手的x,y坐标,见"robocode基本原理之坐标锁定"文章target.x = getX()+Math.sin(absbearing_rad)*e.getDistance(); //works out the x coordinate of where the target istarget.y = getY()+Math.cos(absbearing_rad)*e.getDistance(); //works out the y coordinate of where the target istarget.bearing = e.getBearingRadians();target.head = e.getHeadingRadians();target.ctime = getTime();               //game time at which this scan was produced 扫描到机器人的游戏时间target.speed = e.getVelocity();         //得到敌人速度target.distance = e.getDistance();}}public void onRobotDeath(RobotDeathEvent e) {if (e.getName() == target.name)target.distance = 10000; //this will effectively make it search for a new target}   }/** This class holds scan data so that we can remember where enemies were* and what they were doing when we last scanned then.* You could make a hashtable (with the name of the enemy bot as key)* or a vector of these so that you can remember where all of your enemies are* in relation to you.* This class also holds the guessX and guessY methods. These return where our targeting* system thinks they will be if they travel in a straight line at the same speed* as they are travelling now.  You just need to pass the time at which you want to know* where they will be.* 保存我们扫描到的目标的所有有用数据,也可用hashtable,vector方法处理所有和我们有关的目标数据(用于群战)* 中间的guessX,guessY方法是针对做直线均速运动机器人一个策略*/class Enemy {/** ok, we should really be using accessors and mutators here,* (i.e getName() and setName()) but life's too short.*/String name;public double bearing;public double head;public long ctime; //game time that the scan was producedpublic double speed;public double x,y;public double distance;public double guessX(long when){//以扫描时和子弹到达的时间差 * 最大速度=距离, 再用对手的坐标加上移动坐标得到敌人移动后的坐标long diff = when - ctime;return x+Math.sin(head)*speed*diff; //目标移动后的坐标}public double guessY(long when){long diff = when - ctime;return y+Math.cos(head)*speed*diff;}}

3、机器人强化版


import robocode.*;
import java.awt.*;import java.awt.Event;import javax.lang.model.element.ExecutableElement;import javax.swing.text.Document;import robocode.AdvancedRobot;import robocode.HitByBulletEvent;
import robocode.HitWallEvent;
import robocode.Robot;import robocode.ScannedRobotEvent;public class YanAn extends AdvancedRobot{private double eDist; //对方的距离private double move; //移动的距离private double radarMove = 45; //雷达移动的角度private double dFirePower; //火力boolean movingForward;/**- run: Crazy's main run function*/public void run() {eDist = 300;// 颜色setColors(Color.ORANGE, Color.BLUE, Color.RED, Color.WHITE, Color.GRAY);while(true){//每过一个周期,运动随机的距离double period = 4*((int)(eDist/80)); //周期;敌人越接近,周期越短,移动越频繁//周期开始,则移动if(getTime()%period == 0){move = (Math.random()*2-1)*(period*8 - 25);setAhead(move + ((move >= 0) ? 25: -25));}//避免撞墙double heading = getHeadingRadians(); //取得bot方向的弧度数double x = getX() + move*Math.sin(heading); //移动move后将要达到的x坐标double y = getY() + move*Math.cos(heading); //移动move后将要达到的y坐标double dWidth = getBattleFieldWidth(); //战场的宽度double dHeight = getBattleFieldHeight(); //战场的长度//当(x,y)超过指定的范围,则反向移动moveif(x < 30 || x > dWidth-30 || y < 30 || y > dHeight-30){setBack(move);}turnRadarLeft(radarMove); //转动雷达execute();}}public void onHitWall(HitWallEvent e) {// Bounce off!reverseDirection();}public void reverseDirection() {if (movingForward) {setBack(40000);movingForward = false;} else {setAhead(40000);movingForward = true;}}/**- onScannedRobot:  Fire!*///onScannedRobot()每当‒在一个动作中‒看到另一个机器人时,游戏就会调用您的方法。它会发送一个事件,该事件可以告诉我们有关机器人的信息-机器人的名称,寿命,位置,前进方向,运行速度等。public void onScannedRobot(ScannedRobotEvent e) {eDist = e.getDistance(); //取得对方距离radarMove = -radarMove; //设置雷达double eBearing = e.getBearingRadians(); //取得和对方相对角度的弧度数//将bot转动相对的角度,以后bot的运动将是以对方为圆心的圆周运动setTurnLeftRadians(Math.PI/2 - eBearing);//转动炮管指向对方setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(getHeadingRadians() + eBearing - getGunHeadingRadians()));//根据对方距离射击dFirePower = 400/eDist;if (dFirePower > 3){dFirePower = 3;}fire(dFirePower);}/**- onHitRobot:  Back up!*/public void onHitRobot(HitRobotEvent e) {// If we're moving the other robot, reverse!if (e.isMyFault()) {reverseDirection();}}}

4、网站

机器人官网https://robocode.sourceforge.io/IDEA环境开发机器人https://my.oschina.net/kanlianhui/blog/1556868ve = -radarMove; //设置雷达double eBearing = e.getBearingRadians(); //取得和对方相对角度的弧度数//将bot转动相对的角度,以后bot的运动将是以对方为圆心的圆周运动setTurnLeftRadians(Math.PI/2 - eBearing);//转动炮管指向对方setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(getHeadingRadians() + eBearing - getGunHeadingRadians()));//根据对方距离射击dFirePower = 400/eDist;if (dFirePower > 3){dFirePower = 3;}fire(dFirePower);}/**- onHitRobot:  Back up!*/public void onHitRobot(HitRobotEvent e) {// If we're moving the other robot, reverse!if (e.isMyFault()) {reverseDirection();}}}

4、网站

机器人官网https://robocode.sourceforge.io/IDEA环境开发机器人https://my.oschina.net/kanlianhui/blog/1556868

robocode机器人案例相关推荐

  1. 初中参观机器人博物馆的作文_展馆导览机器人好不好用?小笨展馆机器人案例...

    每次科技发展都会给社会带来技术变革,例如工业革命时代的纺纱机,发电机等,极大地提高了生产效率,推动了社会的进步.二十一世纪,人工智能成为了当下技术变革的排头兵,机器人作为其载体已经被应用在各类展馆当中 ...

  2. robocode 机器人编码

    robocode 机器人编码 robocode robot code 机器人编码 battle 战斗 warning:the battle you are about to start is vrey ...

  3. 西门子PLC 发那科机器人案例 西门子PLC触摸屏以及三菱伺服应用

    西门子PLC 发那科机器人案例. 本案例采用西门子1200系列的1215C PLC和西门子人机界面跟两台发那科机器人以及视觉系统构成(发那科机器人一台六轴一四轴)伺服系统为三菱J4系列. PLC本体控 ...

  4. 西门子PLC/发那科机器人案例 本案例采用西门子1200系列的1215C PLC和西门子人机界面跟两台发那科机器人以及视觉系统构成

    西门子PLC/发那科机器人案例. 本案例采用西门子1200系列的1215C PLC和西门子人机界面跟两台发那科机器人以及视觉系统构成(发那科机器人一台六轴一四轴)伺服系统为三菱J4系列. PLC本体控 ...

  5. 智能多轮对话机器人案例剖析(附源码)-张子良-专题视频课程

    智能多轮对话机器人案例剖析(附源码)-269人已学习 课程介绍         智能多轮对话机器人案例剖析(附源码) 三个完整案例,体验式教学: 一套开源框架,所学即所用: 课程收益     掌握任务 ...

  6. Rasa 3.X 智能对话机器人案例开发硬核实战高手之路 (7大项目Expert版本)

    课程标题:Rasa 3.X 智能对话机器人案例开发硬核实战高手之路(7大项目Expert版本) 课程关键字:Rasa Application.Debugging.E-commerce.Retail.C ...

  7. robocode机器人1.0版

    问题及代码: package com.anbo.g1; import robocode.*;import java.awt.*; import java.awt.Event; import javax ...

  8. 微信机器人服务器成本,微信机器人案例汇总

    四月份分享主题:微信机器人文章汇总,项目地址:项目地址:https://github.com/pig6/wxrobot(或点击阅读原文) 第一篇.项目介绍 从项目选择库.github下载代码.如何运行 ...

  9. 微信公众号接入天行机器人案例和方法

    首先使用的是天行机器人: 1.接入基本原理: https://www.tianapi.com/apiview/47 申请完成后的结果如下 调用对应的接口的参数如下: http://api.tianap ...

  10. Science 好文:强化学习之后,机器人学习瓶颈如何突破?

    来源 | AI科技评论 编译 | 陈彩娴 编辑 | 陈大鑫 在过去的十年里,机器学习确实取得了巨大的突破,计算机视觉与语言处理方面也因此出现了许多改变世界的重要应用.但是,这股"春风&quo ...

最新文章

  1. Activity悬浮并可拖动(访悬浮歌词)
  2. evoc服务器长鸣报警显示正常,UPS电源故障灯亮,蜂鸣器长鸣报警怎么办
  3. 现在的教育:感慨之一
  4. apk解密工具_手机端操作| Auto.js一键解密/一键加密工具免费分享
  5. WCF之服务实例管理
  6. python判断txt文件是否为空_Python中的空值怎么判断
  7. 【转】我该 不该学习VULKAN
  8. 单一指责原则(Single Responsibility Principle) SRP
  9. linux yum自动挂载_Linux系统本地Yum仓库制作
  10. 看小白如何解决ajax跨域问题
  11. 20行Python代码爬取王者荣耀全皮肤
  12. 21世纪大学生之你是属于哪种看网课。
  13. 如何在Excel中制作斜线
  14. Linux之奇怪的知识---supervisor超级守护进程的意义和使用方法
  15. Python字符串的‘ ’,“ ”,''' '''
  16. 基于IPFS视频存储的在线视频网站
  17. 物联卡需要实名认证吗?物联网卡实名认证有什么用?
  18. 中文改写神器下载-中文改写神器
  19. 【TA-霜狼_may-《百人计划》】图形4.5 DoF景深基础
  20. 罗德里格斯公式 理解、推导

热门文章

  1. 【原创】2021-2001广东统计年鉴面板数据、珠三角数据、广东年鉴(可直接使用)
  2. 贝塞尔方程与贝塞尔函数学习笔记
  3. ESP32使用PCF8563时钟模块进行网络校时
  4. 非合作博弈篇——非合作博弈论问题的表示(strategic form)
  5. MySQL调用存储过程和函数
  6. python源码剖析_《Python源码剖析》很值很强大!
  7. php mysql日期转换成时间戳_php日期转时间戳,指定日期转换成时间戳【转】
  8. js 车牌号模糊处理
  9. sybase常用sql语句
  10. 游戏开发入行大师攻略