Robocode Tank Royale - Python?

91 views
Skip to first unread message

Sarb

unread,
Sep 24, 2024, 12:00:54 PM9/24/24
to Robocode
Apologies if this question has already been asked.

I am interested in developing bots in Python. It appears this may be possible with Robocode Tank Royale. How would I go about building a Python bot API? Any pointers or guidance would be greatly appreciated.

Refs:

fnl

unread,
Sep 24, 2024, 12:22:22 PM9/24/24
to Robocode
Hi Sarb,

Currently, there are two official bot APIs for Robocode Tank Royale:

Java platform: https://github.com/robocode-dev/tank-royale/tree/main/bot-api/java
.Net platformhttps://github.com/robocode-dev/tank-royale/tree/main/bot-api/dotnet

And at some point I will introduce an API for web as well.

If you want to build an API from scratch, you could choose to:
1) Create an API very similar to the current APIs that are made very similar on purpose. Meaning that your Python API would have same classes and methods, but in Python style of course.
2) Create your own version and just use communicate with the server in a more "raw" fashion by communicating over a WebSocket.

If you choose option 2, you need to send and receive messages using the protocol described here:
https://github.com/robocode-dev/tank-royale/blob/main/schema/schemas/game/README.md

And the schemas (message formats) are available here (In JsonSchema format)
https://github.com/robocode-dev/tank-royale/tree/main/schema/schemas/game

If you choose option 1, you should create something similar to BaseBot as a first step (like I did), which handles the basic communication between a bot and the server.
Later you can create a Bot with more advanced methods as step 2.

Also note that you could use the existing APIs as is. For example, we have Jython, which is a Python implementation for the existing Java Bot API.
And you could use Python.Net for with the existing .Net Bot API.

I you want to do a real Python API that are similar to the existing one, I will be happy to assist you. 👍
I guess most code from the existing platforms can be translated without a big hassle for Python. I did the same for Java to .Net, and I will do it again later for the coming web API. 😊

Best regards,
- Flemming

fnl

unread,
Sep 24, 2024, 12:24:59 PM9/24/24
to Robocode
Correction:
Jython is a Python implementation for Java, which can be used for the the existing Java Bot API for Robocode Tank Royale.

Sarb

unread,
Sep 25, 2024, 2:01:50 PM9/25/24
to Robocode
Thank you Flemming.
This looks very interesting! Let me read up.
Regards,
Sarb

Davide Cappellini

unread,
Sep 29, 2024, 4:48:34 AM9/29/24
to Robocode
Hi Sarb

If you are interest in taking the longer path, building your own API in python, I wrote a specific page for your case: https://github.com/robocode-dev/tank-royale/wiki/Tutorial-on-writing-a-Bot-API-for-Tank-Royale

Sarb

unread,
Sep 30, 2024, 6:34:44 PM9/30/24
to Robocode
Hello Flemming,
Perhaps you can help with a follow-up question. To help, I'd like to share some background of my use case.
I am using Robocode to explore AI. Namely RL and Neural Nets. To expedite training, in the classic Robocode, I rely heavily upon the feature whereby minimizing the UI greatly speeds up the simulation and hence data collection. Now I could have missed it, but is something similar possible in Royale? If so, I expect the simulation bottleneck would now be speed of websocket traffic right?

BTW. My motivation for programming the bots in Python is of course to enable use of existing libraries such as PyTorch & Tensorflow.
Thank you,
Sarb

On Tuesday 24 September 2024 at 09:24:59 UTC-7 fnl wrote:

Sarb

unread,
Sep 30, 2024, 6:34:50 PM9/30/24
to Robocode
Thank you Davide.
Sarb

fnl

unread,
Sep 30, 2024, 6:54:49 PM9/30/24
to Robocode
You can set the turn timeout in microseconds (us) for each game type. This is possible from the GUI from the menu: Battle -> Setup Rules. The default turn timeout is set to 30.000 microseconds = 30 ms
Or it can be set manually in the games.properties file, e.g. as `1v1.turnTimeout=30000

You are right that the network traffic and also WebSocket implementation at the server and client (bot) side introduce some latency.

You can also create your own Observer that subscribe to events from the server, which you record. This way you can train your AI based on the recorded data without taking turn timeout and network latency into account.

Cheers,
- Flemming
Reply all
Reply to author
Forward
0 new messages