Discussion:
basic help
Tomás Abril
2014-05-02 22:03:35 UTC
Permalink
Hi, I'm new to robocode and just started my first robot.
I created a kind of targeting that predicts where the enemy will be if he
keeps going in the same direction and in the same speed. But it doesn't
seem to be working.
My bot just shoots exactly where it scans the other robot. I am fighting
against the sample wall bot.

Here is my bot:
https://github.com/tomasabril/cortinabot/blob/master/Tomasbot.java

Can someone help me?
Thanks
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
fnl
2014-05-04 20:58:27 UTC
Permalink
Your code look okay to me. I have downloaded the source, compiled it, and
had several games againt sample.Walls.
I see you are right that the bullet is always "behind" - but I can't see
why.

With my own bots I usually computes the x,y coordinates of the enemy and
try to figure out what the x,y coordinate will be after my bullet has
traveled the distance to the target x,y.

I propose you have a look at the Liniar Targetting algoritms<http://robowiki.net/wiki/Linear_Targeting>available at the
RoboWiki <http://robowiki.net>.

Cheers,
- Flemming
Post by Tomás Abril
Hi, I'm new to robocode and just started my first robot.
I created a kind of targeting that predicts where the enemy will be if he
keeps going in the same direction and in the same speed. But it doesn't
seem to be working.
My bot just shoots exactly where it scans the other robot. I am fighting
against the sample wall bot.
https://github.com/tomasabril/cortinabot/blob/master/Tomasbot.java
Can someone help me?
Thanks
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
fnl
2014-05-05 19:15:27 UTC
Permalink
Nice! Why didn't I figure that out. Of course the getHeadingRadians() and
getGurnHeadingRadians() should be used. :-)
That was the reason why it was so hard to find the error in your code.
Right mathematics, but wrong methods regarding degrees versus radians. =)

Thanks for sharing the updated version for reference. I will keep that in
mind. :-)

Cheers,
- Flemming
Hello flemming,
thanks for the reply.
I just changes everything from pure angles(degrees) to radians and it is
now working!. The magic of pi it seems.
I was probably treating degrees as normal (scalar?) numbers at some point
but coudn't find where.
Before I was also not properly using the scanner separate from the gun.
public void onScannedRobot(ScannedRobotEvent e) {
// calculate firepower based on distance
double firePower = Math.min(500 / e.getDistance(), 3);
// calculate speed of bullet
double bulletSpeed = 20 - firePower * 3;
double absoluteBearing = getHeading() + e.getBearing();
double eLateralVelocity = e.getVelocity() * Math.sin(e.getHeading() - absoluteBearing);
double offset = Math.asin(eLateralVelocity/bulletSpeed);
turnGunRight(normalize( absoluteBearing - getGunHeading() + offset ));
// if the gun is cool and we're pointed at the target, shoot!
if ( getGunHeat() == 0 && Math.abs(getGunTurnRemaining()) < 10 ) {
fire(firePower);
}
public void onScannedRobot(ScannedRobotEvent e) {
// calculate firepower based on distance
double firePower = Math.min(500 / e.getDistance(), 3);
double bulletSpeed = 20 - firePower * 3;
double eAbsoluteBearing = getHeadingRadians() + e.
getBearingRadians();
double eLateralVelocity = e.getVelocity() * Math.sin(e.
getHeadingRadians() - eAbsoluteBearing);
double offset = Math.asin(eLateralVelocity/bulletSpeed);
setTurnGunRightRadians(Utils.normalRelativeAngle(eAbsoluteBearing
- getGunHeadingRadians() + offset ));
// if the gun is cool and we're pointed at the target, shoot!
if ( getGunHeat() == 0 && Math.abs(getGunTurnRemaining()) < 10 ) {
setFire(firePower);
}
execute();
turnRadarRightRadians(Utils.normalRelativeAngle( getHeadingRadians
() + e.getBearingRadians() - getRadarHeadingRadians() ));
}
Post by fnl
Your code look okay to me. I have downloaded the source, compiled it, and
had several games againt sample.Walls.
I see you are right that the bullet is always "behind" - but I can't see
why.
With my own bots I usually computes the x,y coordinates of the enemy and
try to figure out what the x,y coordinate will be after my bullet has
traveled the distance to the target x,y.
I propose you have a look at the Liniar Targetting algoritms<http://robowiki.net/wiki/Linear_Targeting>available at the
RoboWiki <http://robowiki.net>.
Cheers,
- Flemming
Post by Tomás Abril
Hi, I'm new to robocode and just started my first robot.
I created a kind of targeting that predicts where the enemy will be if
he keeps going in the same direction and in the same speed. But it doesn't
seem to be working.
My bot just shoots exactly where it scans the other robot. I am fighting
against the sample wall bot.
https://github.com/tomasabril/cortinabot/blob/master/Tomasbot.java
Can someone help me?
Thanks
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...