In my bot Parakeet, I store two arrays of floats instead of two arrays of doubles.. It cuts the filesize in half... I didn't need the precision of doubles anyway. --Dummy
Hrm ... what format do you save as Dummy? I just save as a text file currently. So Im not sure how saving as a float instead of a double will help in that circumstance! -- Wolfman
What are the limits of this file anyway? I was considering just serializing my Enemy objects, but I guess that's out of the question? -- PEZ
Serializing Enemy objects works, but if you find yourself running out of space, you can do better. You don't need to store things like last position, heading, velocity, etc. which are probably in your enemy class. What DuelistMini does is to store an array of doubles in a GZipOutputStream?. Remember that arrays are java Objects, so you can write an entire array by using:
myObjectOutputStream?.writeObject(myArray);
and read an entire array from an input stream by using:
myArray = (double[][]) myObjectInputStream?.readObject();
Parakeet saves one integer and two arrays per datafile (one datafile for each opponent it meets in 1-on-1. No data-storage in melee battles). The source of Parakeet is included in the .jar file on the RoboCodeRepository?. Actually, I looked in TheArtOfWar's source code to see how writing to files worked. Which reminds me... forgot to add credits in Parakeet's description and source. --Dummy
Object Streams consume a lot of space. Take a look inside a file written using ObjectOutputStream?. If I remember correctly, each field is identified by its name and type, as well as the field's value. The signatures of the object's methods might also be written to the file. On the other hand, these files should compress very well with Zip Streams.
If you are really want to reduce file size, you might want to look at Data Streams. Write only the fields you absolutely need. If you still need to reduce the file size, try cramming larger fields into smaller ones where possible (ie: double into int). Sure, you will lose some precision, but if file size is a real issue for you, you have to be willing to make some sacrifices.
TheArtOfWar's Bot class uses Data Streams, and the Reaction class crams two double fields (heading and speed) into two byte fields. The source is available at the RobocodeRepository. I should have used Zip Streams for further file size reduction, but I never got around to it -- Ray Vermette