当前位置:网站首页>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
边栏推荐
- An example of linear regression based on tensorflow
- Solving the problem of displaying too many unique values in ArcGIS partition statistics failed
- Tensorflow tensor introduction
- .105Location
- Process management command
- Closure type of rust (difference between FN, fnmut and fnone)
- xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
- C# 的数据流加密与解密
- Excel opens large CSV format data
- Basic usage of crawler requests
猜你喜欢
JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
Fashion classification case based on keras
Go language JSON package usage
C network related operations
An example of linear regression based on tensorflow
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
Implementation of object detection case based on SSD
Re regular expression
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
随机推荐
Thirteen documents in software engineering
QTableWidget使用讲解
.104History
Stanford machine learning course summary
powerdesigner各种字体设置;preview字体设置;sql字体设置
Docker 安装 MySQL
Notes on common basic usage of eigen Library
Gobang game based on pyGame Library
Box pointer of rust
Flash - Middleware
Cells in rust share variable pointers
解决允许在postman中写入注释请求接口方法
GDAL + ogr learning
positioner
C medium? This form of
解决报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Correct opening method of option
C#的随机数生成
Arcpy adds fields and loop assignments to vector data
Batch export ArcGIS attribute table