当前位置:网站首页>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
边栏推荐
猜你喜欢
k8s之实现redis一主多从动态扩缩容
Closure type of rust (difference between FN, fnmut and fnone)
.104History
ArcGIS license error -15 solution
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
GDAL + ogr learning
powerdesigner各种字体设置;preview字体设置;sql字体设置
QTableWidget使用讲解
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
Docker 安装 Redis
随机推荐
Realization of consumer gray scale
_ FindText error
An example of linear regression based on tensorflow
Jenkspy package installation
journal
Clion installation tutorial
Go file operation
C byte array (byte []) and string are converted to each other
powerdesigner各种字体设置;preview字体设置;sql字体设置
C#字节数组(byte[])和字符串相互转换
Go对文件操作
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Climbing watermelon video URL
Dock installation redis
Mode of interprocess communication
Visualization of residential house prices
A few lines of code teach you to crawl lol skin pictures
Process management command
Crawler for querying nicknames and avatars based on qqwebapi