Robocode/My First Robot

From RoboWiki
< Robocode(Difference between revisions)
Jump to: navigation, search
(New page: {{stub}} Will be finished by User:FlemmingLarsen Category:Robocode Documentation)
 
Line 2: Line 2:
  
 
Will be finished by [[User:FlemmingLarsen]]
 
Will be finished by [[User:FlemmingLarsen]]
 +
 +
== Creating a Robot ==
 +
Here's the fun stuff: This is what Robocode is all about!
 +
 +
Creating a robot can be easy. Making your robot a winner is not. You can spend only a few minutes on it, or you can spend months and months. I'll warn you that writing a robot can be addictive! Once you get going, you'll watch your creation as it goes through growing pains, making mistakes and missing critical shots. But as you learn, you'll be able to teach your robot how to act and what to do, where to go, who to avoid, and where to fire. Should it hide in a corner, or jump into the fray?
 +
 +
== My First Robot ==
 +
Ready to create your first robot? I hope you'll find that it's easy, straightforward, fun, and addictive!
 +
 +
Robocode ships with a number of sample robots that you can look at for ideas, and to see how things work. You can use the Robot Editor to look at all of them.
 +
 +
In this section, we'll use the Robot Editor to create your very own, brand new robot.
 +
 +
=== First Step ===
 +
The first step is to open up the Robot Editor. From the main Robocode screen, click on the '''Robot''' menu, then select '''Editor'''.
 +
 +
When the editor window comes up, click on the '''File''' menu, then select '''New Robot'''.
 +
 +
In the dialogs that follow, type in a name for your robot, and enter your initials.
 +
 +
Voila! You now see the code for your own robot.
 +
 +
=== Cool. So what am I looking at? ===
 +
This is what you should be looking at (names have been changed to protect the innocent):
 +
 +
  package man;
 +
  import robocode.*;
 +
  &nbsp;
 +
  public class MyFirstRobot extends Robot {
 +
      public void run() {<b>
 +
          while (true) {
 +
              ahead(100);
 +
              turnGunRight(360);
 +
              back(100);
 +
              turnGunRight(360);
 +
          }</b>
 +
      }
 +
  &nbsp;<b>
 +
      public void onScannedRobot(ScannedRobotEvent e) {
 +
          fire(1);
 +
      }</b>
 +
  }
 +
 +
We're only concerned with the bits in '''bold''' here... you won't need to change anything else. Not that much, right?
 +
 +
By the way, if you're REALLY concerned about the rest of it, right now, I describe it here..
 +
  
 
[[Category:Robocode Documentation]]
 
[[Category:Robocode Documentation]]

Revision as of 23:16, 27 November 2007

This article is a stub. You can help RoboWiki by expanding it.

Will be finished by User:FlemmingLarsen

Contents

Creating a Robot

Here's the fun stuff: This is what Robocode is all about!

Creating a robot can be easy. Making your robot a winner is not. You can spend only a few minutes on it, or you can spend months and months. I'll warn you that writing a robot can be addictive! Once you get going, you'll watch your creation as it goes through growing pains, making mistakes and missing critical shots. But as you learn, you'll be able to teach your robot how to act and what to do, where to go, who to avoid, and where to fire. Should it hide in a corner, or jump into the fray?

My First Robot

Ready to create your first robot? I hope you'll find that it's easy, straightforward, fun, and addictive!

Robocode ships with a number of sample robots that you can look at for ideas, and to see how things work. You can use the Robot Editor to look at all of them.

In this section, we'll use the Robot Editor to create your very own, brand new robot.

First Step

The first step is to open up the Robot Editor. From the main Robocode screen, click on the Robot menu, then select Editor.

When the editor window comes up, click on the File menu, then select New Robot.

In the dialogs that follow, type in a name for your robot, and enter your initials.

Voila! You now see the code for your own robot.

Cool. So what am I looking at?

This is what you should be looking at (names have been changed to protect the innocent):

 package man;
 import robocode.*;
  
 public class MyFirstRobot extends Robot {
     public void run() {
         while (true) {
             ahead(100);
             turnGunRight(360);
             back(100);
             turnGunRight(360);
         }
     }
  
     public void onScannedRobot(ScannedRobotEvent e) {
         fire(1);
     }
 }

We're only concerned with the bits in bold here... you won't need to change anything else. Not that much, right?

By the way, if you're REALLY concerned about the rest of it, right now, I describe it here..

Personal tools