Anatomy - to create your own intelligent robot

zhaozj2021-02-16  61

Anatomy - to create your own intelligent robot

Author: Li Tianyi Robocode robocode@etang.com want to introduce to you the idea a long time, has no time to, ah, such a good thing, how can we miss it.? This series of articles are all provided by: Robocode China Union () provides comprehensive technical support. Robocode anatomical map

Robocode Anatomy Figure 1 Each robot consists of three active components - can be forward / retreat, left and right. Tower (GUN) - mounted on the body, can rotate around, launch bullets. Radar (Radar) ) - Installing above the turret, can be rotated left and right, triggering events when other robots are found. Let's take a clearer image in combination with the robot's body, turret, radar rotation and related API functions.

Robocode Anatomy Figure 2 My first robot is ok, understanding so many content, but when it is moving. From now on we will start from the most basic Java program to create our own intelligent robot step by step. One step by step to master the essence of Robocode. Since the lead is just a primer, the Java terminology mentioned is not all described. You can find the relevant information to see if you come back.

package wind; import robocode *;. public class MyFirstRobot extends Robot {public void run () {while (true) {ahead (100); turnGunRight (360); back (100); turnGunRight (360);}} public void onScannedRobot (ScannedRobotevent E) {Fire (2);}}

Robocode above is the most basic code, package wind; import robocode *;. Public class MyFirstRobot extends Robot {public void run () {}} import robocode *;. Java tells you to introduce all class public class under robocode MyFirstRobot Extends Robot tells Java I want the machine human beings that inherit the Robot object, the robot name is myFirstPUBLIC VOID RUN ()} Robocode public interface function, to activate the robot thread first we introduce the Run () method

While (True) {Ahead (100); Turngunright (360); Back (100); Turngunright (360);

While (True) {} When the condition is established, the event within {} is handled. This loop allows our machine to be processed / back, rotating, fire, etc. Ahead (100), call AHEAD (100) to call forward, let the robot advance 100 The distance Turngunright (360) Rotate 360 ​​degree back (100) Retriever 10 When your robot scans other robots, trigger OnsacnNedRobot event, add a little way in this event, you can process it. Fire (1) is a bullet that transmits a energy of 1. Public void onscannedrobot (ScannedRobotevent E) {Fire (1);

Ok, in the development tool, you can put it in the battlefield to practice. Original source: http://www.robochina.org/

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

New Post(0)