Difference between revisions of "SuperSittingDuck"

From Robowiki
Jump to navigation Jump to search
m
m (Using <syntaxhighlight>.)
Line 17: Line 17:
  
 
== Code ==
 
== Code ==
<pre>package wiki.SuperSampleBot;
+
<syntaxhighlight>package wiki.SuperSampleBot;
 
import robocode.*;
 
import robocode.*;
 
import java.awt.Color;
 
import java.awt.Color;
Line 72: Line 72:
 
}
 
}
 
 
}</pre>
+
}</syntaxhighlight>

Revision as of 09:31, 1 July 2010

April Fools!!!

SuperSittingDuck is part of the Super Sample Bots set by CrazyBassoonist. These robots are intended to provide new robocoders with a new challenge after beating all of the sample robots.


Movement

SuperSittingDuck moves to the enemy and stays at a close distance, then goes and cries in a corner of the field if it gets hit too much.


Targeting

None.


Code

package wiki.SuperSampleBot;
import robocode.*;
import java.awt.Color;

/**
 * SuperSittingDuck - a SuperSampleBot by CrazyBassoonist
 */
public class SuperSittingDuck extends AdvancedRobot{
	int enemyHits;
	boolean	goCryInCorner;
	/**
	 * run: SuperSittingDuck's default behavior
	 */
	public void run() {
		/**
		*set the colors
		*/
		setBodyColor(Color.yellow);
		setGunColor(Color.yellow);
		do{
			turnRadarRightRadians(Double.POSITIVE_INFINITY);
		}while(true);
	}
	public void onScannedRobot(ScannedRobotEvent e){
		double absBearing=e.getBearingRadians()+getHeadingRadians();
		double robotForce=5*(e.getDistance()-100);
		/*
		*If we get hit too much, go cry in the corner.
		*/
		if(goCryInCorner){
			turnRight(90-getHeading());
			ahead((getBattleFieldWidth()-getX())-20);
			turnRight(0-getHeading());
			ahead((getBattleFieldHeight()-getY())-20);
		}
		/*
		*Otherwise go towards the other robot and don't fire at him
		*/
		else{
			setAhead(robotForce);
			setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(absBearing-getHeadingRadians()));
		}
		setTurnRadarRightRadians(robocode.util.Utils.normalRelativeAngle(absBearing-getRadarHeadingRadians()));
	}
	public void onHitByBullet(HitByBulletEvent e){
		/*
		*Find out how much the enemy has hit us...
		*/
		enemyHits++;
		if(enemyHits==4){
			System.out.println("Oh, the shame of losing!");
			goCryInCorner=true;
		}
	}
	
}