Robocode常见问题

  版权信息:
● 本博客使用CC 3.0协议,转载请保留该信息。
● 原文作者: 戴晓天 @ 云飞机器人实验室
● 原文地址: Robocode常见问题

本文由 云飞机器人实验室 翻译。

What is the difference between frames and ticks?
一帧(Frame)与单位时间(Tick)有什么区别?
A tick refers to one unit, which is also called a Turn in Robocode. During one turn, you may perform one action as a Robot, or multiple (independent) actions as an AdvancedRobot. A frame is a unit of drawing to the Robocode client interface. If you are processing turns slowly, you will get one frame per tick / turn. However, if you up the turns per second beyond your computer’s ability to render the frames, you will miss some frames of animation. This won’t affect the robots’ behavior, unless you foolishly added code in your onPaint(Graphics2D) method that alters your bots behavior. In that case, your bot will behave differently depending on whether or not the Paint button has been enabled, and if the framerate can keep up with the turnrate.
一个单位时间指Robocode中的一个回合。在这个回合中,Robot只能执行一个动作,AdvancedRobot只能执行一组独立动作。而一帧是一连串界面的绘图动作。如果你将每回合的时间设得很长,你会得到一帧/回合。然而,如果你每回合的速度过快,超过了计算机的绘制速度,那么你可能会丢帧。但这只是绘制上的损失,不会影响你机器人的行为(除非你傻到在OnPaint中编写代码)。

Can I fire bullets with power higher than 3.0 or lower than 1.0?
我可以发射火力在1.0与3.0之外的子弹么?
No and yes. You can’t fire bullets with power greater than 3.0, but you can fire bullets with power as low as 0.1. If you call a firing function (i.e. setFire()) with a value greater than 3.0, Robocode will adjust it to 3.0, and if you call it with a power lower than 0.1 (except 0.0 which will not fire) it will adjust it to 0.1. Additionally, you can fire bullets with power less than 0.1 under one condition: when your robot has less than 0.1 energy left, in which case a bullet is fired with however much energy your robot had left.
是也不是,你不可以发射大于3.0的子弹,但是可以发射小到0.1能量的子弹。如果调用setFire()时大于3.0,会被矫正到3.0;同样的,小于0.1会被矫正到0.1。只有一种情况能发射<0.1的子弹,那就是你的能量不足0.1,这时子弹能量是你当前的最大生命。

How fast does a bullet travel?
子弹的速度有多快?
A bullet travels at a speed between 11.0 and 19.7 depending on the power. The more powerful the bullet, the slower. The formula to calculate it is velocity = 20 – (3 * power).
子弹的速度与能量相关,介于11.0-19.7之间,能量越大,速度越慢。计算公式是:速度 = 20 – (3 * 能量).

Does the robot velocity get added to the bullet velocity on firing?
发射子弹会增加机器人的移动速度么?(天哪,这是谁想的问题)
No, bullet velocity is not affected by robot velocity. It’s kind of like the speed-of-light thing. =)
不会的,子弹的速度不会影响机器人的速度。

Which is the range of a bullet?
子弹的射程有多远?
A bullet has no range. It keeps going until it hits a robot or a wall.
子弹的射程无穷大,直到撞击到墙或机器人。

I want to fire a bullet every turn, but I can’t. Why?
我可以在每个回合(turn,also known as tick)发射子弹么?为什么?
Every time you fire, the gun generates some heat. You must wait till it is cool again to fire. If you give a fire order when your gun is hot, it will do nothing. The heat generated by a shot is 1 + (firepower / 5). The gun cools down at a default rate of 0.1 per turn (note that you can change this parameter when you run the battle, but nobody usually does). It means you can fire a 3.0 power bullet every 16 ticks.
不可以,每当你发射子弹时,会产生炮管热量,当你在炮管没有冷却之前,发射子弹的命令不会响应。热量产生的公式是:1 + (子弹能量 / 5)。炮管热量以0.1/回合的速度耗散,这意味着每16个回合才能发射一颗3.0能量的子弹。

How much damage does a bullet do? How do I gain or lose energy?
子弹会导致多少伤害?我何时会增加或损失能量?
You lose energy every time you hit a wall, you are hit by an enemy bullet, ram an enemy, or you fire your gun. The amount of energy you lose by being hit is 4 * bullet power + 2 * max(bullet power – 1 , 0). So the maximum amount is 16.0. When you fire, you spend a quantity of energy equal to the power of the bullet fired. When one of your bullets hits an enemy, you collect back 3 * bullet power energy. When you hit an enemy bot, each bot takes 0.6 damage. If an AdvancedRobot (but not a Robot or JuniorRobot) hits a wall, it will take max(abs(velocity) * 0.5 – 1, 0) damage.
每当你撞墙、被敌人击中、与敌人碰撞或者你发射子弹时,你都会损失能量。被击中时的能量损失的公式是:4 * 子弹能量 + 2 * max(子弹能量 – 1 , 0)。所以最大损失的能量是16。当你发射子弹时,你损失的能量与子弹能量相当。当你击中敌人时,你可以得到3*子弹能量的反馈。当你与别人撞击时,双方都会损失0.6的能量。如果一个AdvanceRobot(Robot、JuniorRobot不会)撞墙了,会损失max(abs(速度) * 0.5 – 1, 0) 的能量。

Some times I get disabled. What happens?
有时我无法动作了(出现标志disabled),发生了什么事?
You can’t kill yourself, so when your energy drops to zero because you hit a wall or you fire, your bot gets disabled. It will not be able to move nor fire. If you are lucky enough and one of your bullets in the air hits an enemy, you will get some energy back and recover from disabled status.
你因撞击或发射子弹而能量耗尽。此时你不能移动、开火。如果你足够幸运,正好有一颗已经发射的子弹打中敌人,那你可以从该状态中恢复。

I get disabled, but I my energy > 0. Why?
有时我能量>0,却依然无法动作,为什么?
There are a few possible causes. You may have called a getXXX() function – such as getVelocity() – too many times a turn. The limit is 10000 getXXX() function calls per turn. To avoid disabling in such situations, either store returned values in variables for future use or use a RobotStatus object obtained from StatusEvent. Another case in which you can get disabled is throwing an exception, which may disable your bot, even if you catch the exception. Also, if your bot gets stuck in an infinite (or very long) loop and skips many turns, it may also get disabled.
你过快的调用了getXXX()或者你出现了异常,或者你进入了死循环(也可能你的计算时间过长)。

How fast do I move?
我能移动的最快速度是多少?
You can move at a maximum speed of 8.0 units/tick. You can modify (down) your maximum velocity by using setMaxVelocity(…). Note that your bot will always accelerate to reach its maximum velocity.
最快速度是8.0单位/回合,你可以通过setMaxVelocity修改该值,但要注意的是,你永远会加速到最快速度。

How fast do I accelerate?
我的加速度有多快?
You accelerate at 1 unit/tick, and you decelerate at 2 units/tick. For example, if you are moving at an speed of 8.0 and reverse your direction your velocities will be [6.0, 4.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0].
加速度为1个单位/回合;减速度为2个单位/回合。如果你以8.0的速度反向运动,你的速度将会是[6.0, 4.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]。

How fast do I turn?
我转弯的速度有多快?
The faster you go, the slower you turn. The formula to calculate it in degrees is 10 – 0.75 * abs(velocity).
你速度越快转弯就越慢。计算公式是:10 – 0.75 * abs(velocity).

What is the size of a bot?
机器人的大小有多大?
The size of a bot is 36×36. Note, this is slightly smaller than the image of the bot. It is modeled as a non rotating square, so it’s always the same regardless of its heading.
机器人的物理模型大小是36*36,实际图片比它略大。该模型是正方形,不分方向,不会因为当前朝向而改变。

It seems that Robocode doesn’t follow standard physics. If my velocity is 0 and I accelerate (acceleration = 1) my final position is 1, but it should be 0.5. What happened?
Robocode好像并不遵循物理规律,当我以初速度为0加速度为1运动时,我的位置应该是0.5,但结果却是1,这是怎么了?
Time in Robocode, rather than being continuous, is in discrete “ticks”. First acceleration is calculated, then velocity, and then position. So if you are stopped at a position 0 and you accelerate 1, your velocity next turn will be 1 and your position also 1.
Robocode中的时间是离散的,以回合(tick)计数。加速度首先被计算,之后是速度和距离。所以如果你以初速度为0加速,一个回合之后你的速度和位置都会是1。

How can I detect when an enemy has fired?
我如何检测到对方开火了?
There is no direct way to detect when an enemy fired, but you can deduce it by monitoring the enemy energy drop. A drop between 0.1 and 3 usually means that it fired a bullet (there can be other reasons, such as a low energy bullet hit or a wall hit). Wall hits are (more or less) detectable as well. A deceleration > 2 means the bot hit a wall (or another bot). A deceleration <= 2 may be simple a bot hitting the brakes, or hitting a wall at velocity = 2, but since hitting a wall at that speed won’t cause any damage, you can ignore that. AdvancedRobots take abs(velocity) / 2 – 1 (Never < 0) damage when hitting a wall, so by detecting (significant) wall-hits and adjusting the enemy drop accordingly, wall hits can be filtered out most of the time. This method fails when the enemy hits another robot.
没有直接的方法直到敌人开火了,但是可以间接的通过监视对方的能量得知。介于0.1-3.0之间的能量降落通常被认为是发射了子弹。当然也有可能是中了能量很小的子弹或是发生了碰撞。实际上碰撞是可以被检测的,当机器人减速度大于2时,就认为发生了碰墙;减速度小于2,可能是它刹车了,或是正好以2的速度撞墙(不过此时几乎没有伤害)。AdvancedRobots撞墙时会损失abs(velocity) / 2 – 1的能量,所以通过检测碰墙,就可以更好的确定敌人开火了。当然,对于机器人之间的碰撞,这种方法无能为力。

How can I detect the position and heading of an enemy bullet?
如何得知对方子弹的位置与朝向?
You can’t. There is no way to know it, directly or indirectly. But of course, you can always guess
不可以。无论是直接的还是间接的。不过你可以猜测。

How fast can I turn my gun?
炮管最快的转速是多少?
The gun turns at 20 degrees per tick.
炮管最快20度/回合。

How fast can I turn my radar?
雷达最快的转速是多少?
It turns 45 degrees per tick.
最快45度/回合。

Can I know the heading of the enemy gun/radar?
我可以知道敌人炮管和雷达的朝向么?
No.
不可以。

Can I specify the initial position of my bot?
我可以选择机器人的初始位置么?
No. The bots are randomly placed in the field at the beginning of each round.
不可以。机器人的初始位置是随机的。

%d bloggers like this: