The Secret of Robocode master

Source: Internet
Author: User
Tags cos range sin

This tip will give you an insight into the workings of the circle aiming. We'll start with a discussion of how basic techniques work, and then explain a simple iteration that can significantly improve accuracy. I also provide the source code, it is easy to adapt to work in your own robot.

Working principle

The pseudo code for calculating the change in X (changes in the x direction) of the robot that makes a circular motion and changing in Y (changes in the Y direction) is quite simple, assuming that you calculate in radians:

Change in x = cos (initialheading) * Radius-cos (initialheading + changeinheading) * radius
Change in y = sin (initialheading + changeinheading) * Radius-sin (initialheading) * radius

The initialheading is the direction of the enemy robot in the initial position, and the direction of the projectile during the flight is changeinheading, we assume that it moves in radius as a circular radius.

Calculate the necessary data

Figure 1 illustrates most of the data we need: R is the circumference radius of the robot's motion, the direction changes to a, and V is the instantaneous speed of the enemy robot's motion.

Figure 1. Move along the circumference

In order to accurately target the enemy, we need some specific data: the current direction of the robot, the direction of each shift, the current speed, the moment our bullets arrive. We can use this data to calculate the circle radius of the enemy's circles, and its final direction (that is, our bullets arrive at the enemy's instant enemy direction). The way in which we calculated the bullet hit position is as follows:

Change in direction of each turn: we use Headingchangeperturn = (heading2-heading1)/time to get this value, where time is two times the interval between measurements. You must also standardize the results, as shown in the following code.

Bullet time: We can meet the need by using simple times = GetTime (range/) + (20-(3*firepower)). Range is the distance between us and the enemy at launch, and firepower is the firing firepower we plan to use. It is not appropriate to assume that the target will not change to our distance when the bullet hits, but before we develop the iteration in the content later in this article, it is sufficient.

Radius: We derive this value using RADIUS = Velocity/headingchangeperturn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.