The Spring Interface

The Spring Interface

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
Horazont
Posts: 4
Joined: 26 Apr 2010, 19:06

The Spring Interface

Post by Horazont »

Hi all,

Well, I'm new. You'll see that I guess, but I thought I should mention it anyways ;).

I used Spring for some time to play now, and I got curious about developing an AI for it. Not that I would have much (or any) experience about writing AIs, but I thought, I would just try and see what happens in the end (and I will force nobody to play against it ;)).

Now, I was wondering which interface to use? Assuming that I use a C-compatible language (that is actually FreePascal, but they're all turing complete, so it does not really matter), just wanting to say that I do not use Lua or Java, which interface would I use? I read something about GlobalAI and found stuff about it in the sourcecode and I have had a short look in the RAI and found the SSkirmishAICallback.h-Interface.

Is GlobalAI already usable? Is there any better interface for object oriented languages than SSkirmishAICallback.h?

by the way  While playing around with a quick port of SSkirmishAICallback.h, I found that for some fields the assigned functions differ (used gdb to find that out after some ominous crashes). Any information on that?

greetings
Last edited by Horazont on 23 May 2010, 02:32, edited 1 time in total.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: The Spring Interface

Post by AF »

RAI etc use the legacy API that prevents us from loosing all the old AIs when we switched to the new APIs.

I would recommend if you are using C++ to use the new C++ API. If you go to my website, you can see an empty AI set up to build with Visual Studio 2008 which uses this API. Copy paste change the names and start coding your AI.

The C++ API itself is built on top of the C API so you can use the C API functions in it.

You can find the blogpost as well as details on how to set it up and start coding here
Horazont
Posts: 4
Joined: 26 Apr 2010, 19:06

Re: The Spring Interface

Post by Horazont »

Thanks for the link. I just had a short look into it, trying to trace which interface you actually use to communicate with the engine, and it seems to be SSkirmishAICallback.h again, am I right? Which is, what, from what I have seen, is used by RAI too So your code is "just" a wrapper around the original interface.
Or am I mixing things up here?

greetings
ps: Nice fast response, I like that :)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: The Spring Interface

Post by AF »

RAI uses the legacy API which is again a wrapper around the C API. The same si true fo the C++ API.

The difference being that the legacy API implements what the C API replaced, an old old interface originally added years ago, that has all sorts of limitations and problems.

The new Object oriented C++ API is another wrapper around the C API, which is much nicer to use. The C API itself is somewhat unwieldy with long function names and lots of parameters.
WeberGunso
Posts: 11
Joined: 15 Sep 2009, 11:08

Re: The Spring Interface

Post by WeberGunso »

Hmmm,

What about using a far easier Interface... a potential Python one?

Some time ago I talked to hoijui about building a Python Interface. Took me some time to understand what should be done to get the thought down to reality. Well my first approach was Interfacing with Cython. Turned out to be quite a hassle at the point of externalizing the AICallback instance.

Yesterday I started the same idea, but this time with a different and much friendlier approach... Boost.Python (libboost-python). Since the Engine already makes use of the libboost libs, I figure its easier to get requirements (at first optional) of an additional boostlib upstream.

====================================================
Now the entire idea has a few pros and contras:
Pros:
1) Python is a extremely powerful language. The coderatio C/C++:Python is about 10:1 to achieve the same goal. And its just sweet/powerful.

2) In case of performance bottlenecks you can always extend Python with C++ libs (libboost-python) or even direct C code (Cython). It is done very fast and easily. If you do it cleverly you might even only use Python as Algorithm prototyping and glue for different objects without having the type handling/converting overhead bashing at your performance.

3) You will be running 1 Interpreter to get the Interface and subsequent SkirmishAI running... through spawning of further Interpreters (multiprocessing lib as of py2.6) you have a easy multi-core support up and running. Even useful in case you want to use the SpringRTS Engine for AI research purposes, just plug your private renderfarm behind it ;)

4) I intend to bring in also some source code from EVE online (Yep, written in Stackless Python), which makes possible to develop your AI on the fly. It works with a testing cycle (syntax and other errors), and on passing the test, plugging in of the freshly edited module. Spring in windowed mode, and you see the changes realtime.

5) No compile times... the worst of all drawbacks on developing something that relies heavily on prototyping like AIs

6) A little more Shugar: take a look at the self enabling approach of "Metaprogramming" (note the quotes) in Python... its just beyond of cool. You don't use Python, you feel Python... I've become a fan of this language since I came into contact with it mere 4 months ago.


Contras:
1) Additional Language in an already 3 Language Environment. We already have C/C++, then comes Lua as scripting language and there is also Java involved in the JavaAI Interface. It is a good thing to support everything, but it also makes things one step messier and more heterogeneous.

2) Performance of pure Python is not known as the best out there, don't worry, its quite performant though (Im currently using it mainstream at a research project revolving around 3d voxel clouds of laser scanners... lots of 3D data). For someone who uses Python as a tool of prototyping or similar purposes, being a capable C/C++ developer, this is THE honeypot (without the trap behind). As of Python3k with the upstream coming UnladenSwallow from Google, it should get serious performance improvements (the most important of improvements is the newly implemented JiT capability). Furthermore there is PyPy coming within the next 3-8 Years, which is a serious hack... want to see it in action, should be closely as fast as C by then. Not really sure if performance is something to be mentioned here at the Contras... but well for sake of completeness.

3) Someone might be asking himself... well we already have a Java Interface and the JVM is known to support Jython... why the pure Python. To be honest, I don't know, what I know is that the wont fully support the PSL (Python Standard Library) before Py3k, and that could take another year or two. And the other aspect that in my opinion has always killed Java for me is the JVM... it behaves like garbage. As a linuxler I know one thing for sure... if you have a PC or Server, the last thing you want on it is anything that needs the JRE, mainly because of the JRE and not of the package. Same with Mono from MS. If one of mentioned VM's would close just ONCE cleanly... it would be great. Big difference is the PVM, at least I haven't experienced a problem even once.
====================================================

This post has 3 objectives:
1) Want to hear about the "Go to Hell's" or "Cool's" from side of the Engine devs, and the potential AI devs out there.

2) Want to know if I'm not running into already occupied territory.

3) Suggestions and Ideas, Wishes and the like (Actually the most important of the 3)

I'm going to do this either way, mainly because I want to play around with AI's myself. Clearly the better if this gets upstream.

Would the Developers think this could get a ticket upstream... ^^!?

If anyone wants to contribute, please say so.
---------
~WeberGunso
~WeberShogun
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: The Spring Interface

Post by hoijui »

hey! :-)
please do not start with the Python interface. there is one nearly finished already by now. But i let the two guys that work on it tell you the details. You may want to join the #ai channel in the lobby.

It was quite some effort to make the AI Interface plugin-able as it is now, and when the system is setup nicely (i think we are quite close to that by now) there should be no drawback with additional languages/plugins.

future interfaces (eg. also the Python one) will be added as git submodules, referenced in the spring main repo. They have to conform to some standards (CMake build file, leaving the source tree clean during build, fail gracefully if dependencies are not found, allow for exclusion from build, support windows and linux (and possibly others i forgot right now)). If they do, and some testing looks promising, the submodule will be referenced, and the authors of the submodule and spring devs will need commit access to it. We will have to see how this is handled exactly, maybe with a fork of the repo on the spring account.

For me, the technical reasons for an other language are not so important. The most important thing is, that there are a lot of (potential) AI devs, with Python as their preferred language.
slogic
AI Developer
Posts: 626
Joined: 17 Mar 2008, 19:03

Re: The Spring Interface

Post by slogic »

WeberGunso wrote:2) Want to know if I'm not running into already occupied territory.
Um, i don't know have you seen this: http://springrts.com/wiki/AIWrapper:PyAI
It is a Python wrapper over C interface. Going further by links i knew it is still in active development. Last commit was done 20 hours ago.
Post Reply

Return to “AI”