Mirror Movement

From Robowiki
Revision as of 20:47, 31 December 2012 by Sheldor (talk | contribs) (Major edit.)
Jump to navigation Jump to search

Mirror Movement is a form of 1v1 movement that tries to copy the movement of the enemy. Though it can be effective against opponents with strong movement, it is utterly useless against opponents with weak movement or antimirror targeting.

There are several styles of mirror movement, ranging from very simple perpendicular mirror movement to the more complex coordinate mirror movement.

Implementations

Here are some code examples of mirror movement. For them to work properly, a decent radar lock is required.

Perpendicular Mirror Movement

This is among the simplest and smallest of all movements, though it isn't very effective. This will turn perpendicular to the enemy and move at roughly the same velocity.

//Put this code in the onScannedRobot area of your robot.
setTurnRightRadians(Math.cos(e.getBearingRadians()));
setAhead(4 * e.getVelocity());

Angular Mirror Movement

This just tries to move in the same direction and at the same speed as the enemy.

//Put this code in the onScannedRobot area of your robot.
setTurnRightRadians(Utils.normalRelativeAngle(e.getHeadingRadians() - getHeadingRadians()));
setAhead(e.getVelocity() * 1000);
setMaxVelocity(Math.abs(e.getVelocity()));

Coordinate Mirror Movement

This style tries to move symmetrically to a point on the battlefield, usually the center. For example, if the enemy were retreating from the center, then so would the mirror bot(as opposed to angular mirror movement, which would advance toward the enemy).

The following code is from mn.micro.perceptual.Mimic 1.0.0.

//Put this code in the onScannedRobot area of your robot.
final double headOnBearing = event.getBearingRadians() + getHeadingRadians();
final double destinationDistanceX = getBattleFieldWidth() - sin(headOnBearing) * event.getDistance() - getX() * 2;
final double destinationDistanceY = getBattleFieldHeight() - cos(headOnBearing) * event.getDistance() - getY() * 2;
double destinationDistance = sqrt(destinationDistanceX * destinationDistanceX + destinationDistanceY * destinationDistanceY);
destinationDistance = destinationDistance > 0.001 ? destinationDistance : 0;
double turn = (destinationDistance > 0 ? atan2(destinationDistanceX, destinationDistanceY) : event.getHeadingRadians()) - getHeadingRadians();
double ahead = POSITIVE_INFINITY;
if (cos(turn) < 0) {
    turn -= PI;
    ahead = NEGATIVE_INFINITY;
}
setTurnRightRadians(normalRelativeAngle(turn));
setAhead(ahead);
setMaxVelocity(destinationDistance);

See Also