Creating non-Java AIs

162 views
Skip to first unread message

Santiago Ontanon

unread,
Jun 4, 2017, 12:19:55 PM6/4/17
to microRTS
I just added functionality to the core classes of the game to develop AIs that communicate with the game via a socket (see some quick explanation at the bottom of this page: https://github.com/santiontanon/microrts/wiki/Code-Guide). This means that AIs can now be created in Python, C++ or any other language. Communication for now can be set to use JSON or XML (for communicating game states and actions back and forth). But this can also be used to run multiple AIs in different machines even if it's all Java.

I hope this is useful!

Darren Williams

unread,
Jan 31, 2018, 12:38:17 AM1/31/18
to microRTS
Hello Santi and forum members,

We're currently looking into creating a remote AI in python using sockets and have a couple questions.

- Has anyone already done this, so we could kindly leverage their good work and/or experience or just ask some questions?
- We are currently communicating using JSON (haven't tried XML yet). After a while of running GameClient.java we get a stacktrace that appears the socket has a malformed json object which could be buffer related: json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1457 (char 1456). Has anyone come across this kind of problem or have any advice?

Thanks for your help in advance.
Regards,
Darren

Santiago Ontanon

unread,
Jan 31, 2018, 12:42:28 AM1/31/18
to microRTS
Hi Darren,

Yes, two of my students are actually using this Socket class to connect to external languages (including Python). I will ask them to come here and see if they know what might be happening. But I recall that something like this happened to both of them initially, so probably they have a fix :)

Santiago Ontanon

unread,
Jan 31, 2018, 10:05:48 AM1/31/18
to microRTS
I just committed a fix suggested by one of my students. Let us know if that fixes it! :) (basically, the JSON server sends a welcome message, which sometimes causes troubles if the AI is not ready to receive it). Otherwise, we can look deeper into it :)

Darren Williams

unread,
Jan 31, 2018, 5:50:17 PM1/31/18
to microRTS
Thank you for your prompt reply. Will update our code and get back to you shortly.

Regards,
Darren

Darren Williams

unread,
Feb 19, 2018, 11:31:18 PM2/19/18
to microRTS
Thanks Santiago for the update. We're moving forward.

Thanks,
Darren

Santiago Ontanon

unread,
Feb 19, 2018, 11:36:09 PM2/19/18
to Darren Williams, microRTS
Great! Any other issues you guys find, by all means let me know! :)

--
You received this message because you are subscribed to the Google Groups "microRTS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microrts+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microrts/c2f86603-df90-4b69-b9cf-439a21bfbf79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Carey

unread,
Feb 21, 2018, 12:18:48 AM2/21/18
to microRTS
Hey Santiago,

I have some questions in regards to the upcoming tournament.

1) How are we expected to host our agents? (Locally or hosted in the cloud).
2) Are there any constraints if we hosted locally? (Python version, ect)
3) Is there a way to signify to the agent that a match has ended?

Santiago Ontanon

unread,
Feb 21, 2018, 2:36:01 PM2/21/18
to microRTS
Hi Scott,

1) Last year I ran everything locally. So, participants submitted their bots and I set everything up in a few local machines to run all the games.
2) There is a lot of flexibility there. The machine I plan to use is going to be dedicated to this, so, I can install anything that is needed. The one thing is that it currently does not have a GPU (waiting for NVidia to have those GTXs back on stock, but not sure when will that happen!). I am planning to run everything on Ubuntu, but I can install any Python version that is required by your bot. If I don't get GPUs on time and you need them, I will need to come up with a plan B
3) Right now the game does not send any notification about that. But if that is something that would make your life easier, I can easily add a "gameOver" function to the AI class, and a corresponding message to the SocketAI class

Santiago Ontanon

unread,
Feb 27, 2018, 12:02:44 AM2/27/18
to microRTS
In case it is useful, I added the "gameOver" function to the AI class, and a corresponding message to the SocketAI class. Now the AI will receive a message "gameOver [winner]" with who won a game at the very end.

David Cotton

unread,
Mar 26, 2018, 12:53:56 AM3/26/18
to microRTS
Hi Santiago and everyone,

I'm looking into creating non-Java AI using Python and just wanted to check I'm on the right path. 

I'm running RunServerExample.java as a server and I've built a Python client inspired by RunClientExample.java that connects via a TCP socket. What has got me puzzled with the client/server examples included with microRTS is that most of the game configuration comes from the client. The client provides the player AIs, the map and runs the main game loop. This has resulted in me duplicating a lot of the game functionality in Python and makes me think I'm probably doing it wrong. 

I'd love to hear if someone has a better way of running non-Java AIs. 

Thanks,
Dave

Santiago Ontanon

unread,
Mar 26, 2018, 11:36:46 AM3/26/18
to microRTS
I know exactly what you mean. The problem of creating a non-Java AI via sockets is that, in the remote language (e.g., Python) you don't have access to all the functionality of the Java core classes like GameState, Unit, etc. One of my students has the same problem and he had to reimplement a lot of the core microRTS functionality on the Python side as well. It would be easy to extend the network protocol to allow the remote language to "ask" queries to the Java side, but I'm scared that the network communication overhead would make the AI too slow.

But this is the first year that people is starting to use the SocketAI seriously, so, all of these issues are surfacing. I am totally open to suggestions to improve it, or to add any functionality that could make your life easier! (or even to try alternative approaches to the socket idea such as Jython, etc.).

santi

David Cotton

unread,
Mar 26, 2018, 5:53:20 PM3/26/18
to microRTS
Thanks a lot for getting back to me so quickly Santi. 

It's reassuring to know that I'm not going down the wrong the path and that others have run into similar issues. 

I'm currently exploring both the Python re-implementation method and extending the Java server class to reduce the functionality needed on the Python side. I'll see which method works better for me and I'll share back with the group my thoughts and if possible a gist or pull request. 

Cheers,
Dave
Reply all
Reply to author
Forward
0 new messages