[an error occurred while processing this directive]
Back to the main JavaBots page.
JavaBot Development Guide
(a work in progress)
This guide should get you through the basics of writing the Java source
code for your JavaBot and compiling it into a .class file to be
loaded into the JavaBot Simulator. This guide assumes no previous knowledge
of the Java programming language, the JDK, or Object-Oriented Programming
(OOP). It does, however, assume some prior programming knowledge and that
you are using Win95.
Modifying and Compiling a Sample Bot
The \JavaBots\samples\ directory contains a few sample JavaBots
to help you in your quest to develop a mean piece of AI. If you've loaded
these bots into the simulator, you may have noticed that the Aimer
bot searches for and chases opponents in much the same manner as the ColliderIII
and the Runner. This is because all three are built around the same
"choose and hunt" design. Additionally, you might have been perceptive
enough to see that the Aimer bot does its scan sweep much slower
than the ColliderIII bot. As you'll see, the speed of the sweep
is determined by a simple constant embedded in the code.
First, we'll try to increase the speed of the Aimer's sweep.
Let's take a look at line 67 of the Aimer.java file located
in \JavaBots\samples\. Using any vanilla text editor (DOS's edit.com
will do) open the Aimer.java file and go to line 67:
if (infolist.size() == 1 || notarget) {
/* stop driving */
success = super.Drive(0, 0, 0);
/* increase the direction of scan by PI/20 */
line 67 -> dir += java.lang.Math.PI/20;
}
Here, the local variable dir is set to its previous value
plus java.lang.Math.PI/20, this new dir value
is used to call Scan() the next time through the while loop.
In other words, dir is incremented by 1/20 of PI each time
through the loop. The term, java.lang.Math.PI is a floating
point constant stored as a class variable inside the class Math.
This class is part of the standard Java package java.lang.
Packages can be likened to a library of pre-existing code similar to C
libraries, for example, Server, Bot, and Visualizer
are all packages written for JavaBots. We'll learn more about classes
and class variables later.
Since 1/20 of PI is a relatively small amount to be sweeping each turn,
we should increase this amount to achieve a more speedy sweep rate. Let's
set edit line 67 so that it increments the scan direction by 1/8 PI:
dir += java.lang.Math.PI/8;
We can now recompile the Aimer.java file and see how it has changed
the Aimer bot. Change directory to \JavaBots\ and run the
setpath.bat file if you have not already done so. Enter the \JavaBots\samples\
directory and type:
javac Aimer.java
This will run the javac Java compiler to compile Aimer.java.
If there are no errors, than you are ready to run the simulator and test
out the new Aimer bot. Change directory to \JavaBots\ and
run launchsim.bat.
Select Load Bot from the File menu and select the Aimer.class
file inside the samples\ directory. Now select Start Sim
from the File menu and you should see the Aimer class sweeping
its scanner around the arena at a faster pace. Add a few bots from the
Extras menu and see how well it does.
Back to the main JavaBots page.