[Home]DB's Robots

Robo Home | Changes | Preferences | AllPages

Difference (from prior major revision) (no other diffs)

Added: 188a189,190

Awesome!! THANK YOU!! I've been wondering how to make my robots do multiple things at once for a while. I never would have guesed that those set commands were the solution! DB

This is my best robot and only success so far.


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

public class hi extends Robot
{
       public void run() {
		// After trying out your robot, try uncommenting the import at the top,
		// and the next line:
		setColors(Color.red,Color.blue,new Color (45,34,145));
		while(true) {
			// Replace the next 4 lines with any behavior you would like
			ahead(10);
			turnRadarRight(360);
			turnRight(25);
		}
	}

	/**
	 * onScannedRobot: What to do when you see another robot
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		if (e.getDistance()<200) {
			turnRight(e.getBearing());
			fire(2);
			ahead(100);
			fire(2);
		}
		else {
			turnRight(e.getBearing());
			fire(2);
		}
	}

	/**
	 * onHitByBullet: What to do when you're hit by a bullet
	 */
	public void onHitByBullet(HitByBulletEvent e) {
		if (e.getDistance()<75)
			fire(3);
		turnRight(e.getBearing());
		fire(2);
		fire(2);
	}
	public void onHitRobot(HitRobotEvent e) {
		fire(3);
	}
	
}

This is a robot that half works.


package dwb;
import robocode.*;
import java.awt.Color;
public class Xedhy extends Robot
{
	public void run() {
		while(true) {
			setColors(new Color(255,255,255),new Color(255,255,0),new Color(100,100,0));
			turnRadarRight(3600);
			ahead(10000);
		}
	}
	public void onHitWall(HitWallEvent event) {
		out.println("HEY!");
		turnLeft(180);
	}
	public void onHitRobot(HitRobotEvent event) {
		out.println("Outta my way!");
		fire(3);
	}

	public void onScannedRobot(ScannedRobotEvent event) {
		out.println("I've got you in my sights.");
		if (event.getDistance()>100) {
			turnRight(event.getBearing());
			fireBullet(1);
			ahead(50);
			turnRadarLeft(20);
		}
		else {
			turnLeft(event.getBearing());
			fireBullet(2);
			ahead(25);
			turnRadarLeft(20);
		}
	}
	public void onHitByBullet(HitByBulletEvent event) {
		out.println("OUTCH!");
		turnRight(event.getBearing());
		fire(2);
		turnRadarLeft(20);
	}
	public void onWin(WinEvent event) {
		out.println("YES!!!!!!");
		turnRight(360);
		fire(1);
		turnLeft(360);
		fire(1);
	}
	public void onDeath(DeathEvent event) {
		out.println("AAAAARRRRG!!!!");
	}	
}

This is a very buggy robot that I havn't worked on very mutch.


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

public class Die extends Robot
{
	public void run() 
		{
			setColors(Color.red,Color.blue,Color.green);
			while(true) 
				{
					turnRadarRight(360);
				}
		}
	
	public void onScannedRobot(ScannedRobotEvent e) 
		{
			if (e.getDistance()>500)
				{
					turnRadarRight(10);
					ahead(200);
				}
			else 
				{
					if (e.getDistance()>100)
						{
							turnRight(e.getBearing());
							fire(1);
						}
					else 
						{
							if (e.getVelocity()==0) 
								{
									turnRight(e.getBearing());
									fire(3);
								}
							else 
								{
									turnRight(e.getBearing());
									ahead(50);
								}
						}
					turnRadarRight(10);
				}
		}

	public void onHitByBullet(HitByBulletEvent e) 
		{
			turnRight(e.getBearing());
			fire(1);
		}
	
	public void onHitRobot(HitRobotEvent e) 
		{
			turnRight(e.getBearing());
			fire(3);
			back(200);
		}
	public void onHitWall(HitWallEvent e) 
		{
			turnRight(e.getBearing());
			back(200);
		}
}

I see all of your creations extend robot. Although you may already know this, you can have them extend AdvancedRobot to be able to execute multiple actions at once (e.g. turning while moving forward) through setX() commands. See the sample bot Crazy for a simple example -- Kev

Awesome!! THANK YOU!! I've been wondering how to make my robots do multiple things at once for a while. I never would have guesed that those set commands were the solution! DB


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited May 13, 2006 7:11 EST by DB (diff)
Search: