You may find the following information useful. These are links to Sun's online Java tutorials.
Write (or modify an existing) bot that prints information about the robot it's tracking to a file. It should also output predictive targeting information to help you debug it.
You will probably want to modify an existing bot that you've written to date, rather than start over from scratch. The notes in this lab make this assumption.
f = NumberFormat.getNumberInstance();
File file = getDataFile("output.dat");
Note #1: Do not re-declare a local 'ps' var inside run(), it will create oodles of problems.
Note #2: You will need to handle the exception that could be thrown when constructing the new PrintStream by using a try..catch statement.
ps.println("Tracking: " + enemy.getName() + " at (x,y) (" + f.format(enemy.getX()) + ", " + f.format(enemy.getY()) + ")");
if (ps != null) ps.close();
Here's an example of the kind of output I'm looking for. You might output a little bit more or a little bit less, but I'm expecting something along these lines.
Tracking: sample.Fire at (x,y) (384.1, 53.2) firePower = 2.1, bulletSpeed = 13.7, time = 13 futureX = 384.1, futureY = 53.2, absDeg = 97.3, turn = 2.4 Tracking: sample.Fire at (x,y) (384.1, 53.2) firePower = 2.1, bulletSpeed = 13.7, time = 13 futureX = 384.1, futureY = 53.2, absDeg = 99.7, turn = 2.4 Tracking: sample.Fire at (x,y) (384.1, 53.2) firePower = 2.1, bulletSpeed = 13.7, time = 13 futureX = 384.1, futureY = 53.2, absDeg = 102.1, turn = 2.4 Tracking: sample.RamFire at (x,y) (181.4, 197) firePower = 3, bulletSpeed = 11, time = 9 futureX = 181.4, futureY = 197, absDeg = 344.2, turn = -117.9 Tracking: sample.RamFire at (x,y) (181.4, 197) firePower = 3, bulletSpeed = 11, time = 9 futureX = 181.4, futureY = 197, absDeg = 341, turn = -97.1 ...
AdvancedRobot for sure. The Robot class does not let you write to an output file.
Are you importing all the right packages? You'll need these two to get the file IO and NumberFormat classes respectively:
import java.io.*; import java.text.NumberFormat;
Put it in the c:\robocode\robots\[initials] directory with your other robots.
You do need to print it up and give me a copy, though.
In the c:\robocode\robots\[initials]\[robotname].data directory.
No one is making you use it, but here's what the output looks like if you don't:
Tracking: sample.TrackFire at (x,y) (559.5203855902, 254.8100637962) firePower = 3, bulletSpeed = 11, time = 6 futureX = 559.5203855902, futureY = 254.8100637962, absDeg = 308.3014154079, turn = 3.1290191007
Given the choice, I think you might prefer something more like:
Tracking: sample.Fire at (x,y) (384.1, 53.2) firePower = 2, bulletSpeed = 14, time = 14 futureX = 384.1, futureY = 53.2, absDeg = 79.8, turn = -1.5
Of course, be my guest. The whole point here is to show you guys how you can dump debug noise to a file for postmortem analysis.
Show me your robot running around the screen and bring up his output in a text editor.
A printout of the code for the outputting robot with your name, the course number (etc.) at the top of the page in comments.
You have discovered a bug in the 1.4.2 JDK. There was a bug report posted to Sun and they've issued the following workaround: just start the JVM with this command-line parameter: -Dsun.io.useCanonCaches=false. IOW, start Robocode like so:
java -Dsun.io.useCanonCaches=false -Xmx256M -jar robocode.jar
That will fix the problem and you will be able to run your OutputBot without it constantly throwing those exceptions.
To fix this once and for good, edit the robocode.bat (or robocode.sh file on Linux) and make sure it looks like the line above.
Credit where it's due: I found this solution on the Robocode Repository right here.