# SpinBotChallenge/St00pid

Robo Home | SpinBotChallenge | Changes | Preferences | AllPages

```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 the Pez' SpinBotChallenge
* http://robowiki.net/cgi-bin/robowiki?SpinBotChallenge
*/

public class St00pid extends Robot
{

long scantime=0;
double bearing = 0;
double spinbotVelocity = 5;
double enemyX, enemyY;
double enemyDist;
double timetohit=1;
double direction=150;
double tX, tY;
boolean found = false;

{
return Math.PI * deg/180;
}

{
}

public double angle_180(double ang)
{
return (ang + 900)%360 - 180;
}

{
else
while(!found)
{
}
}

public void move()
{
if (getTime()>timetohit)
{
direction = -direction;
timetohit = getTime() + enemyDist/11 - 14;
}
else
doNothing();
}

{
double tX, tY, dX, dY;
double sign;
tX = getX() + dX;
tY = getY() + dY;

if (tX>=20 && tX<=getBattleFieldWidth()-20 && tY>=20 && tY<=getBattleFieldHeight()-20)
return;

if (tX < 20)
{
tX = 20;
if (dY<0)
sign = -1;
else
sign = 1;
dX = 20-getX();
dY = sign * Math.sqrt(direction*direction - dX*dX);
}

if (tX > getBattleFieldWidth()-20)
{
tX = getBattleFieldWidth()-20;
if (dY<0)
sign = -1;
else
sign = 1;
dX = getBattleFieldWidth()-20-getX();
dY = sign * Math.sqrt(direction*direction - dX*dX);
}

if (tY < 20)
{
tY = 20;
if (dX<0)
sign = -1;
else
sign = 1;
dY = 20-getY();
dX = sign * Math.sqrt(direction*direction - dY*dY);
}

if (tY > getBattleFieldHeight()-20)
{
tY = getBattleFieldHeight()-20;
if (dX<0)
sign = -1;
else
sign = 1;
dY = getBattleFieldHeight()-20-getY();
dX = sign * Math.sqrt(direction*direction - dY*dY);
}
double turn = deg(Math.atan2(dX, dY)) - getHeading();
if (direction<0)
turn += 180;
turnRight(angle_180(turn));
}

public void gun()
{
if (Math.abs(bearing - getGunHeading()) < 20)
// 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, remember?) and that the gun needs time (probably one tick
// to turn before firing...
if (!(getGunHeat()<1))
return;

double db=(scantime-getTime() - 1)*11;
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()
{
while (!(getGunHeat()<1))
{
found = false;
}
timetohit = getTime() + enemyDist/11 - 20;
while(true)
{
move();
found = false;
gun();
}
}

public void onScannedRobot(ScannedRobotEvent e)
{
found = true;
scantime = getTime();
enemyDist = e.getDistance();
enemyX = getX() + enemyDist * Math.sin(rad(bearing));
enemyY = getY() + enemyDist * Math.cos(rad(bearing));
spinbotVelocity = e.getVelocity();
}

}
```

Robo Home | SpinBotChallenge | Changes | Preferences | AllPages