Multiple battles headless?

46 views
Skip to first unread message

Andrew Perrott

unread,
Jan 23, 2021, 4:50:05 PM1/23/21
to robocode

Hi all, I'm writing a genetic algorithm to build me some robots, and to test them it runs a command like:

`./robocode.sh -battle settings.battle -nodisplay -results roundResults.txt`

for each robot it generates. It's running this for a lot of robots, so the overhead of starting up the application each time takes quite a while.

Is there a way to run multiple battles in one go, or 'hold on' to a single instance of the application that I can call each time for a battle without a display?

In case it matters, I'm running it on ubuntu using Python's subprocess module to fire off the command.

Thanks!

fnl

unread,
Jan 24, 2021, 3:26:26 PM1/24/21
to robocode
You should have a look at the Robocode Control classes, i.e. the RobocodeEngine.

Here is a link to an example. Make sure to click the "Package" on the header and scroll down to see the example of how to use the RobocodeEngine class:
https://robocode.sourceforge.io/docs/robocode/index.html?robocode/control/RobocodeEngine.html

Cheers,
- Flemming

Andrew Perrott

unread,
Jan 25, 2021, 2:28:31 PM1/25/21
to robocode
Just what I wanted, thanks! It will be a bit awkward hooking it up with what I've got already but it will definitely be faster.

On a similar note, do you know if it's safe to run multiple instances of the engine at the same time, or are there resources that can't be shared concurrently?

Thanks again!

fnl

unread,
Jan 25, 2021, 2:32:23 PM1/25/21
to robocode
I have not tried to run multiple instances of the RobocodeEngine within the same application.
So I don't know if it will work, but it should be easy for you to try out.

Regarding accessing resources concurrently, it should not be a problem as long as the robot instance does not write it's data to the same file as another robot instance.

You might also try to run the RobocodeEngine from multiple processes e.g. from a shell/batch script or similar.

Cheers,
- Flemming

Andrew Perrott

unread,
Jan 29, 2021, 2:01:16 PM1/29/21
to robocode
Thought I would follow up on this in case people were interested in the results.

Yes, running multiple instances worked fine. I wrote a small java class that would sequentially run a selection of robots in battles via RobocodeEngine and report results, and my python script would call this a bunch of times in parallel (using asyncio) with a different 'chunk' of robots and wait for them all to finish. Each process was surprisingly consistent with how long it took.

Doing it this way still had an overhead for each time it spun up the Robocode engine(s) so there were diminishing returns for adding threads (assuming a fixed gene pool/chunk size). Writing the whole thing in java and holding onto the Robocode instances is probably the way to go for maximum robots tested per hour.

Still, I got massive performance improvements from this so I would recommend doing this if you're making a genetic algorithm or something similar.

Once again, thanks for the help!

fnl

unread,
Jan 29, 2021, 5:03:34 PM1/29/21
to robocode
Thank you for the follow-up. It is nice to know that it is possible to run multiple instances of the RobocodeEngine without causing issues other than the expected overhead. :-)
This is valuable information for other people that is interested in this information in the future.

Best regards,
- Flemming
Reply all
Reply to author
Forward
0 new messages