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. 

RoboCode Logo

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

  1. Download and install Netbeans. (Instructions)
  2. 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.
  3. 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.
    1. Choose an install location. For this example I will assume install location = /Users/dfleck/robocode. On windows this could be c:\robocode
  4. To test your robocode setup, double-click on the file to run robocode. You should see the battle
    1. Windows: robocode.bat
    2. Mac or Linux: robocode.sh
      1. 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".
    3. Choose Options->Sound Options to turn on the sound (it's much better with sound)
    4. Start a test battle
      1. Choose Battle->New
      2. Highlight 3 or 4 robots 
      3. Click Add to add them into the battle
      4. Change the number of rounds to 3
      5. Click "Start Battle"
    5. At this point RoboCode is setup... but not for use in Netbeans!
  5. Setting up Netbeans for use with RoboCode
    1. File -> New Project. Category=General, Projects=Java Application
      Netbeans Project
    2. Give your package a name and location
      New Project
    3. Add in the RoboCode library
      1. In Netbeans right-click on your project.
      2. Choose "Properties"
      3. Choose "Libraries"
      4. Choose "Add JAR/Folder"
      5. Choose all the JARs in robocode_install_dir/libs
      6. Press "ok"
        addjar
    4. Setup the Runtime
      1. Right-click on your project and select "properties"
        1. Main-class: robocode.Robocode
        2. Arguments: leave this blank
        3. Working Directory: install directory (/Users/dfleck/robocode or c:\robocode)
        4. VM Options: -Xmx512M -Dsun.io.useCanonCaches=false
          1. 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).
        5. Select "ok"
          properties
  6. Configuring Robocode to see your bot.
    1. In Netbeans choose Run->Run Project (this should start Robocode)
    2. Choose Options->Preferences
    3. Choose Development Options
    4. Click "Browse" and choose the classes directory under your Netbeans build directory
    5. Choose Finish
      classpath
  7. Creating your first Robot
    1. Select File->New
    2. Choose category: "Java Classes"
    3. Choose File Types: Java Class
    4. Make up a classname for your Robot (mine is DansRobot)
    5. Click Finish
    6. Create your new Robot. A simple bot could be like this: MyFirstRobot.java make sure to change the package name and class name!!   
      newclass
  8. Testing your robot
    1. From Netbeans choose "Run"
    2. In Robocode create a new battle
    3. In the Robot list your Robot should now show up. 
    4. Select your robot and start the battle!
  9. Debugging
    1. 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

Some Hints