当前位置:网站首页>Robocode tutorial 8 - advanced robot
Robocode tutorial 8 - advanced robot
2022-04-23 18:08:00 【dawnsun001】
In this tutorial , We are going to learn AdvancedRobot and Robot The difference between , Learn to AdvancedRobot Is the premise for us to write high IQ robots .
Robots that can run efficiently are inherited AdvancedRobot, because Robot It's thread blocking ,AdvancedRobot It is thread non blocking . The difference between them is obvious , analysis while(true){} It's easier to understand thread blocking and non blocking with the code inside .
public void run() {
while(true) {
ahead(100);
turnGunRight(90);
}
}
stay Robocode Each robot in the is an independent thread , We know that whether it's extends Thread still implements Runnable We must achieve public void run() Method , This is essential . In order to ensure that the robot continuously runs its own program , So... Is used in the thread while(true) loop . In each cycle ,ahead(100) machine
The robot moves forward 100 pixel , next turnGunRight(90) Right turn gun 90 degree , You will find that the robot executes according to strict sentence by sentence code , Only after the execution ahead(100) after , Will execute turnGunRight(90), Then cycle . Our robots will walk a square line on the battlefield .
Let's analyze another code , This code is inherited from AdvancedRobot, You will find that each method is preceded by set, This is to facilitate and Robot Make a difference .
public void run() {
while(true) {
setAhead(100);
setTurnGunRight(90);
execute();
}
}
Almost the same code as above , Just one more sentence execute(); And this execute() Is the key to non blocking code , This involves java Multithreaded programming , We won't talk much about , We can think of it this way execute(), It's equivalent to a sign , The program records the contents of all the previous code to be executed , But not implemented. , Only received execute() After the command , Previously recorded commands will run alternately , For the above code , It's a small step forward , Turn a small angle , Take a small step forward , Turn a small angle , So circular . So on the battlefield, our robot will walk a circular video .

Okay , About Robocode That's all the basic content of , With this knowledge, I can write some good robots . But to write smarter actual combat robots , We still need a lot of algorithms , Later, we will introduce these algorithms , Including random motion , Pseudo random motion , Linear prediction aiming , Circular prediction aiming , Statistical aiming , Virtual wave aiming and so on .
版权声明
本文为[dawnsun001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230544289368.html
边栏推荐
- Queue solving Joseph problem
- 读取excel,int 数字时间转时间
- Box pointer of rust
- Re regular expression
- The difference between deep copy and shallow copy
- Rust: the output information of println is displayed during the unit test
- JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
- QTableWidget使用讲解
- MySQL 中的字符串函数
- 消费者灰度实现思路
猜你喜欢

解决允许在postman中写入注释请求接口方法

Docker 安装 MySQL

Map basemap Library
Logic regression principle and code implementation

Fashion classification case based on keras

Classification of cifar100 data set based on convolutional neural network

Solving the problem of displaying too many unique values in ArcGIS partition statistics failed

.104History
![[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)](/img/91/3272d5ad04cd1d8476c739546f4356.png)
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)

.105Location
随机推荐
Robocode tutorial 5 - enemy class
k8s之实现redis一主多从动态扩缩容
xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
Map basemap Library
Rust: how to implement a thread pool?
Build openstack platform
How to install jsonpath package
Go language JSON package usage
I / O multiplexing and its related details
C network related operations
Box pointer of rust
undefined reference to `Nabo::NearestNeighbourSearch
Process management command
Implementation of object detection case based on SSD
Excel opens large CSV format data
idea中安装YapiUpload 插件将api接口上传到yapi文档上
Go语言JSON包使用
How to ensure the security of futures accounts online?
C#字节数组(byte[])和字符串相互转换
Operators in C language