# Segmentation/Segments

Robo Home | Segmentation | Changes | Preferences | AllPages

Segments

When gathering data for a statistical operation, you will segment on one or more of these variables. Here are most of the variables that are segmented on, feel free to add variables and how to collect them to the list.

• VisitCount?: Typically GuessFactor, but it could be applied to whatever you wish. You always have this segment.
• ` (oldAngle-newAngle)/max_escape_angle // eg, Math.asin(max bot velocity/bullet velocity)`
• Distance: Range to the target at shot time.
• ` e.getDistance() `
• Bullet Flight Time: Time from fire until the bot will be hit.
• ` e.getDistance() / (20 - 3 * shotPower) `
• Bullet Power: The power of the bullet you fire with. Could be useful against wavesurfers that weight danger on power.
• ` shotPower `
• Target Velocity: The targets velocity.
• ` e.getVelocity() `
• ` e.getHeading() - oldHeading `
• ` e.getHeading() - (e.getBearing() + getHeading()) // abs heading - abs bearing `
• Target LateralVelocity: The velocity perpendicular to your direction.
• ` e.getVelocity() * Math.sin(e.getHeadingRadians() - (e.getBearingRadians() + getHeadingRadians())) `
• ` e.getVelocity() * -1 * Math.cos(e.getHeadingRadians() - (e.getBearingRadians() + getHeadingRadians())) `
• Target Acceleration: If target is accelerating, constant, or decelerating. Often very useful.
• ```    int accelSegment(double deltaBearing, double oldDeltaBearing) {
int delta = (int)(Math.round(5 * enemyDistance * (Math.abs(deltaBearing) - Math.abs(oldDeltaBearing))));
if (delta < 0) {
return 0;
}
else if (delta > 0) {
return 2;
}
return 1;
}```
• Near Wall: Probably the most useful. Usually split into middle, near wall, and near corner.
• Move Times: Number of ticks since the velocity was last 0, since velocity changed, or since velocity was max speed. Useful against stop and go and oscillators, and many other types of movement. Some tanks, like CassiusClay, also make this (inversely) proportional to the enemy's distance.
• ```if(enemyVelocity==0) moveTimes=0;  else  moveTimes++;
moveTimesIndex = Math.min(9, moveTimes/5);
```
• Wave Type: If data is from real or virtual bullet. Only useful if profiles match.

• Antigravity Force: The magnitude of the antigravity vector acting on an enemy
• This means calculating the antigravity for the enemy rather than for self, and segmenting on this; I had been planning something similar in another of my bots a while back, but never got around to it
• Robots Remaining: The number of enemies remaining.
• Number of Teammates: The number of teammates an enemy has remaining
• Could be very useful; droids can die when there are no radars left, and certain teams may modify their movement strategies based on this (DrunkenTeam? comes to mind)

I have a question about the calculation of LateralVelocity and AdvancingVelocity. This page says to multiply the velocity by the sin and cos, respectively, of this angle:
```(e.getHeadingRadians() - e.getBearingRadians() + getHeadingRadians())
```
But it seems to me it should be this:
```(Math.PI - (e.getHeadingRadians() - (e.getBearingRadians() + getHeadingRadians()))
```
Let's take two example situations. The opponent is directly above me, and we're both facing up (zero radians). The first solution gives 0 (sin=0, cos=1), the second gives Pi (sin=0, cos=-1). Clearly they are both right for the LateralVelocity, but the first gives them a positive AdvancingVelocity while the second gives a negative. Second example: we're in the same positions, but now my heading is Pi/4 (45 degrees). The first equation now calculates to (0 - (-Pi/4) + Pi/4) = Pi/2 (sin=1, cos=0), while the second calculates to (Pi - (0 - (Pi/4 - Pi/4))) = Pi (sin=0, cos=-1); the same as it did in the first situation. I see no way they should be 100% lateral and 0% advancing in this situation.

The "Math.Pi - ..." thing could be dropped if positive advancing = moving away from you, but it sounds like the opposite of that. Could somebody please just confirm to me that my assessment is correct? I'm pretty new to Robocode, and I'm afraid I'm just misunderstanding something here... Thanks. -- Voidious

```double advancingvelocity = -Math.cos(e.getHeadingRadians()-absbearing)*e.getVelocity();
```
Note you make Math.cos(angle) negative to get the AdvancingVelocity vector. Hope that helps. --Corbos

Yes, now I see that... Thanks. This means that I am looking at it correctly. It was still wrong on this page, though, as the last two pieces of the "angle" expression would need parens to be subtracing the absolute bearing. I'll go ahead and edit them here... -- Voidious

I believe I fixed the formula for relative heading, but I wouldn't mind somebody double checking it ;) (This page has been around a while...) -- Voidious

Robo Home | Segmentation | Changes | Preferences | AllPages