当前位置:网站首页>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一主多从动态扩缩容
- Romance in C language
- Array rotation
- Box pointer of rust
- Flash - Middleware
- Notes on common basic usage of eigen Library
- Closure type of rust (difference between FN, fnmut and fnone)
- Serialization scheme of serde - trust
- Nat commun | current progress and open challenges of applied deep learning in Bioscience
- [UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
猜你喜欢
C network related operations
Dock installation redis
C# 的数据流加密与解密
How to install jsonpath package
QTableWidget使用讲解
Go language JSON package usage
MySQL auto start settings start with systemctl start mysqld
YOLOv4剪枝【附代码】
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
From source code to executable file
随机推荐
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
Robocode tutorial 5 - enemy class
Gst-launch-1.0 usage notes
PowerDesigner various font settings; Preview font setting; SQL font settings
MATLAB小技巧(6)七种滤波方法比较
Using files to save data (C language)
Pyppeter crawler
The difference between deep copy and shallow copy
Cells in rust share variable pointers
proxy server
Basic usage of crawler requests
Clion installation tutorial
Rust: a simple example of TCP server and client
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Closure type of rust (difference between FN, fnmut and fnone)
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
Re expression régulière
Auto. JS custom dialog box
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
Scikit learn sklearn 0.18 official document Chinese version