📜 ⬆️ ⬇️

Physics Robocode

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.

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.
image

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:

In TTX it is necessary to note 3 tricks:
  1. 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.
  2. 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.
  3. 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:

')

Computing loop (Robocode processing loop)


The computational cycle in the game is as follows:
  1. Redraw the game view.
  2. All robots execute code until the command is returned in its own threads, which, then, are suspended.
  3. Time is updated (time = time + 1)
  4. All bullets are moved and collisions are calculated. This includes shots of new bullets.
  5. All robots move in the following order: tower, radar, body, acceleration, speed, position.
  6. All robots perform a scan.
  7. Resumes the execution of robot threads.
  8. 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

Source: https://habr.com/ru/post/147956/


All Articles