Mono AI interface

Mono AI interface

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

Moderators: hoijui, Moderators

User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Mono AI interface

Post by Agon »

MonoAIInterface

Description:
MonoAIInterface provides the possibility to write and use CLI*1 compatible AIs.
A list*2 of possible languages is available at the mono homepage.

License (Not yet decided):
MonoInterface: LGPL
CSharp wrapper code: MIT-License/LGPL/BSD

Status:
  • MonoInterface(80%)-needs testing, docs, minor tweaks
  • C# wrapper code(90%) - needs testing
  • CMake integration (50%) - C# related files are missing
  • CMake mono module (70%) - Works only under Linux
  • MonoNullAI (100%) - works
  • MSAI (MonoSampleAI) (25%)
  • Wiki pages (~20%)
  • Documentation (~15%)
  • Tutorials (0%)
Folder structure:
AI/Interfaces/MonoInterface/
-->Provides an AI interface for CLI AIs
AI/Wrappers/CSharp/
-->Wrapper code written in C#, AI developer who want to program there AIs in a CLI*2 compatible language should use this code.

Extra software required for using and developing CLI AIs:
Mono >2.0.1 (2.0 should work, too but it has some bugs)
GLib2 (Mono dependency)
Extra software required for building:
Mono-devel >2.0.1 (2.0 should work, too but it has some bugs)
GLib2-devel (Mono dependency)

*1: http://en.wikipedia.org/wiki/Common_Lan ... astructure
*2: http://www.mono-project.com/Languages
Last edited by Agon on 22 Feb 2009, 14:44, edited 3 times in total.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

The MonoInterface can now load the MonoNullAI without any Problem.
(MonoNullAI is a CLI AI which implements handleEvent and returns 0. It is similar to the NullAI)

Code from MonoNullAI:

Code: Select all

using System;

static class MonoNullAI
{		
	public static int handleEvent (int teamId, int topic, object data)
	{
		return 0;
	}
}
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Mono AI interface

Post by imbaczek »

mighty cool! how's with windows support on that?
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

Windoz support will be a bit difficult.
For Windoz I need to adjust the FINDMono.cmake file to find mono.
GLib2 needs to be installed.
And for the mono.dll a mono.lib needs to be generated.

I have no working Windoz currently due new hardware.
I will install a new Windoz after openSUSE 11.1 is released because I want to clean my computer.

Next step is to get SAICallback working means I need to create a list of runtime function registration with AWK.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

Due problems with native to managed pointers I was rewriting half of the code.
While I did this I found out (with the help of hoijui) that it is impossible to use C++ pointer for C pointer.
So I had to rewrite the complete handling of native to managed functions in C.
Due to this I decided to move from C++ to C because C is faster and Mono expects char*'s not std::string's and the conversion from (const) char*/std::string was to much for me.

At the end I rewrite the complete MonoInterface in C.
Half of it is done.
Error/warning/info handling is missing and native to managed calling.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

A little status update.

I worked on the C part of the Interface until I faced a problem yet unknown.
Calling Mono api functions in the init event of SAILibrary crashes spring. But if I call it in the init or loadSAILibrary function of the interface it works.
The init where the crash happens is past to the SAILibrary struct in loadSAILibrary as a function pointer. I don't know if it happens because of a thread issue (dead locked resources, but I call a mono function "mono_thread_attach" which should fix it if it is a thread issue) or due the possibility that mono can not be used in function pointers. Where are 6 threads running at the time of the crash.
2 SDL threads doing nanosleep();
2 MonoVM threads, one doing a *_wait() and one poll()
1 OpenAL I think nanosleep();
1 Spring thread where the error happens.
Maybe someone has an idea :S
I will try some tactics to figure out what is wrong.
- Writing a program which loads the MonoVM through a function pointer
- And a test program for testing the thread issue possibility.

At the moment my PC is not working because I installed and uninstalled various packages which caused some trouble to the GUI :S.
I wanted to setup my PC new anyway.
Until it is setup I will write some awk script to generate a C# wrapper....

And the windows support needs to wait until the Linux version works basically.
The windows support will also be more difficulty.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

Hoijui does not think it has something to do with a function pointer.
And he is probably right, it should not matter for the MonoVM.

So I will write a test application which starts the MonoVM in a second thread.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

After long time I finally finished the basics of the MonoAIInterface.

At the moment it should load any CLI compiled .dll with a runtime version 1.0 or 2.0.

I have a problem with handleEvent which is called more than 30 times a second which I think triggers this exceptions after a few seconds:
SIGPWR (Power fail/restart)
and then
SIGXCPU (CPU time limit exceeded)
repeats again after a few seconds.
But it does not crash spring. I can press okay and continue.

On the managed side I run this command:
Console.WriteLine("TeamID: " + teamId + " Topic: " + topic);
This will be written to the console on each handleEvent call.
Means more than 30 times per second.

From the mono project side:
"SIGPWR, SIGXCPU: these are used internally by the GC and pthreads."

Maybe someone can help with this problem.

Edit:
wikipedia:
On some operating systems, the Boehm garbage collector uses SIGXCPU and SIGPWR to synchronise cross-thread garbage collection.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Mono AI interface

Post by imbaczek »

no idea, maybe you need to provide signal handlers and pass them to mono?
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

Can't find something like this in the documentation.
And in an article it says:
Currently Mono does not provide a mechanism for signal chaining, but one might be available in the future, see Bug #75990 (http://bugzilla.ximian.com/show_bug.cgi?id=75990) for information on the current status of this feature.
As I understand this mono does not support handling signals and I did a quick look at the source and it has a internal function which handles signals but not the two I mentioned.

I will see how I can bypass them.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

I asked on gimpnet #monodev about the problem.
And the answer was:
Add this lines to ~/.gdbinit

Code: Select all

handle SIG33 nostop noprint
handle SIGPWR nostop noprint
handle SIGXCPU nostop noprint
So the problem was with gdb which consumed the signals and stopped, printed them.

Oh and it is no performance problem...
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

I have written a CLIWrapperCodeGenerator in C#.
The wrapper can produce C#, VisualBasic and JScript code and works with AISEvents.h at the moment.

Edit:
Also Boo language support added.

Edit02:
Added IronPython support. Looks kinda silly :mrgreen:
Example

Code: Select all

 # 
    #  This AI event is sent once per game frame, which is about 30 times per second
    #  by default.
    # 
    class SUpdateEvent(object):
        """type(frame) == System.Int32"""
        __slots__ = ['frame']
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

The MonoAIInterface is nearly finished thanks to very much help from hoijui and some people from #monodev on gimpnet.
What is left:
Documentation, optimize (free memory/ better algorithm) and some more options in the lua file.
And of course some testing...

At the moment I'm searching for a good license which does not bite GPL and has a copyleft.
So far LGPL seems the best...
But feel free to suggest a better license.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Mono AI interface

Post by imbaczek »

LGPL should be fine.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

imbaczek wrote:LGPL should be fine.
Yeah, I will use LGPL.
What is the difference between 2.1 and 3.0?

My little C to CodeDom wrapper can now successful wrap AISCommands , AISEvents and can output any CLI language which provides a CodeDomProvider.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

The interface is nearly done.
Some cmake commands to compile/generate C# code is left and windows support.

And of course some testings....
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Mono AI interface

Post by Licho »

Regarding SIGPWR and SIGXCPU - I run into yet unresolved problems with mono GC in spring downloader tracker. GC was freezing whole program and was spamming those signals. It was more likely with many threads and asynchronous IO operations.
Other large scale mono projects suffer from it too - for example for hosting ASP.NET aplication under mono, its recommended to restart apache module every few hours :)

If you can, let it run over .NET on windows?
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

If you use gdb you can disable them in the gdb config file.
The two signals mean that a cross (platform) thread actions happens (something like this), wikipedia has the answer.
You can ignore them.

Btw. I lost two month of work due a hard drive hardware problem.
I will maybe restart this after the summer.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Mono AI interface

Post by imbaczek »

offtopic: i don't know how many times i've seen this "hard drive problem lost ages of work". always always always make backups of important stuff!
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Re: Mono AI interface

Post by Agon »

imbaczek wrote:offtopic: i don't know how many times i've seen this "hard drive problem lost ages of work". always always always make backups of important stuff!
I did, that is the reason why I lost "only" two months.

I blame Auswaschbar for this, he did not allow me to commit my stuff :twisted:
(joking, I should have uploaded it to github, by myself)
But I wanted to rewrite it anyway, it was hacked together.
Post Reply

Return to “AI”