Robocode – Untouchable

Robocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java or .NET. The robot battles are running in real-time and on-screen.

About six months ago, in school, my team (Wonjohn Choi, Raafay Muzaffar) created our robot named “Untouchable” based on Robocode software.

With numerous experiment, this robot is designed to avoid bullets with a repeated movement and shoot bullets with optimized power.

Untouchable

Untouchable

This robot wins against any built-in robocode robots and won school Robocode contest!

You can download the full zip file in Downloads page.

Here is the main source code (without comments):


/**
 *
 * Untouchable - a robot by Wonjohn Choi and Raafay Muzaffar
 * @author Wonjohn Choi, Raafay Muzaffar
 * @date Jan. 19th, 2010
 */

import robocode.*;
import java.awt.Color;

public class Untouchable extends Robot
{
  Color getRandomColor[]=new Color[4];

  public void run()
  {
    this.turnGunRight(90);
    this.turnRadarRight(90);

    while(true)
    {
      for(int i=0;i<4;i++)
      {
        getRandomColor[i]=
        Color.getHSBColor((float)Math.random(),(float)Math.random(),(float)Math.random());
      }

      setColors(getRandomColor[0],getRandomColor[1],getRandomColor[2],Color.WHITE,getRandomColor[3]);

      for(int i=0;i<2;i++)
      {
        this.turnRadarLeft(360);
        this.turnRight(20);

        this.ahead(250);
      }

      for(int i=0;i<2;i++)
      {
        this.turnRadarLeft(360);
        this.turnLeft(10);

        this.back(250);
      }

    }
  }

  /**
   * onScannedRobot: What to do when you see another robot
   */
  public void onScannedRobot(ScannedRobotEvent e)
  {
    this.turnRight(e.getBearing()-90);

    double dist=e.getDistance();

    if(this.getEnergy()<5)
    {
      this.fire(0.1);
    }

    else if(dist<200)
    {
      this.fire(3);
    }

    else if(dist<400)
    {
      this.fire(2);
    }

    else if(dist<600)
    {
      this.fire(1);
    }

    else
    {
      this.fire(0.1);
    }
  }

  public void onHitRobot(HitRobotEvent e)
  {
    if (e.getBearing() >= 0)
    {
      turnRight(e.getBearing()-90);
    }
    else
    {
      turnRight(-1*(e.getBearing()-90));
    }

    fire(3);
  }
}
Advertisements

About Wonjohn Choi
Hello, I am a software developer Wonjohn Choi. I live in Mississauga, Ontario, Canada and study at a school called St. Francis Xavier Secondary School. My core interests include Math, Computer Science, and Engineering. Thank you.

Leave a Reply

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: