Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Robocode Difficulty Understanding

Hello cf,
I urgently need to know what these lines of code do?

1.
Code:
```gravityX = gravityX * 0.85D - Math.sin(bearing) / enemyDist;
gravityY = gravityY * 0.85D - Math.cos(bearing) / enemyDist;```
2.
Code:
```setTurnRightRadians(Utils.normalRelativeAngle(Math.atan2(gravity
+ 1.0D / getX() - 1.0D / (fieldX - getX()), gravityY + 1.0D
/ getY() - 1.0D / (fieldY - getY()))
This is a code snippet from the DustBunny nano bot, in which uses anti-gravity. I read through the anti-gravity articles, but this doesn't seem like them. Even picking them slightly apart would help me a lot.

I understand the force acting, but was is D?

- Sammy12

• "D" suffix simply indicates that the number in use is a double, not a float. Although best I know Java goes the other way; fractional numbers are double by default and floats must be affixed with F, unlike whole numbers which are integers unless specified as long (ie: `13L;`). You can check this against the Number:
PHP Code:
``` Number n = 0.85;System.out.println(n.getClass().getSimpleName());  ```
Returns Double, while:
PHP Code:
``` Number n = 85;System.out.println(n.getClass().getSimpleName());  ```
Returns Integer.

So in Java, 1.0 = 1.0D.

As for the rest of the equations, there's simply no way to describe them aside from what they do. Its clearly calculating rotation movements, but I can't tell you why or for what.

• ## Users who have thanked Fou-Lu for this post:

Sammy12 (05-29-2012)

• Thanks Fou-Lu,

I think gravityX and gravityY are for the X and Y are the forces at a 90 degree angle when head to head with a bot.

The Math.atan2 is the angle of the quotient of the two coordinates (maybe field - coordinate), so basically the perfect angle between X and Y, which is the best angle for the robot to move in.

Thank you for your incite on the "D" that helps make things a lot easier. Did you not want to tell me what the answer was or was there not enough information provided?

• Not enough information to use. But on top of that I'd have to dust off the old geotrig books to solve the equations to see what its actually doing :P

• haha thanks for all the help it actually really helped me understand what was going on

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•