Difference between revisions of "Mirror Movement"

From Robowiki
Jump to navigation Jump to search
m
(Rewrite page)
 
(One intermediate revision by one other user not shown)
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 [[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]].
  
It is particularly more problematic to face such robots for robots which have strong movement.
+
Implementing mirror movement requires [[One on One Radar|a decent radar lock]].
 +
 
 +
The current state-of-art mirror is '''[[PolishedRuby]]'''.
 +
 
 +
== 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:
 +
 
 +
<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>
 +
 
 +
The enemy coordinates must then be transformed, before being passed to the <tt>goTo()</tt> function. The transformation depends on the type of mirroring:
 +
 
 +
; 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>
 +
 
 +
== Perpendicular Mirror Movement ==
 +
This type of movement will circle the enemy, by turning perpendicular to it and moving at roughly the same velocity.
 +
 
 +
<syntaxhighlight lang="java">
 +
public void onScannedRobot(ScannedRobotEvent e) {
 +
    setTurnRightRadians(Math.cos(e.getBearingRadians()));
 +
    setAhead(4 * e.getVelocity());
 +
}
 +
</syntaxhighlight>
 +
 
 +
== See Also ==
 +
* [[oldwiki:MirrorMovement|Mirror Movement on the old RoboWiki]]
  
{{stub}}
 
 
[[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.

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());
}

See Also