Mirror Movement

From Robowiki
(Redirected from Mirror)
Jump to navigation Jump to search

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