Write your Group AI in Python!
Moderators: hoijui, Moderators
Write your Group AI in Python!
I've written a Python wrapper for the Spring group AI interface. You can use this to write group AIs in Python, which might be easier than writing them in C++. The webpage has source code, a Windows DLL, and some example AIs (mostly ported from the C++ group AIs).
http://www.jwhitham.org.uk/pyai/
This is the first version, so there are bound to be rough edges. However I have been playing using it, and it seems stable. If you have any comments, please post them below. Thanks!
http://www.jwhitham.org.uk/pyai/
This is the first version, so there are bound to be rough edges. However I have been playing using it, and it seems stable. If you have any comments, please post them below. Thanks!
-
- Posts: 665
- Joined: 06 Jun 2006, 19:49
Yes - PyAI would work far better if it was possible to do this. Would the devs accept a patch from myself?jcnossen wrote:Nice work, only the spring restriction of 1 AI per DLL is now a drawback... Ideally someone would write a patch to have more than 1 AI per DLL
True: SWIG is a really useful tool. All it takes is a bit of glue code, and possibly some extra wrappers for some functions to make them behave in the way that the users of the scripting language expect. I started this process for Python, but there are still some things that could be improved.jcnossen wrote:This also allows others to easily make wrappers of other scripting languages, because SWIG supports quite a lot of them (C#, perl, ruby, tcl...)
- Michilus_nimbus
- Posts: 634
- Joined: 19 Nov 2004, 20:38
That's possible, but I don't know much about Lua myself. SWIG is able to generate Lua - have a look at http://www.swig.org/ to see what it can do. Basically it produces proxy classes to represent C++ classes in the language of your choice, which is ideal for auto-generating an interface between your favourite scripting language and C++. The PyAI source might be useful if you are doing this, in particular 'spring.i' which contains instructions for SWIG, and 'prepare.py' which calls SWIG and processes the results.AF wrote:Can this be used for lua? It'd be a godsend if you set it up for that, as it would take out a huge chunk of XE10 work and allow me to change a heck of a lot very quickly and allow a huge feature explosion
Provided the patch is of sufficient quality, I'm pretty sure we do.Jack wrote:Yes - PyAI would work far better if it was possible to do this. Would the devs accept a patch from myself?jcnossen wrote:Nice work, only the spring restriction of 1 AI per DLL is now a drawback... Ideally someone would write a patch to have more than 1 AI per DLL
-
- Posts: 665
- Joined: 06 Jun 2006, 19:49
I dont get the point, that compiles into ,exe's, what we have here is a library/ aka .so/.dll in c/c++ with an attatched scripting language, only I dont see how the language is getting attatched or what its even getting attatched to, just that he's used SWIG. I see no linkage between IGroupAI::InitAI() or CommandFinished() calls from the engine and the python equivilants, I cant even find the functions that initialize the whole thing and pass it back to the engine.
Look at the JNI documentation.
You could use SWIG too.
Write an itnerface class in java but instead fo defining the functions just write
public static native return_type function_name(params);
Then once the class is done, pass it through the javah and it'll generate a c/c++ header.
For the most part this is easy as the data types jint, jchar, jfloat, jdouble etc are all exactly the same as the standard c/c++ data types, the only conversions and issues come with JString and structures/objects.
Another issue is where they use stuff like void* to pass over information, and I havent figured out what the java equivilant is yet and howto translate between them two.
You could use SWIG too.
Write an itnerface class in java but instead fo defining the functions just write
public static native return_type function_name(params);
Then once the class is done, pass it through the javah and it'll generate a c/c++ header.
For the most part this is easy as the data types jint, jchar, jfloat, jdouble etc are all exactly the same as the standard c/c++ data types, the only conversions and issues come with JString and structures/objects.
Another issue is where they use stuff like void* to pass over information, and I havent figured out what the java equivilant is yet and howto translate between them two.
Unfortunately this won't work. I thought about doing this, and investigated it, but Py2exe isn't able to embed the Python interpreter in a DLL: it can only generate EXE files. So you do have to install Python - sorry!hollowsoul wrote:http://www.py2exe.org/
That's in gluecpp, which gets #included by the SWIG code. The reason for doing this, rather than compiling gluecpp separately, is that I needed access to certain SWIG functions in order to get the C++ pointer for a Python object. The reason for not calling gluecpp something more sensible, like 'glue.cpp', is that scons will then attempt to build it separately (any suggestions of better ways to organise this are welcome). Hope this helps.AF wrote:I took a look at the source and found it to be a seething mass of confusion, I cant even find the exported functions the engine calls to get the name of the groupAI and the copy of IGroupAI.