CS211
Programming Assignment #1
Robo Battle
In
this project you will learn to use Netbeans to debug, compile and run
Java projects. In addition this will serve as a basic review of some
Java fundamentals. To do this we will be writing robot battle code in
Netbeans using the RoboCode
project from sourceforge.
Instructions:
Using the RoboCode API you will create a new Robot "ScaredyBot".
ScardyBot runs away whenever it sees another bot. While running away it
shoots behind itself in an attempt to hit the other bot. A correct
implementation of ScaredyBot must be done by all students in the class.
Additionally, you can get extra credit for writing a second
bot to enter into our class battle tournament. With the
second bot you must provide a short (2-3 sentences) description of the
bot's logic.
Getting
Started
- Download
and install Netbeans. (Instructions)
- Download the
RoboCode code. http://robocode.sourceforge.net/download.
Choose the "robocode" Release 1.4.4 package (or whatever the latest release is). You do not need the source
code.
- Double-click on the
robocode-setup-1.4.4.jar (it is an executable Jar). If it doesn't run
automatically ensure you have Java 1.5 installed on your machine.
- Choose
an install location. For this example I will assume install location =
/Users/dfleck/robocode. On windows this could be c:\robocode
- To
test your robocode setup, double-click on the file to run robocode. You
should see the battle
- Windows:
robocode.bat
- Mac or Linux: robocode.sh
- Note:
You cannot just click on the robocode.sh icon. You need to start a
shell window, and then from the command line change directory into the
robocode directory, then run "./robocode.sh".
- Choose
Options->Sound Options to turn on the sound (it's much better
with sound)
- Start a test battle
- Choose
Battle->New
- Highlight 3 or 4 robots
- Click
Add to add them into the battle
- Change the number
of rounds to 3
- Click "Start Battle"
- At
this point RoboCode is setup... but not for use in Netbeans!
- Setting
up Netbeans for use with RoboCode
- File
-> New Project. Category=General, Projects=Java Application
- Give
your package a name and location
- Add in the
RoboCode library
- In Netbeans right-click on your project.
- Choose "Properties"
- Choose "Libraries"
- Choose
"Add JAR/Folder"
- Choose all the JARs in robocode_install_dir/libs
- Press
"ok"
- Setup the Runtime
- Right-click
on your project and select "properties"
- Main-class:
robocode.Robocode
- Arguments: leave this blank
- Working
Directory: install directory (/Users/dfleck/robocode or c:\robocode)
- VM
Options: -Xmx512M -Dsun.io.useCanonCaches=false
- NOTE:
Depending on your computer's memory, using 512M may be to high. If you
cannot run robocode from Netbeans with this setting, remove the
"-Xmx512M" from the run properties (this window).
- Select
"ok"
- Configuring
Robocode to see your bot.
- In Netbeans
choose Run->Run Project (this should start Robocode)
- Choose
Options->Preferences
- Choose Development
Options
- Click "Browse" and choose the classes
directory under your Netbeans build directory
- Choose
Finish
- Creating your first Robot
- Select
File->New
- Choose category: "Java Classes"
- Choose
File Types: Java Class
- Make up a classname for your
Robot (mine is DansRobot)
- Click Finish
- Create
your new Robot. A simple bot could be like this: MyFirstRobot.java make sure to change the package name and class name!!
- Testing your robot
- From Netbeans choose "Run"
- In Robocode create a new battle
- In the Robot list your Robot should now show up.
- Select your robot and start the battle!
- Debugging
- We'll
get into this later, but if you want to run your bot in the debugger
you can. Just remember to hit "Pause/Debug" in the Robocode window so
all the other bots are paused. Then, hit "next turn" to advance the
Robocode turns as you require.
Next steps
- From here you should view some of the example bots in the robot editor (in Robocode).
- You should also look at the Javadocs for Robocode (in your Robocode install directory)
- You may also want to view the Robocode site documentation at http://robocode.sourceforge.net/help/
- You
may view other robots to get ideas, but you MUST code your own Robot!!
Copying a sample robot is not acceptable. You must implement a
different Robot algorithm for the extra credit.
Some Hints
- You will need to extend the Robot class.
- You will need to implement the onScannedRobot method. This method is called when you "see" another robot.
- The
"run" method is called at the beginning of the battle. You probably
want to spin your radar constantly at the end of the run method
turnRadarLeft(360). See code in other bots.