Looking to start a C# AI - Approaches? - Page 3

Looking to start a C# AI - Approaches?

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

Moderators: hoijui, Moderators

gajop
Moderator
Posts: 2984
Joined: 05 Aug 2009, 20:42

Re: Looking to start a C# AI - Approaches?

Post by gajop » 14 Feb 2012, 16:52

I didn't quite understand the priority2 idea, but as far as synchronization goes, it should be ok, since thread 1 is blocked when thread 2 is doing stuff.
1 x

User avatar
ivand
Posts: 103
Joined: 27 Jun 2007, 17:05

Re: Looking to start a C# AI - Approaches?

Post by ivand » 14 Feb 2012, 17:49

gajop wrote:I didn't quite understand the priority2 idea, but as far as synchronization goes, it should be ok, since thread 1 is blocked when thread 2 is doing stuff.
The idea is that Interface can survive AILib throwing errors, disconnecting and reconnecting to Interface multiple times.

When connection is missing (due to AI Lib Exception or just AI Lib being unloaded), each time handleEvent is fired, Interface checks if connections is present, and if it's not, tries to establish a session. This takes time (approximately 2 seconds).

The idea is to offload connection establishment loop to separate thread as when it's separate we don't care about this 2 seconds being lost in the default thread.

Yesterday night I built the prototype which runs three threads, one is default, one for client and one for server. It all works well, however I expect socket implementation is not thread safe as I'm getting errors inside sockets-related code sometimes. The problem could have been solved by mutex lock preceding every call to socket functions, however the server object in Apache Thrift is implemented as monolithic object, so it doesn't expose any event based callbacks or smth. One solution is to rewrite server code a little bit (thanks god it's open source), however I'm looking more into standard solutions. There should be ones available. Still checking options....
1 x

User avatar
hoijui
Former Engine Dev
Posts: 4342
Joined: 22 Sep 2007, 09:51

Re: Looking to start a C# AI - Approaches?

Post by hoijui » 14 Feb 2012, 18:13

maybe contact the Apache Thrift devs for that matter.
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 09 Apr 2012, 07:31

Glad to see there are others interested in C#

My first language was Java, but I self taught myself C# for work and now I like almost everything about it.

Unfortunately, I'm not familiar with AWK and C++ so I don't think I would be much use in helping write the interface.
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 05 Dec 2018, 19:22

Is there anyone still interested in C#?

I'm working on a Java AI but I keep finding myself wishing it was C#. The Thrift stuff sounded promising to me, but it's been six years now...

In the time since anyone has last discussed a C# AI, .NET Core has become available, meaning that some of the Linux/Mac concerns should go away, and it wouldn't have to rely on Mono to accomplish it. In my humble opinion, C# has evolved to add some great feature while Java has kinda stagnated.
1 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14436
Joined: 17 Nov 2005, 02:43

Re: Looking to start a C# AI - Approaches?

Post by Forboding Angel » 06 Dec 2018, 00:02

Honestly, AIs written in anything other than lua are kind of pariahs at this point. Gamedevs have zero control over non-lua AI, and those AI generally only work for a single game, if that. LuaAIs can be adapted and worked on after that author has long since abandoned them. A perfect example of this is BA and Evo's DAI. Originally Shard by AF, it was a non-luaai, however it used a lot of lua for behaviors. As a result, it ended up being converted by eronobos into a LuaAI. Because of that, Damgam, Doo and a few others were able to extend it and make it devilishly good.

Better yet, it is even more extensible easily, and will never stop working simply because it hasn't been compiled for the current engine version or any other silly reason. Gamedevs in general don't like non-lua AI, and for very good reason. It is impossible as a gamedev in spring to rely on a non-lua ai, because at any point, the author may abandon it, and you're left with your dick in your hand.

If it's for research project or just for the hell of it to learn, then by all means go ahead. However, I feel it's important that you know ahead of time that it is likely that no gamedev will really take a non-lua ai seriously. ESPECIALLY those who don't have their own distribution system, which knocks out basically everyone except Evo and ZK. But even those of us that do have our own pipeline likely can't be arsed to deal with the annoyance that is dealing with an AI that must be constantly maintained.

/wet blanket
Last edited by Forboding Angel on 06 Dec 2018, 16:32, edited 1 time in total.
1 x

User avatar
ivand
Posts: 103
Joined: 27 Jun 2007, 17:05

Re: Looking to start a C# AI - Approaches?

Post by ivand » 06 Dec 2018, 09:58

Forboding Angel wrote:
06 Dec 2018, 00:02
Honestly, AIs written in anything other than lua are kind of pariahs at this point.
I'm not sure this is a correct statement.
As far as the most popular Spring game, the most advanced AIs like Circuit, ZKGBAI or DeinFruend's AI were written in C++ and Java.
5 x

User avatar
Silentwings
Moderator
Posts: 3450
Joined: 25 Oct 2008, 00:23

Re: Looking to start a C# AI - Approaches?

Post by Silentwings » 06 Dec 2018, 11:23

I agree, non-lua AIs remain current - that said, I can't see why anyone would write an AI in C# when you have C++ already available.
1 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14436
Joined: 17 Nov 2005, 02:43

Re: Looking to start a C# AI - Approaches?

Post by Forboding Angel » 06 Dec 2018, 16:32

ESPECIALLY those who don't have their own distribution system, which knocks out basically everyone except Evo and ZK
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 06 Dec 2018, 18:59

Silentwings wrote:
06 Dec 2018, 11:23
I agree, non-lua AIs remain current - that said, I can't see why anyone would write an AI in C# when you have C++ already available.
Because that developer likes C# better, or doesn't know C++? Everyone has their language preferences.
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 06 Dec 2018, 19:08

Forboding Angel wrote:
06 Dec 2018, 00:02
Honestly, AIs written in anything other than lua are kind of pariahs at this point. Gamedevs have zero control over non-lua AI, and those AI generally only work for a single game, if that. LuaAIs can be adapted and worked on after that author has long since abandoned them. A perfect example of this is BA and Evo's DAI. Originally Shard by AF, it was a non-luaai, however it used a lot of lua for behaviors. As a result, it ended up being converted by eronobos into a LuaAI. Because of that, Damgam, Doo and a few others were able to extend it and make it devilishly good.

Better yet, it is even more extensible easily, and will never stop working simply because it hasn't been compiled for the current engine version or any other silly reason. Gamedevs in general don't like non-lua AI, and for very good reason. It is impossible as a gamedev in spring to rely on a non-lua ai, because at any point, the author may abandon it, and you're left with your dick in your hand.

If it's for research project or just for the hell of it to learn, then by all means go ahead. However, I feel it's important that you know ahead of time that it is likely that no gamedev will really take a non-lua ai seriously. ESPECIALLY those who don't have their own distribution system, which knocks out basically everyone except Evo and ZK. But even those of us that do have our own pipeline likely can't be arsed to deal with the annoyance that is dealing with an AI that must be constantly maintained.

/wet blanket
I'm not sure what you mean by "Gamedevs have zero control over non-lua AI". Do they have control over lua AI's? They can choose which AI ships with the game, but not every AI is meant to be shipped with the game. If I choose to write an AI in lua, or any other language, it can be abandoned. I don't see that as a reason to not attempt writing one in the first place. I don't care if gamedevs take my AI seriously or not. I do care that they provide an interface for the most popular languages, or have a simple and straightforward way of creating such an interface. By providing that, more people are going to be willing to attempt writing an AI. And the more people attempting such things, the more likely it is that we'll end up with some really good AI. The vast majority will get abandoned or be low quality, but a few shining gems will come out of it.

Personally I'm going to keep working on my Java AI, but I'll be looking for a way to create a C# interface. I was just hoping there might be some interest in the community for adding additional language support.
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 06 Dec 2018, 19:14

In web development, there's something called the OpenAPI Specification (formerly known as Swagger). It's a way of describing an API that makes it simple to generate a client for an API, in any language. There's code generators for all the popular languages, and it's not too difficult to directly consume an OpenAPI even if you don't use the generated code.

OpenAPI wouldn't work well for AI's. It's meant for HTTP REST based API's. But the general concept is sound. It sounds like Apache Thrift was a step in that direction, but then I didn't see any further discussion of it.

I guess what I'm proposing is that as a community we pick some sort of open way that would make it easy to add additional language support, and then we work towards that goal. I don't know all that needs to be done to accomplish this. My own knowledge of Spring internals is limited. But I'd love to help with this, even take the lead on it. I'll just need support from the community to accomplish it, and I want to get input so that this could be integrated into the engine when its ready.
1 x

User avatar
ivand
Posts: 103
Joined: 27 Jun 2007, 17:05

Re: Looking to start a C# AI - Approaches?

Post by ivand » 06 Dec 2018, 21:43

msm8bball wrote:
06 Dec 2018, 19:14
It sounds like Apache Thrift was a step in that direction, but then I didn't see any further discussion of it.

I guess what I'm proposing is that as a community we pick some sort of open way that would make it easy to add additional language support, and then we work towards that goal. I don't know all that needs to be done to accomplish this. My own knowledge of Spring internals is limited. But I'd love to help with this, even take the lead on it. I'll just need support from the community to accomplish it, and I want to get input so that this could be integrated into the engine when its ready.
I guess gRPC can serve as a bit more modern alternative to Thrift. At least at present time, most people opt to use gRPC rather that Thrift for reasons beyond my curiosity.

My work has never taken off from the point you can see in this thread and I guess no one really cared to revisit this idea for many years, excluding you. If you want to lead this, I hope no one would mind. The challenges should still be same:
1) Parse C++ AI Interface files to extract the methods and their parameters. I guess(?), awk scripts are still used to to automatically create the Java interface, so it should be possible to rework them. This step should generate .proto file, that would list all callins and callouts in the form of service definition.
2) Run gRPC compiler to produce the "server" C++ part. Next either awk or something else should fill in "server" methods with bindings to existing C++ AI interface from one side and with local socket connection on the other side.

If I'm not missing something (it's been a while since I last looked into this), this should do the trick. The client side in this case will be a standalone executable, that would open socket to C# interface binding from the other side.

That said, you need to think twice, because:
1) Standalone executable doesn't really fit into the distribution model. Even if it did, what would launch or terminate it?
2) I recall having issues with unidirectional nature of RPC helpers as they are modeled more or less after client-server model, not peer-to-peer as you would need in case of AI. gRPC seems to have something called bidirectional streaming, but I only skimmed over the definition and 0% sure it fits the task.
3) Make sure Kloot - the lead developer of spring engine nowadays - approves the inclusion of the interface that would do something like the above beforehand. Otherwise you risk wasting the great efforts you'd spend.

After re-thinking this task myself, I think, I'd rather spend time on doing something with existing interfaces. All-in-all modern C++ is not that fugly, and I'm guessing you can use some nicer language supported on JVM other than Java (which I understand you might not like). In the end the effort to do C# interface, especially in the form I envisioned years ago, is a big task of daunting complexity, perhaps your time could be spent better elsewhere.

P.S If you still feel brave, I suggest you work with some prototype first, don't attach it to spring yet: spring is somewhat complex to build, hard to debug, it loads relatively slow, etc. As a first step just take the C++ AI interface files and try to parse them into the .proto or .thrift file.
1 x

msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

Re: Looking to start a C# AI - Approaches?

Post by msm8bball » 06 Dec 2018, 22:44

ivand wrote:
06 Dec 2018, 21:43
msm8bball wrote:
06 Dec 2018, 19:14
It sounds like Apache Thrift was a step in that direction, but then I didn't see any further discussion of it.

I guess what I'm proposing is that as a community we pick some sort of open way that would make it easy to add additional language support, and then we work towards that goal. I don't know all that needs to be done to accomplish this. My own knowledge of Spring internals is limited. But I'd love to help with this, even take the lead on it. I'll just need support from the community to accomplish it, and I want to get input so that this could be integrated into the engine when its ready.
I guess gRPC can serve as a bit more modern alternative to Thrift. At least at present time, most people opt to use gRPC rather that Thrift for reasons beyond my curiosity.

My work has never taken off from the point you can see in this thread and I guess no one really cared to revisit this idea for many years, excluding you. If you want to lead this, I hope no one would mind. The challenges should still be same:
1) Parse C++ AI Interface files to extract the methods and their parameters. I guess(?), awk scripts are still used to to automatically create the Java interface, so it should be possible to rework them. This step should generate .proto file, that would list all callins and callouts in the form of service definition.
2) Run gRPC compiler to produce the "server" C++ part. Next either awk or something else should fill in "server" methods with bindings to existing C++ AI interface from one side and with local socket connection on the other side.

If I'm not missing something (it's been a while since I last looked into this), this should do the trick. The client side in this case will be a standalone executable, that would open socket to C# interface binding from the other side.

That said, you need to think twice, because:
1) Standalone executable doesn't really fit into the distribution model. Even if it did, what would launch or terminate it?
2) I recall having issues with unidirectional nature of RPC helpers as they are modeled more or less after client-server model, not peer-to-peer as you would need in case of AI. gRPC seems to have something called bidirectional streaming, but I only skimmed over the definition and 0% sure it fits the task.
3) Make sure Kloot - the lead developer of spring engine nowadays - approves the inclusion of the interface that would do something like the above beforehand. Otherwise you risk wasting the great efforts you'd spend.

After re-thinking this task myself, I think, I'd rather spend time on doing something with existing interfaces. All-in-all modern C++ is not that fugly, and I'm guessing you can use some nicer language supported on JVM other than Java (which I understand you might not like). In the end the effort to do C# interface, especially in the form I envisioned years ago, is a big task of daunting complexity, perhaps your time could be spent better elsewhere.

P.S If you still feel brave, I suggest you work with some prototype first, don't attach it to spring yet: spring is somewhat complex to build, hard to debug, it loads relatively slow, etc. As a first step just take the C++ AI interface files and try to parse them into the .proto or .thrift file.
Awesome, thanks for the update on where you left off at!

Yes, we'd need to have a standalone executable system, and the engine would have to be responsible for launching it and killing it when finished. I think it'd be up to the individual AI developer to ensure their executable doesn't crash, so the game engine won't have to monitor it or anything.

Good idea on a standalone prototype too. I'll have to put some more thought into this and I'm sure I'll have some questions, but I appreciate your input.

Yes, I considered using another JVM language, such as Scala. But I've been programming professionally with C#/.NET for years, and I really enjoy the language (even though I learned Java first). I'd like Spring to support .NET Core. It's fast, it's cross platform, C# is (objectively?) better and (IMHO) libraries are better. I personally don't have much experience with F#, but my understanding is it has a pretty strong following, so by supporting .NET Core, we by extension support F# and VB.NET (yuck!) too.

I'm actually undecided on whether to just add .NET Core interface, or implement Thrift/grpc/something else. Obviously it'd be better for the community if it was not just .NET Core.
1 x

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14436
Joined: 17 Nov 2005, 02:43

Re: Looking to start a C# AI - Approaches?

Post by Forboding Angel » 07 Dec 2018, 01:19

msm8bball wrote:
06 Dec 2018, 19:08
I'm not sure what you mean by "Gamedevs have zero control over non-lua AI". Do they have control over lua AI's? They can choose which AI ships with the game, but not every AI is meant to be shipped with the game. If I choose to write an AI in lua, or any other language, it can be abandoned.
Ok a lot to unpack there...

Yes, we have complete control over a luaai, because it is part of our game. If you make a non-luaai, then that ai likely has to be recompiled for every single version of the engine. This is incredibly messy from the perspective of distribution. You are thinking in terms of someone downloading springlobby and using spring from that angle, which is a bit unrealistic when it comes to distribution of a game. It's also a very subpar method of distribution.

If you write an ai in lua, then even if you leave, any other dev can add to it, update it and extend it. As an example, Shard->DAI and Evo+BA.

But hey, whatever floats your boat.
1 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 9964
Joined: 24 Jan 2006, 21:12

Re: Looking to start a C# AI - Approaches?

Post by PicassoCT » 11 Dec 2018, 22:46

Well, wasnt there a java AI Interface, that could be used as a bridge?

Hoiju did work on that.

Be aware, that while your AI can use unlimited ressources, the amount of orders it can issue per frame is limited.
1 x

Post Reply

Return to “AI”