简体   繁体   中英

Linear targeting in robocode

Can anyone explain me this code? i don't understand condition in the loop while and "predicted X". why predicted_X < 18 ? what does 18 mean?

while((++deltaTime)*BULLET_SPEED < 
        Point2D.Double.distance(myX, myY, predictedX, predictedY)) {
    predictedX += Math.sin(enemyHeading) * e.getVelocity();
    predictedY += Math.cos(enemyHeading) * e.getVelocity();
    enemyHeading += enemyHeadingChange;
    if(predictedX < 18.0 
            || predictedY < 18.0
            || predictedX > getBattleFieldWidth() - 18.0
            || predictedY > getBattleFieldHeight() - 18.0) {
        predictedX = Math.min(Math.max(18.0, predictedX), 
                getBattleFieldWidth() - 18.0);  
        predictedY = Math.min(Math.max(18.0, predictedY), 
                getBattleFieldHeight() - 18.0);
        break;
    }
}

The robot´s width is 36px so 18.0 is half of it. The condition just makes sure that your predictedX/Y isn´t outside of the battlefield

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM