This material was originally prepared as a section of the article
“First Steps in Robocode,” but I decided to take it out because it significantly increased the size of the already large initial article and is not basic and necessary for the implementation of the first step. If you are immediately interested in the second step or gradually have grown to it, then I ask under the cat.
Units
First, I will describe the units of measurement.
- Time is measured in ticks, which are equal to one move. A limited amount of real time is given per turn, which depends on the processor power and is calculated when you first start the game or at the request of the user. If during the specified time the robot does not issue a command to the next move, this move will be “skipped” (But if you previously issued the command “Drive 100 pixels forward”, then your robot will move until it passes the specified distance).
- The distance is measured in certain arbitrary units. However, in the case where the dimensions of the battlefield are completely on the screen, these units are equal to one pixel. If you write “pixel” to (!!!) robotic workers, for your own good they will tell you the same thing, but they will correctly understand you, so I will use the term pixel later. Distance values are floating point numbers.
- Speed is measured in pixels per turn.
- In general, the acceleration formula is a = v / (t ^ 2), but since 1 move in the game is an atomic time unit, acceleration is somewhat simplified and is also measured in pixels per turn (I’ll tell you more later).
- Angles are measured in radians. The same API allows you to use degrees, and I strongly recommend that you choose something for yourself and use this value everywhere, since all trigonometry works with radians, then I recommend them to choose.
- Energy, bullet power, damage is measured in some arbitrary units. I will call it “energy units”.
- The temperature of the gun is measured in undescribed units and I will use abstract degrees (hereafter simply “degrees”).
The origin of coordinates, traditionally, is in the lower left corner, but the angles are unusual. 0 radian indicates north and further clockwise: Pi / 2 - east, Pi - south, (Pi * 3) / 2 - west, 2 * Pi - north.

Tactical and technical characteristics of the tank
The robot consists of three parts - the body, the tower and the radar, the rotation of which is dependent on each other (however, you can set the flag of automatic compassation). The performance characteristics of the robot are as follows:
- The initial energy of 100 units.
- Power shot from 0.1 to 3 units of energy.
- The speed of the bullet depends on the power and is calculated by the formula 20 - (3 * <power shot>)
- Maximum speed of 8 pixels / stroke in both directions.
- Maximum acceleration 1 pixel / move.
- Maximum braking 2 pixels / stroke.
- The maximum speed of body rotation depends on the speed of the tank and is calculated by the formula (10 - 0.75 * <speed module>) degrees / stroke.
- The maximum speed of rotation of the tower is 20 degrees / stroke.
- The maximum speed of rotation of the radar is 45 degrees per turn.
- Initially, the gun has some heat (at the moment it is equal to three degrees, but in the implementation it is better to take heating instead of this constant on the first turn), which gradually decreases with the intensity adjusted at the moment of the battle creation (the default value used at the moment in official competition, equal to 0.1 degrees per turn). Also, when fired, the gun heats up by the following value: 1 + <shot power> / 5. You can only fire when the gun is cold (heat is 0).
- The radius of the radar arch is 1200 pixels (a tank can only see those robots that are in the radar arch).
In TTX it is necessary to note 3 tricks:
- When passing through zero, a special rule applies. First, the tank slows down the necessary part of the turn, and then the remaining part accelerates. Thus, if the tank's speed is equal to 0.8 and he gave the command to move backwards, then the resulting speed will be -0.6 (or 0.6 in the opposite direction), since time for braking is 0.8 / 2 = 0.4 stroke, the remaining time for acceleration is (1 - 0.4) = 0.6, speed is 1 * 0.6 = 0.6.
- At zero speed, and provided that all three components rotate in the same direction, the radar can be rotated 45 + 20 + 10 = 75 degrees. If the radar turns in the opposite direction from the hull and tower, it will turn only 45 - 20 - 10 = 15 degrees per turn.
- Automatic compensation for the rotation of tank parts, does not affect the maximum angles of rotation. For example, if a tank has a flag for automatic compensation of turns of all parts, the radar has a direction of 90 degrees and the command was given to turn the body to the right by 10 degrees, then the direction of the radar will remain equal to 90 degrees. If, in addition to turning the body, the command was also given to rotate the radar to the left by 45 degrees, then the direction of the radar will be equal to 90 - (45 - 10) = 65 degrees.
Collisions
The game has the following possible collisions:
- Robot with a robot. In the game model, robots are represented by non-rotating (independent of the direction of movement) rectangles (currently squares). A collision occurs at their intersection and each robot takes damage in the amount of 0.6 energy units. It is also written on (!!!) roboviks: “If the robot moves in the opposite direction, it will not be stopped), and I, frankly, I do not know what it means “in the opposite direction of the collision” and, since it is by and large not important, I leave it to the most curious readers in the source code of the game. The robot that moved in the “direction of collision” is also 1.2 points.
- Robot with a wall. Walls are represented by segments and a collision occurs at the intersection of a segment of a wall with the bounding box of the robot. In this case, the robot receives damage in the amount of <speed module> * 0.5 - 1; (But not less than zero). I will describe the exception in this rule later.
- Robot with a bullet. Bullets are represented by segments between the positions of the bullet in the current and previous turn. Collisions occur at the intersection of the bounding rectangle and the segment, while the victim receives damage in the amount of 4 * <bullet power>, if the bullet capacity is> 1, then plus 2 * (power - 1), and the attacker is given a bonus energy of 3 * < bullet power> and the same points.
- Bullet with bullet. The collision occurs at the intersection of segments of bullets and no one loses or receives anything.
')
Computing loop (Robocode processing loop)
The computational cycle in the game is as follows:
- Redraw the game view.
- All robots execute code until the command is returned in its own threads, which, then, are suspended.
- Time is updated (time = time + 1)
- All bullets are moved and collisions are calculated. This includes shots of new bullets.
- All robots move in the following order: tower, radar, body, acceleration, speed, position.
- All robots perform a scan.
- Resumes the execution of robot threads.
- There is an event handling in robots streams.
Here it is worth paying attention to one common mistake - a bullet is fired before the gun turns (see steps 4 and 5). Thus, you must turn the gun not by the time of the shot, but for the tick before.
On this (including the article “First steps in Robocode”) the basic knowledge of Robocode ends and you, in principle, are ready to start programming your first robot. You can continue to read at
roboviki , or you can contact me in a personal question, or in the comments to show interest in continuing the series of articles on Robocode