package dummy;
import robocode.*;
import java.awt.geom.Point2D;
//import java.awt.Color;
/**
* St00pid - a robot by Kwok-Cheung Li, also known as "Dummy"
* designed to participate in David Alves' SpinBotChallenge
*/
public class St00pid extends Robot
{
long scantime=0;
double bearing = 0;
double heading=0;
double spinbotTurnRate = rad(6.25);
double spinbotVelocity = 5;
double enemyX, enemyY;
double enemyDist;
double radarturn;
double adjustradar=10;
double timetohit=1;
double direction=150;
double tX, tY;
boolean found = false;
public double rad(double deg)
{
return Math.PI * deg/180;
}
public double deg(double rad)
{
return 180 * rad/Math.PI;
}
public double angle_180(double ang)
{
return (ang + 900)%360 - 180;
}
public void radar()
{
radarturn = angle_180(bearing - getRadarHeading());
if (radarturn>0)
adjustradar = 10;
else
adjustradar = -10;
turnRadarRight(angle_180(bearing - getRadarHeading()) + adjustradar);
while(!found)
{
turnRadarRight(adjustradar);
}
}
public void move()
{
if (getTime()>timetohit)
{
turnRight(angle_180(bearing - getHeading() + 90 - direction/20));
ahead(direction);
direction = -direction;
timetohit = getTime() + enemyDist/11 - 20;
}
else
doNothing();
}
public void gun()
{
turnGunRight(angle_180(bearing - getGunHeading()));
// db is the distance the simulated bullet has travelled; db will probably
// be initialized at a negative value, because we want to offset the fact
// that the last scan may be some time ago (we're working with Robots, not
// AdvancedRobots, remeber?) and that the gun needs time (probably one tick
// to turn before firing...
double db=(scantime-getTime() - 1)*11;
double ww = rad(heading);
double eX = enemyX - getX();
double eY = enemyY - getY();
do
{
db+=11; //11 is the velocity of a fire(3) bullet.
double dx=spinbotVelocity*Math.sin(ww);
double dy=spinbotVelocity*Math.cos(ww);
ww+=spinbotTurnRate; // turn w radians for next step
eX+=dx;
eY+=dy;
}while (db< Point2D.distance(0,0,eX,eY));
double ang = angle_180(deg(Math.atan2(eX, eY)) - getGunHeading());
turnGunRight(ang);
fire(3);
}
public void run()
{
turnRadarRight(360);
while(true)
{
move();
radar();
gun();
}
}
public void onScannedRobot(ScannedRobotEvent e)
{
found = true;
scantime = getTime();
bearing = e.getBearing() + getHeading();
heading = e.getHeading();
enemyDist = e.getDistance();
enemyX = getX() + enemyDist * Math.sin(rad(bearing));
enemyY = getY() + enemyDist * Math.cos(rad(bearing));
spinbotVelocity = e.getVelocity();
}
}