Home > Game making, Visual Basic > Robocode: AI Masterpieces Blowing Each Other to Bits!

Robocode: AI Masterpieces Blowing Each Other to Bits!

I recently downloaded and installed an awesome open-source piece of freeware called RoboCode. In this cool programming game, you get to create artificially intelligent tanks and pitch them in epic battles against each other.  If this sounds like fun to you, then read on.

Though RoboCode can be difficult to learn, the RoboCode team has created an awesome wiki that will get you started in no time.  Unfortunately, the tutorial for .NET are written for C#. But today, I am going to teach you how to make the MyFirstRobot in Visual Basic.

Step 1: Download and install Robocode. First, download RoboCode here. Then double-click the downloaded file.  Click No, type C:\Program Files\RoboCode, Click Yes, Click Yes again, and wait for it to finish.

Step 2: Create the Robots Project.  In Visual Basic, click File -> New Project.  Choose Class Library for the type and Robots for the Name.

Step 3: Add a Robocode reference.  Right-click “Robots” in the Solution Explorer, then click “Add Reference…”.  Go to the Browse Tab, and navigate to C:\Program Files\RoboCode\libs\robocode.dll.

Step 4: Create your robot.  Create a new class, name it MyRobot.  Then edit the code to look like this:

 ' Access to the public Robocode API
 Imports Robocode

 ' The namespace with your initials, in this case FNL is the initials
 Namespace FNL
     ' The name of your robot is MyRobot, and the robot type is Robot
     Class MyRobot : Inherits Robot
         ' The main method of your robot containing robot logics
          Public Overrides Sub Run()
             ' -- Initialization of the robot --

             ' Here we turn the robot to point upwards, and move the gun 90 degrees
             TurnLeft(Heading - 90)

             ' Infinite loop making sure this robot runs till the end of the battle round
                 ' -- Commands that are repeated forever --

                 ' Move our robot 5000 pixels ahead

                 ' Turn the robot 90 degrees

                 ' Our robot will move along the borders of the battle field
                 ' by repeating the above two statements.
         End Sub

         ' Robot event handler, when the robot sees another robot.
         Public Overrides Sub OnScannedRobot(ScannedRobotEvent e)
             ' We fire the gun with bullet power = 1
         End Sub
     End Class
 End Namespace

Step 5:  Setting up the project for use in Robocode.  Double-click My Project in the Solution Explorer.  In the Application Tab, set the following properties:

Assembly name: FNL.MyRobot_1.0

Default Namespace: FNL.

Step 6:  Add your robot to Robocode.  Build your Project by pressing F6. Click Start, All Programs, Robocode, Robocode.  Once RoboCode has started up, click Options, Preferences.  In the Development Options tab, click “Add…”.  Then navigate to <Your Project>\bin\Debug\FNL.MyRobot_1.0.dll.  Then click Ok, then Finish.

Step 7:   Set up a battle. In RoboCode, click Battle, New.  In the leftmost box, click FNL. In the middle box, click MyRobot. Then click Add.  Do the same for sample.Target. Then click Start, and watch your creation dominate!

I hope that you now have a basic understanding of how to make robots for RoboCode.  The daily question: What is your favorite open-source game?  See ya later!

  1. LinuxGuy
    August 12, 2011 at 7:31 PM

    SuperTuxKart, hands down. Well, maybe xscorch could win too. sTk works on windows though.

  1. No trackbacks yet.

Your comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: