Difference between revisions of "Mirror Movement"
(Major edit.) |
(Rewrite page) |
||
Line 1: | Line 1: | ||
− | '''Mirror Movement''' is a form of [[ | + | '''Mirror Movement''' is a form of [[1v1]] movement that tries to imitate 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:AntiMirrorSystem|anti-mirror targeting]]. |
− | + | Implementing mirror movement requires [[One on One Radar|a decent radar lock]]. | |
− | + | The current state-of-art mirror is '''[[PolishedRuby]]'''. | |
− | |||
− | == | + | == Coordinate Mirror Movement == |
− | This | + | This style of mirror movement tries to move to a point "opposite" the opponent. It requires a [[GoTo]] method, such as this one: |
− | + | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="java"> |
− | + | private void goTo(double x, double y) { | |
− | + | /* Transform our coordinates into a vector */ | |
− | + | x -= getX(); | |
+ | y -= getY(); | ||
+ | |||
+ | /* Calculate the angle to the target position */ | ||
+ | double angleToTarget = Math.atan2(x, y); | ||
+ | |||
+ | /* Calculate the turn required get there */ | ||
+ | double targetAngle = Utils.normalRelativeAngle(angleToTarget - getHeadingRadians()); | ||
+ | |||
+ | /* | ||
+ | * The Java Hypot method is a quick way of getting the length | ||
+ | * of a vector. Which in this case is also the distance between | ||
+ | * our robot and the target location. | ||
+ | */ | ||
+ | double distance = Math.hypot(x, y); | ||
+ | |||
+ | /* This is a simple method of performing set front as back */ | ||
+ | double turnAngle = Math.atan(Math.tan(targetAngle)); | ||
+ | setTurnRightRadians(turnAngle); | ||
+ | if(targetAngle == turnAngle) { | ||
+ | setAhead(distance); | ||
+ | } else { | ||
+ | setBack(distance); | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | It also requires calculating the coordinates of the enemy robot: | ||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
+ | public void onScannedRobot(ScannedRobotEvent e) { | ||
+ | double enemyX = getX() + e.getDistance() * Math.sin(getHeadingRadians() + e.getBearingRadians()); | ||
+ | double enemyY = getY() + e.getDistance() * Math.cos(getHeadingRadians() + e.getBearingRadians()); | ||
+ | |||
+ | // TODO | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | The enemy coordinates must then be transformed, before being passed to the <tt>goTo()</tt> function. The transformation depends on the type of mirroring: |
− | This | + | |
− | <syntaxhighlight> | + | ; Vertical line-reflection |
− | + | : <syntaxhighlight lang="java">goTo(getBattleFieldWidth() - enemyX, enemyY);</syntaxhighlight> | |
− | + | ||
− | + | ; Horizontal line-reflection | |
− | + | : <syntaxhighlight lang="java">goTo(enemyX, getBattleFieldHeight() - enemyY);</syntaxhighlight> | |
+ | |||
+ | ; Point-reflection over the battlefield center | ||
+ | : <syntaxhighlight lang="java">goTo(getBattleFieldWidth() - enemyX, getBattleFieldHeight() - enemyY);</syntaxhighlight> | ||
+ | |||
+ | == Relative Mirror Movement == | ||
+ | This type of movement attempts to imitate the opponent's movement (same direction and same velocity), starting at the bot's current location. For instance, if the enemy moves upward 100 units, your bot will also move upward 100 units. Not very effective against most guns, and '''must''' be combined with [[Wall Smoothing]] for any level of usefulness. | ||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
+ | public void onScannedRobot(ScannedRobotEvent e) { | ||
+ | setTurnRight(Utils.normalRelativeAngleDegrees(e.getHeading() - getHeading())); | ||
+ | setMaxVelocity(Math.abs(e.getVelocity())); | ||
+ | setAhead(Double.POSITIVE_INFINITY * e.getVelocity()); | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | == Perpendicular Mirror Movement == |
− | This | + | This type of movement will circle the enemy, by turning perpendicular to it and moving at roughly the same velocity. |
− | + | <syntaxhighlight lang="java"> | |
− | <syntaxhighlight> | + | public void onScannedRobot(ScannedRobotEvent e) { |
− | + | setTurnRightRadians(Math.cos(e.getBearingRadians())); | |
− | + | setAhead(4 * e.getVelocity()); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== See Also == | == See Also == | ||
− | * [[oldwiki:MirrorMovement]] | + | * [[oldwiki:MirrorMovement|Mirror Movement on the old RoboWiki]] |
+ | |||
[[Category:Terminology]] | [[Category:Terminology]] | ||
[[Category:Movement]] | [[Category:Movement]] |
Latest revision as of 22:11, 28 August 2017
Mirror Movement is a form of 1v1 movement that tries to imitate 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 anti-mirror targeting.
Implementing mirror movement requires a decent radar lock.
The current state-of-art mirror is PolishedRuby.
Contents
Coordinate Mirror Movement
This style of mirror movement tries to move to a point "opposite" the opponent. It requires a GoTo method, such as this one:
private void goTo(double x, double y) {
/* Transform our coordinates into a vector */
x -= getX();
y -= getY();
/* Calculate the angle to the target position */
double angleToTarget = Math.atan2(x, y);
/* Calculate the turn required get there */
double targetAngle = Utils.normalRelativeAngle(angleToTarget - getHeadingRadians());
/*
* The Java Hypot method is a quick way of getting the length
* of a vector. Which in this case is also the distance between
* our robot and the target location.
*/
double distance = Math.hypot(x, y);
/* This is a simple method of performing set front as back */
double turnAngle = Math.atan(Math.tan(targetAngle));
setTurnRightRadians(turnAngle);
if(targetAngle == turnAngle) {
setAhead(distance);
} else {
setBack(distance);
}
}
It also requires calculating the coordinates of the enemy robot:
public void onScannedRobot(ScannedRobotEvent e) {
double enemyX = getX() + e.getDistance() * Math.sin(getHeadingRadians() + e.getBearingRadians());
double enemyY = getY() + e.getDistance() * Math.cos(getHeadingRadians() + e.getBearingRadians());
// TODO
}
The enemy coordinates must then be transformed, before being passed to the goTo() function. The transformation depends on the type of mirroring:
- Vertical line-reflection
goTo(getBattleFieldWidth() - enemyX, enemyY);
- Horizontal line-reflection
goTo(enemyX, getBattleFieldHeight() - enemyY);
- Point-reflection over the battlefield center
goTo(getBattleFieldWidth() - enemyX, getBattleFieldHeight() - enemyY);
Relative Mirror Movement
This type of movement attempts to imitate the opponent's movement (same direction and same velocity), starting at the bot's current location. For instance, if the enemy moves upward 100 units, your bot will also move upward 100 units. Not very effective against most guns, and must be combined with Wall Smoothing for any level of usefulness.
public void onScannedRobot(ScannedRobotEvent e) {
setTurnRight(Utils.normalRelativeAngleDegrees(e.getHeading() - getHeading()));
setMaxVelocity(Math.abs(e.getVelocity()));
setAhead(Double.POSITIVE_INFINITY * e.getVelocity());
}
Perpendicular Mirror Movement
This type of movement will circle the enemy, by turning perpendicular to it and moving at roughly the same velocity.
public void onScannedRobot(ScannedRobotEvent e) {
setTurnRightRadians(Math.cos(e.getBearingRadians()));
setAhead(4 * e.getVelocity());
}