View topic - Mono AI interface



All times are UTC + 1 hour


Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Mono AI interface
PostPosted: 16 Nov 2008, 15:38 
User avatar

Joined: 16 May 2007, 17:33
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_Language_Infrastructure
*2: http://www.mono-project.com/Languages


Last edited by Agon on 22 Feb 2009, 14:44, edited 3 times in total.

Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 20 Nov 2008, 20:47 
User avatar

Joined: 16 May 2007, 17:33
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:
using System;

static class MonoNullAI
{      
   public static int handleEvent (int teamId, int topic, object data)
   {
      return 0;
   }
}


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 20 Nov 2008, 22:23 
Moderator

Joined: 22 Aug 2006, 15:19
mighty cool! how's with windows support on that?


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 20 Nov 2008, 23:06 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 22 Nov 2008, 20:39 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 12 Dec 2008, 20:47 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 12 Dec 2008, 21:55 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Jan 2009, 15:44 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Jan 2009, 15:53 
Moderator

Joined: 22 Aug 2006, 15:19
no idea, maybe you need to provide signal handlers and pass them to mono?


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Jan 2009, 18:22 
User avatar

Joined: 16 May 2007, 17:33
Can't find something like this in the documentation.
And in an article it says:
Quote:
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 31 Jan 2009, 16:40 
User avatar

Joined: 16 May 2007, 17:33
I asked on gimpnet #monodev about the problem.
And the answer was:
Add this lines to ~/.gdbinit
Code:
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...


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 31 Jan 2009, 22:25 
User avatar

Joined: 16 May 2007, 17:33
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:
 #
    #  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']


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 03 Feb 2009, 22:22 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 03 Feb 2009, 22:35 
Moderator

Joined: 22 Aug 2006, 15:19
LGPL should be fine.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 10 Feb 2009, 21:48 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 22 Feb 2009, 14:47 
User avatar

Joined: 16 May 2007, 17:33
The interface is nearly done.
Some cmake commands to compile/generate C# code is left and windows support.

And of course some testings....


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Mar 2009, 17:16 
Server Owner & Developer
User avatar

Joined: 19 May 2006, 18:13
Location: Brno, Czech rep., EU, Terra, Sol, Orion arm, Milky way, Virgo supercluster
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?


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Mar 2009, 20:14 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Mar 2009, 20:16 
Moderator

Joined: 22 Aug 2006, 15:19
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!


Top
 Offline Profile  
 
 Post subject: Re: Mono AI interface
PostPosted: 25 Mar 2009, 20:18 
User avatar

Joined: 16 May 2007, 17:33
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.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.