Advertisement
FKNyak

AdvancedEnemyBot

May 27th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. package JCJH;
  2.  
  3. import robocode.Robot;
  4. import robocode.ScannedRobotEvent;
  5.  
  6.  
  7. /**
  8.  * Record the advanced state of an enemy bot.
  9.  *
  10.  * @author Justin Chang
  11.  * @version 5/11/17
  12.  *
  13.  * @author Period - 5
  14.  * @author Assignment - AdvancedEnemyBot
  15.  *
  16.  * @author Sources - none
  17.  */
  18. public class AdvancedEnemyBot extends EnemyBot
  19. {
  20.     private double x;
  21.  
  22.     private double y;
  23.  
  24.  
  25.     /**
  26.      *
  27.      * Get's x.
  28.      *
  29.      * @return x value
  30.      */
  31.     public double getX()
  32.     {
  33.         return x;
  34.     }
  35.  
  36.  
  37.     /**
  38.      *
  39.      * Get's y.
  40.      *
  41.      * @return y value
  42.      */
  43.     public double getY()
  44.     {
  45.         return y;
  46.     }
  47.  
  48.  
  49.     /**
  50.      * Resets values.
  51.      */
  52.     public void reset()
  53.     {
  54.         super.reset();
  55.         x = 0.0;
  56.         y = 0.0;
  57.     }
  58.  
  59.  
  60.     /**
  61.      * Resets values.
  62.      */
  63.     public AdvancedEnemyBot()
  64.     {
  65.         reset();
  66.     }
  67.  
  68.  
  69.     /**
  70.      *
  71.      * Updates values.
  72.      *
  73.      * @param e
  74.      *            Scanned attributes
  75.      * @param robot
  76.      *            The robot.
  77.      */
  78.     public void update( ScannedRobotEvent e, Robot robot )
  79.     {
  80.         super.update( e );
  81.         double absBearingDeg = ( robot.getHeading() + e.getBearing() );
  82.         if ( absBearingDeg < 0 )
  83.         {
  84.             absBearingDeg += 360;
  85.         }
  86.  
  87.         x = robot.getX()
  88.             + Math.sin( Math.toRadians( absBearingDeg ) ) * e.getDistance();
  89.         y = robot.getY()
  90.             + Math.cos( Math.toRadians( absBearingDeg ) ) * e.getDistance();
  91.  
  92.     }
  93.  
  94.  
  95.     /**
  96.      *
  97.      * Predicted x.
  98.      *
  99.      * @param when
  100.      *            Time
  101.      * @return Predicted x
  102.      */
  103.     public double getFutureX( long when )
  104.     {
  105.         return x
  106.             + Math.sin( Math.toRadians( getHeading() ) ) * getVelocity() * when;
  107.     }
  108.  
  109.  
  110.     /**
  111.      *
  112.      * Predicted y.
  113.      *
  114.      * @param when
  115.      *            Time
  116.      * @return Predicted y
  117.      */
  118.     public double getFutureY( long when )
  119.     {
  120.         return y
  121.             + Math.cos( Math.toRadians( getHeading() ) ) * getVelocity() * when;
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement