Difference between revisions of "Mirror Movement"

From Robowiki
Jump to navigation Jump to search
m
(Major edit.)
Line 1: Line 1:
A type of movement that copys the movement of the enemy, like looking in the mirror. One of the simplest types of movement to implement, it is used by many robots.
+
'''Mirror Movement''' is a form of [[One on One|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 [[oldwiki:AntiMirrorGun|antimirror targeting]].
  
It is particularly more problematic to face such robots for robots which have strong movement.
+
There are several styles of mirror movement, ranging from very simple perpendicular mirror movement to the more complex coordinate mirror movement.
  
{{stub}}
+
== Implementations ==
 +
Here are some code examples of mirror movement.  For them to work properly, a decent [[One on One Radar|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.
 +
<syntaxhighlight>
 +
//Put this code in the onScannedRobot area of your robot.
 +
setTurnRightRadians(Math.cos(e.getBearingRadians()));
 +
setAhead(4 * e.getVelocity());
 +
</syntaxhighlight>
 +
 
 +
=== Angular Mirror Movement ===
 +
This just tries to move in the same direction and at the same speed as the enemy.
 +
<syntaxhighlight>
 +
//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()));
 +
</syntaxhighlight>
 +
 
 +
=== 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.
 +
<syntaxhighlight>
 +
//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);
 +
</syntaxhighlight>
 +
 
 +
== See Also ==
 +
* [[oldwiki:MirrorMovement]]
 
[[Category:Terminology]]
 
[[Category:Terminology]]
 
[[Category:Movement]]
 
[[Category:Movement]]

Revision as of 20:47, 31 December 2012

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