You may find the following information useful. These are links to Sun's online Java tutorials.
Write a class that extends the EnemyBot class you wrote previously.
These steps are deliniated in such a way that you should be able to compile after each step to make sure your code is working properly.
Inside the AdvancedEnemyBot's update() method, please do the following:
double absBearingDeg = (robot.getHeading() + e.getBearing()); if (absBearingDeg < 0) absBearingDeg += 360;
// yes, you use the _sine_ to get the X value because 0 deg is North x = robot.getX() + Math.sin(Math.toRadians(absBearingDeg)) * e.getDistance();In a nutshell, this line computes the lentgh of the opposite side of a triangle (which may actually be negative in some cases), and then offsets it by our robot's X value.
// yes, you use the _cosine_ to get the Y value because 0 deg is North y = robot.getY() + Math.cos(Math.toRadians(absBearingDeg)) * e.getDistance();Similarly, this line computes the lentgh of the adjacent side of a triangle (which may actually be negative in some cases), and then offsets it by our robot's Y value.
return x + Math.sin(Math.toRadians(getHeading())) * getVelocity() * when;
return y + Math.cos(Math.toRadians(getHeading())) * getVelocity() * when;Note that getFutureX() and getFutureY() are much like the getX() and getY() above except that it uses Rate x Time (getVelocity() * when) instead of distance (e.getDistance())
Please look at the EnemyBot lab's Q & A for answers to this.
Make a robot that uses the AdvancedEnemyBot class you wrote and show me it running around the screen, tracking enemies and shooting at them. I imagine you'll want to look at Improved Targeting for some pointers on how to dow that.
The AdvancedEnemyBot.java file with your name, the lab # and the course # at the top of the page in comments. I do not need to see a printout of a robot that uses this class, but I _do_ want to see it running around the screen shooting (predictively) at other bots.
Yeah, probably.
Remember back in your math classes when you used to ask "When are we ever gonna use this stuff?" Well class, ask not for whom the bell tolls, your day has come. Be thankful that I'm giving you a ton of the code rather than making you figure it all out by yourself.
Technically, not a question, but I'll take it anyway. Answer: There is no fool-proof way to predictively target an opponent. There are too many variables at work (such as starting and stopping of the target bot) and no way to anticipate with 100% accuracy where your enemy will be. If you want to try to improve it, you're welcome to, but I want you to know right now that you won't be able to hit every time.
You may find that your robot is not predicting properly. He may be turning around the opposite way, not firing properly into a specific quadrant of the screen or something similar.
The most likely reason why this is happening is because you've used the wrong math operator someplace (i.e. you used a '*' when you should have used a '+' -- Alterhatively, you may have used an 'x' someplace when you should have used a 'y'.) Double-check the above instructions and make sure you've got the right code in the right place.
If, after checking, you're still having a devil of a time, don't worry about it too much. Next week I'll show you how to make a robot that prints output to a file. This will help you to troubleshoot your bot by getting a view of what's going on inside. For right now, you can use the out.println() to print some debug noise into your bot's output window.