passing data between RobocodeEngine and the robots

Skip to first unread message

Davide Cappellini

Feb 7, 2021, 2:47:02 PM2/7/21
to robocode
I was wondering if there's any method to pass data (primitives or not) from the engine to the sandboxed robots and vice versa other than writing the files to the disk.

I was thinking that a good way could be that the engine "offers" a globally shared data point that the bots can write in and the engine read from it.


Feb 7, 2021, 3:06:29 PM2/7/21
to robocode
Robots in Robocode are constrained in what they can access on purpose.
But they do have small storage of 200.000 bytes for writing and reading data. This is used for e.g. robots based on genetic programming where the genes are stored as a string.

But you might be able to use this storage for your purpose as well.
Robots store their data into a directory named if the class name of the robot is MyRobot in the 'robots' directory.
Try to run the sample bot sample.SittingDuck and check the /robots/sample/ directory.

You can use e.g. getDirectory() and getDataFile(filename) to get the File for the individual robot:

And you can write to the file using RobocodeFileOutputStream or RobocodeFileWriter, and read from it using regular input streams, e.g. FileReader (have a look at SittingDuck sample robot).

With this knowledge, it should be possible to write into the data directory with a file from the RobocodeEngine which the robots can read in.

Best regards,
- Flemming N. Larsen
Reply all
Reply to author
0 new messages