Robocode Robots project is a collection of robocode robots. This project is a collection of robots for the robocode framework. Robocode is an alphaworks project from IBM that provides an environment for creating software robots that compete against each other.
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. 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 robocodeinstalldir/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: 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.
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.
![Robocode Robocode](http://robowiki.net/w/images/a/a8/NewBattleDialog-FnlBot.png)
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.
Normalizes an angle to be near an absolute angle. The normalized angle will be in the range from 0 to 360, where 360 itself is not included. If the normalized angle is near to 0, 90, 180, 270 or 360, that angle will be returned. The method is used for defining when the angle is near one of angles listed above. Parameters: angle - the angle to normalize Returns: the normalized angle that will be in the range of 0,360 See Also:,.
normalNearAbsoluteAngle public static double normalNearAbsoluteAngle(double angle). Normalizes an angle to be near an absolute angle. The normalized angle will be in the range from 0 to 2.PI, where 2.PI itself is not included. If the normalized angle is near to 0, PI/2, PI, 3.PI/2 or 2.PI, that angle will be returned.
The method is used for defining when the angle is near one of angles listed above. Parameters: angle - the angle to normalize Returns: the normalized angle that will be in the range of 0,2.PI See Also:,. isNear public static boolean isNear(double value1, double value2). Tests if the two double values are near to each other. It is recommended to use this method instead of testing if the two doubles are equal using an this expression: value1 value2. The reason being, that this expression might never become true due to the precision of double values. Whether or not the specified doubles are near to each other is defined by the following expression: (Math.abs(value1 - value2).