Use vector to implement enemy list in Robocode

Source: Internet
Author: User
Tags relative

Objective

Robocode in the melee model, how to better grasp the situation of multiple opponents, so as to adopt a better strategy, every player is an urgent need to solve the problem. Most world-class robots use vectors (vector) arrays to hold the information of multiple opponents.

and the role of vector is more than this, the last world champion Yngwie also use vector to preserve the bullet hit information, to provide a basis for better decision-making. Of course this is beyond our topic today, interested friends can look at the enemy class and strategy class in Yngwie.

Well, let's start today's vector tour, and if you're not particularly familiar with the vector in Java, I've finally introduced some knowledge about vectors.

Get a line for our enemy.

Friends familiar with Java know that vectors are used to hold collections of objects. Today we use him to save some information about our enemies, and it's not an easy job to grab the guys that are running around and get into our collection. Kong: "All things are class". So, let's first declare a class: the track class. Take the attributes of the enemy we know as an attribute in this class: name, absolute angle, relative angle, distance, energy, rate of enemy tank relative to the direction of your head, and direction of enemy tank. These are all obtained through the Scannedrobotevent object, the specific API function please refer to the Robocode API help. The code is as follows:

/**
  * Track类,保存目标的信息
  */
package mytest;
import robocode.*;
public class Track
{
     public String Name; //敌人坦克的名称
     //敌人的绝对角度,通过计算得出
    public double Heading;
     //敌人坦克相对于你车头方向的相对角度
    public double Bearing;
     public double Distance; //敌人坦克的距离
     public double Energy; //能量
     public double Velocity; //速率
     public double FaceHeading; //敌人坦克面向的方向
     public double trackX,trackY; //敌人坦克的坐标
    //下一个标准时间中敌人坦克所在的位置
   public double nextTrackX,nextTrackY;
     public void update(ScannedRobotEvent e)
     {
        Name=e.getName(); //敌人坦克的名称
        Bearing=e.getBearing(); //敌人坦克相对于你车头方向的 相对角度
        Distance=e.getDistance(); //敌人坦克的距离
        Energy=e.getEnergy(); //能量
        Velocity=e.getVelocity(); //速率
        FaceHeading=e.getHeading(); //敌人坦克面向的方向
     }
}

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.