IBM ROBO-CODE2007. 7. 1. 18:24

원본 http://robocode.sourceforge.net/help/ide/ide.html



Getting tired of Robocode's built-in editor? It may be time for a real IDE (Integrated Development Environment). This tutorial will show you how to use Eclipse, available at
www.eclipse.org/downloads/.

At the time of this writing, the latest stable build is Eclipse SDK 3.2.2. Robocode itself is being developed usinh the Eclipse SDK (typically the newest version possible). If a more recent stable version exists, you should of course download that instead of the 3.2.2 release.

What are you waiting for? Go get it now!

Once you have Eclipse installed and running, I'll show you how to create a project for your robots.

Next: Creating a project for your robots



---------------------------------------------------------------------------------------


Creating a Project for your Robots

In order to build a Robocode robot in Eclipse, we first have to create a "Project" to store them in. This page will assist you in setting that up.

First, select File->New->Project in the menu.

In the "New Project" dialog, select "Java Project" then click Next.


Type in a name for your project, then click next. Do not click Finish yet. (Oops! I clicked finish)

Select the "Libraries" tab, then click on "Add External JARs"

Browse to the robocode directory, select "robocode.jar" then click "Open"

The window should now look like this. Make sure "robocode.jar" is selected.

Now you must select the "Javadoc location: (None)" under "robocode.jar" and click "Edit..."

Type in (or browse to) the path for robocode.jar, again. Optionally, enter the location of Robocode's Javadocs. The window should now look like this:

Click "OK", then click "Finish" to build your project. Congratulations!

Next: Creating a Robot

----------------------------------------------------------------------------------------------------------


Creating a Robot

Ok, so we have a project now, and it's time to create a robot (or many robots!) in it.

First, right-click on the "MyRobots" project, and select New -> Class:


Next, fill in the package name (Robocode suggests your initials), a Robot Name (here I have "FnlBot"), and change the Superclass to "robocode.Robot":


Click Finish, and you'll see your robot class, like this:

You can now edit your robot however you like.

You can save your robot as often as you like by hitting CTRL-S, or selecting "File->Save". There's no need to select Compile anymore, since Eclipse takes care of it for you. Have fun playing around with Eclipse. Personally, I like to change all the colors, turn off bold print, move the windows around, and do all sort of things to customize it to my liking. Since there's no better way to learn than by playing around, I'll leave you to it! (Hint: Workbench -> Preferences -> Java -> Editor -> Colors)

The only thing left is to make sure Robocode sees your robot.

Next: Adding your robot(s) to Robocode


 ------------------------------------------------------------------------------------------------------------

Adding your Robot Project to Robocode

Start up Robocode and select the Options->Preferences menu, select the Development tab, then type in the path to your robots project.

Click Finish, then start a new battle, and voila! There's your robot.

You can edit your robot in Eclipse as much as you want. Just remember to save it (CTRL-S) before switching back to Robocode. Robocode will use the latest saved version, every time you start a new battle.

Eclipse is very powerful, and will assist you greatly in writing robots (or anything else, for that matter). For instance, try hitting CTRL-SPACE when you can't remember the exact wording of something:

Next: Running your robot from Eclipse

Running your robot from Eclipse

Wondering how to run your robot in Robocode from Eclipse? Well this is possible!

Right-click on your project, move the mouse-pointer down to "Run As" in the menu that opens and click "Run...".

Now the following window will show up:

Click on the "Java Application" on the left side, and afterwards the "New" button (New launch configuration).

Now you should change the name of your launch configuration to something you remember, e.g. "MyRobots - Robocode".

In the "Main class" text field you must write "robocode.Robocode", which is the main class of Robocode used for playing the game.

Next, you must click on the "Arguments" tab.

Here you write "-Xmx512M -Dsun.io.useCanonCaches=false" into the "VM arguments" text box. The "-Xmx512M" tells the Java VM that Robocode can use up to 512 MB RAM (on the heap), and "-Dsun.io.useCanonCaches=false" is a workaround to prevent SecurityExceptions to occur when robots try to access a file.

Finally, you must click on the "Other" radio button under "Working directory", and then write the full path to the folder where Robocode is installed in the text file beside "Other".

Now you press "Run", and Robocode will (hopefully) start up. In Robocode you start your robot by selecting Battle->New from the menu or by using the hotkey Ctrl+N. Next, you select your robot and some other opponent robots, and press "Start Battle".

The next time you want to run your robot(s) in Robocode from Eclipse, you simply run your launch configuration like this:

An easier way is just to click on the green play button without the popup menu. This will start the last launch configuration automatically, which should be your project.

Next: Debugging your robot with Eclipse


Debugging your robot with Eclipse

In some situations, you might want to debug your robot by setting break points (e.g. conditional breakpoints), step through lines of codes and see how the values of your variables changes as the code goes along, or just see if an event handler is ever called.

Fortunately, this is possible to do with Robocode!

Before you can start debugging with Eclipse, you must be able to run your robot from Eclipse. So if you have not already setup your project accordingly to Running your robot from Eclipse, you must do this before you are able to proceed with debugging.
In the following example we set a breakpoint in the first line of the run() method of a robot. In this case the robot is a simple Robot where each command takes exactly 1 turn to execute() before it processes the next.

Right-click in the border area of the source editor till a popup menu shows up, where you can select "Toggle Breakpoint".

When the breakpoint has been set, a blue bullet will be shown beside the line to break at.

Now, let's try to start debugging our robot.

You start debugging by clicking on the debug button that looks like a bug and selecting your launch configuration. Alternatively, you could just click on the debug button, which will start debugging from the last launch configuration that was started.

When Robocode has started up, you start your robot by selecting Battle->New from the menu or by using the hotkey Ctrl+N. Next, you select your robot and perhaps some opponent robots, and press "Start Battle".

Notice: As soon as the battle begins, it is important that you must press the "Pause/Debug" button at the bottom of the battle window.

This will pause Robocode making debugging possible. If you do not pause Robocode, the game will run, and the robot that you debug will be seen as inactive when it hits a breakpoint, as it has not been active for some time. Besides, when Robocode is paused the internal time is also put on hold, which can be critical when debugging.

In this example, Eclipse should already have switched into the Debug Perspective. If this is the first time you debug with Eclipse, it might ask you if you want to switch into the Debug Perspective. Here I normally answer "Yes".

In the Debug Perspective, the excution of your robot should already have stopped at our breakpoint.

If Eclipse has not stopped at our breakpoint, you should resume the battle by clicking on the "Pause/Debug" button until Eclipse stops at our breakpoint, and then click on the "Pause/Debug" button again to pause the battle.

Now we want to step to the next line after our breakpoint. Therefore we press the "Step Over" button or alternatively press the F5 key.

Nothing happens? Well, Robocode is still paused, so we will not be able to proceed the debugging before we continue the battle. However, we do not want Robocode to rush with continuing the battle, playing lot's of turns before we get the chance of getting to the next line after our breakpoint. We just want to execute one turn at a time when debugging.

Here the "Next Turn" button becomes handy, which is located next to the "Pause/Debug" button at the bottom of the battle window. This button can only be activated when the game is paused, and is used for letting Robocode execute to the next turn of the battle, i.e. it performs a single turn.

In our case, we should carefully click on the "Next Turn" button approximately 4 times (might be more or less times) until Eclipse steps to the next line of code after our breakpoint. The reason why you have to hit the button several times is because it takes several turns until the robot has finished turning.


Now we have made a single step with our robot. So now we could set a breakpoint on the "fire(1)" line in the onScannedRobot() method, which is the event handler that is called whenever our robot scans another robot.

Here we don't want to make one turn at the time. Instead, we just resume the game by clicking on the "Pause/Resume" button.

When our robot scans another robot, Eclipse will jump right to the breakpoint set in onScannedRobot().


Above all, have fun and enjoy!



Posted by BAGE