Difference between revisions of "Robocode 1"

From CompSciWiki
Jump to: navigation, search
(Introduction and Installation rough draft steps finished)
m (Changed the name of the main menu from robot console to main menu)
Line 21: Line 21:
  
  
When the battle ends you will be presented with a scoreboard of the demo battle and the Robot Console. Close the scoreboard, we have no use for it.
+
When the battle ends you will be presented with a scoreboard of the demo battle and the Main Menu. Close the scoreboard, we have no use for it.
 +
 
 +
== The Main Menu ==
 +
 
 +
 
  
== The Robot Console ==
 
 
-talk about all sections
 
-talk about all sections
 
-new  
 
-new  

Revision as of 18:19, 3 April 2012

COMP 1010 Home > Back to Extra Labs

Introduction

In this lab you will learn and be able to play the exciting coding game called Robocode. Robocode is an event driven program that allows us to create, modify and test virtual warrior robots in a virtual battlefield. If you are not familiar with event driven programming you should consider completing the GUI Lab part 1 lab or at least read Step 3. Completing these Robocode labs will also give you a head start on understanding and using Application Programming Interfaces (APIs).

Installation

Note: To play and use Robocode you must have Java 5 or higher installed on your machine. You can download Java from here: http://java.com/en/.

  • After Robocode is installed you can run it by either using the supplied shortcut or navigating to your installation folder and running the robocode.bat file.

Upon first boot of the game you see a short demo battle


RoboCodeIntroBattle.png


When the battle ends you will be presented with a scoreboard of the demo battle and the Main Menu. Close the scoreboard, we have no use for it.

The Main Menu

-talk about all sections -new


Sample battle

- To see what the program actually does (sample.MyFirstRobot, sample.RamFire, sameple.Tracker) - screen shot of main menu

Create your first Robot

Now that you have the basics down, lets create your first Robot. 1.From the Robot menu, select "Editor" (Or Press Ctrl+E). This opens up the Robot Editor where you will make, edit, and compile your Robot. 2. From the "File" menu, select "New", then select Robot. (Or press Ctrl+N). 3. Enter a name for your Robot (This name cannot contain any spaces, similar to java variables! Remember, Robocode is made in java). Click "Ok". 4. Enter a short package name for your Robot. This should be somewhat different than your Robot's name. 5. Voila! Your Robot has been created. As you can see the Robot code pops up and is ready to edit. Your Robot is what is known as an [1] in more advanced programming. 6. Your Robot has some basic methods in its file. These include run(), onScannedRobot(ScannedRobotEvent e), onHitByBullet(HitByBulletEvent e), onHitWall(HitWallEvent e).


Making the Robot Move

Now that your code for your Robot has been created, lets add in some functionality. By default the robot has some movement functionality already in it. If you look in the the run() method, inside the main loop while(true) are the following movements. ahead(100); turnGunRight(360); back(100); turnGunRight(360); Lets test this out. Compile your Robot by going under to"Compiler", select "Compile" (Or press Ctrl+B). Once it successfully compiler click "Ok". Yay, your Robot is now compiled and ready to move around the map!

Go back to the main GUi and lets import your Robot. Click "Battle", and click "New" (Or press Ctrl+N). Locate your package under the Packages section. Click on it to see your Robot under the "Robots" section. Click on "Add ->" and add your Robots to the list of selected Robots. Now lets see if your Robot actually moves! Click on Start Battle. Unless you added any other Robots your Robot should just run around aimlessely for 10 rounds. But now we have verified that movement works! If you like, you can add in different values to the ahead, turnGunRight, back, and turnGunRight to experiment with it.

Firing on Other Robots

Now that we know our Robot can move around, let's make it fire on other Robots! By default, when your


Additional Methods

  - run(), onSeannedRobot() and onHitByBullet()

Battle your Robot

- This is what you would have to show the TA, that your Robot can defeat a default one.