Robocode study notes (1)

zhaozj2021-02-16  78

I saw a introduction to Robocode, excited. Learn Robocode today, hehe.

First access the IBM AlphaWorks Robocode page, on this page, find the latest executable of the Robocode system. This distribution package is a self-contained installation file. After downloading the packet, you can use the following command line to install this package on the system (of course, we assume that Java VM is already installed on your machine (JDK 1.3 .x) The above version).

Java-Jar Robocode-setup.jar

During the installation process, Robocode will ask you to compile the robot using this external Java VM. You can also choose the JIKES compiler that is provided as part of the Robocode distribution package.

When Robocode is activated, two associated GUI windows will be seen, the two windows constitute the Ide of Robocode:

Battlefield Robot Editor

The battlefield is a battle between the robots until the venue of the victory. The main simulation engine is placed thereto, and allows you to create battle, save battle, and open new or existing battles. Through the control in the interface area, you can suspend or continue fighting, terminate the battle, eliminate any robot individual or get statistical data for any robot. In addition, Robot Editor can be activated on this screen.

Robot Editor is a custom text editor that can be used to edit the Java source file generated by generating robots. The Java compiler (for compiling robot code) and custom Robot packer are integrated in its menu. All robots created by Robot Editor and successfully compiled are in the battlefield on a deployment. (Individual thinks the text editor it provides is not very good, and finally use JB to edit, as long as the Robocode.jar after the Requird Libraries is added to the decompression, it is ok.

Each robot in Robocode is composed of one or more Java classes. These classes can be compressed into a JAR package. To this end, the latest version of Robocode provides "Robot packager" that can be activated in the battlefield GUI window.

The Robocode robot is a graphical tank. Please note that the robot has a rotatable gun, and the radar on the gun can also be rotated. Vehicle, guns and radar can rotate separately, that is, at any time, robot tanks, guns, and radar can be turned to different directions. By default, these directions are consistent, all point to the direction of the tank movement.

Attachment: The command set of the robot command Robocode robot is included in the Robocode API JavaDoc. These commands are public methods for the Robocode.Robot class.

(1) Mobile robots, guns and radars

Basic commands for mobile robots and their equipment:

Turnright (double deterree) and turns (double deterree) turn the robot to a specified angle. Ahead (double distance) and back (double distance) make the robot to move the specified pixel point distance; the two methods are completed when the robot comes from the wall or another robot. Turngunright (Double Degree) and Turngunleft (Double Degree) can be rotated in the direction of the tank. Turnradarright (Double Degree) and TurnRadarleft (Double Degree) rotate the radar above the gun, the direction of rotation is also independent of the direction of the gun (and the direction of the tank). These commands are also given to the program after executing. In addition, when turning the tank, the direction of the gun (and radar) will be moved by calling the following methods.

SetadjustGunForrobotturn (Boolean Flag): If Flag is set to True, then the tank rotates, the gun keeps the original direction. SetadjustRadarForrobotturn (Boolean Flag): If Flag is set to true, the radar will maintain the original direction when the tank is turned to TRUE. SetadjustRadarforgunturn (Boolean Flag): If Flag is set to true, the radar will maintain the original direction when the gun is turned. Moreover, the action it performs is like called SetAdjustRadarForrobotturn (TRUE).

(2) Get information about robotics

Getx () and getY () can capture the current coordinates of the robot. GetHeading (), getGunHeading () and getRadarheading () can draw the current direction of tanks, guns or radars, which is expressed in an angle. GetBattlefieldWidth () and getBattlefieldHeight () can get the current round battlefield size.

(3) Shooting command

Once the mobile robots and related weapons and equipment are mastered, we should consider shooting and controlling the task. Each robot has a default "energy level" at the beginning. When its energy level is reduced to zero, we think that the robot has been eliminated. When shooting, the robot can use up to three energy units. The more energy supplied to the shell, the greater the damage caused by the target robot. Fire (Double Power) and Firebullt (Double Power) are used to transmit the designated energy (firepower). The called FireBullet () version returns a reference to the Robocode.Bullet object, which can be used for advanced robots. (That is, when you are sure you can hit the other party, the bigger the fire, the better, ^ _ ^)

(4) event

Whenever the robot is moving or turned, the radar is always active, and if the radar detects that there is a robot in its range, an event will trigger an event. As a robot creator, we have the right to choose various types of events that may occur in battle. The basic ROBOT class includes all of these events default procedures. However, we can overwrite any of the default processing programs that "nothing, and" then implement your own custom behavior. Here are some of the more common events:

转载请注明原文地址:https://www.9cbs.com/read-14256.html

New Post(0)