Robo Home | DaRula | Changes | Preferences | AllPages

Here's the code..feel free to add comments in it. I will add some too so that you can understand it better.

Outdated code

package gez;
import robocode.*;
import tools.*; //my own tools library because i had to have something like
                //normalRelativeAngle() wich didn't work here for any reason

public class DaRula extends AdvancedRobot
	static boolean target = false; //this is true if I have a target
	static double dir; //this is the absolute direction of my target
	static double rDir = 10.0; //this is a variable for radarLock
	static String name; //of course the target's name
	static int time = 0; //I use this for timing-out my target
	                     //if I can't scan it for any reason
	static double mov = 90.0; //used for moving ahead because I have to define
	                          //globally if my robot goes forward or backward
	static double hp; //my targets energy to notice changes for supposing a shot
	public void run() {
		while(true) {
				if(time > 5)
					target = false; //if I can't see my target for more than 5 frames
					                //for any reason I will dismiss it
				rDir = -rDir; //radar oscillation
				//Utils.normal() is functionally equal to normalRelativeAngle()
				//but it works also with my bots.. :S
				setTurnRadarRight(Utils.normal( dir - getRadarHeading() + rDir ));
				setTurnGunRight(Utils.normal(dir - getGunHeading()));
				setTurnRight(Utils.normal(dir - getHeading()+90.0));
			} else{
				setTurnRadarRight(mov); //I'm using mov because it doesn't matter
				                        //in wich direction my radar goes if it
										//scans for a target.

	public void onScannedRobot(ScannedRobotEvent e) {
		if( !target ){
			name = e.getName();
			target = true;
		if( name == e.getName() ){
			dir = e.getBearing() + getHeading();
			time = 0; //here i'm reseting my target timer just because i'm scanning
			          //my target right now ;-)
			double diff = (hp-e.getEnergy()); //here's the heart of the movement. :D
			if( diff > 0.0 && diff <= 3.0 )   //it's basically just a radnomizer
				if( Math.random() > 0.4 )     //to dodge bullets
					mov = -mov;
			hp = e.getEnergy();
	public void onHitWall( HitWallEvent e ){
		mov = -mov; //i don't want to be a mule :)

Ok now it's smaller than 250 CodeSize. But I'm glad to hear optimizations. -- gez


If you aren't going to use him in melee battles you can ditch the name and logic based on it. -- Maritn

What exactly does melee battle mean? I tried it against some MiniBots and even against [Rapture 2.13]?. It does well against those bots on a battlefield of 800x600. -- gez

Melee battles (in the Roborumble) are 10 way fights, every bot for himself. It takes a more complex bot design to take into account multiple opponents. At least larger bots are designed with more complexity to handle it. The smaller bots may just do the best they can with minimal accomodations. I wouldn't know. -- Martin

I don't want to use it in melee battles. It's designed for OneOnOne only. -- gez

Robo Home | DaRula | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited November 28, 2007 16:54 EST by Gez (diff)