Re: basic help

fnl <[email protected]>
Newsgroups gmane.comp.java.robocode
Message-ID <[email protected]>
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

Den mandag den 5. maj 2014 02.06.02 UTC+2 skrev Tomás Abril:
>
> 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.
>
> Here is the code for future reference:
> before:
>
>
>         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);
>                 }
>
>
> after:
>     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() ));
>
>     }
>
>
>
> On Sunday, May 4, 2014 5:58:27 PM UTC-3, fnl wrote:
>>
>> 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
>>
>> Den lørdag den 3. maj 2014 00.03.35 UTC+2 skrev 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.
>>>
>>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.