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: 3051
Joined: 05 Aug 2009, 20:42

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

Post by gajop »

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.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

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

Post by ivand »

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....
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

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

Post by hoijui »

maybe contact the Apache Thrift devs for that matter.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

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

Post by Forboding Angel »

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.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

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

Post by ivand »

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.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

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

Post by Silentwings »

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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

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

Post by Forboding Angel »

ESPECIALLY those who don't have their own distribution system, which knocks out basically everyone except Evo and ZK
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

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

Post by ivand »

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.
msm8bball
Posts: 52
Joined: 09 Oct 2009, 08:08

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

Post by msm8bball »

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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

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

Post by Forboding Angel »

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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

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

Post by PicassoCT »

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.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

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

Post by Anarchid »

Lua AI's are horrible for any serious AI project.

- They very often will cheat inadvertently; it takes huge effort to make them not cheat
- They run in sync on every machine, and will lag the game for everyone, not just their host
- They run in Lua, which means that you can't use any fancy libraries that arent' available in pure Lua. Have fun reimplementing neural nets and voronoi from scratch!
- No multithreading (except Lua coroutines, lol)

The Java interface works quite well, so does the C++.

It would be cool to have a C# interface.
User avatar
ThinkSome
Posts: 387
Joined: 14 Jun 2015, 13:36

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

Post by ThinkSome »

That is cool, but engine AIs simply crash the engine and newbies really love that.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

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

Post by Anarchid »

That is cool, but engine AIs simply crash the engine and newbies really love that.
Incorrect.

At least the Java AI's crash themselves and then sit around braindead without segfaulting the game. Neither are LuaAI's guaranteed to not crash the game, historically quite a lot of crash bugs were accessible through the synced lua api.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

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

Post by AF »

NTai didn't crash the engine, it handled that situation. Most native AIs crash the engine deliberatley for ideological reasons.

There are some fundamental problems here:

1: Native AIs regardless of their language have no insight into the internals of games that use lua rule, there's only 2 windows into the lua rules world
1a: Sending custom commands where you know in advance what the parameters and IDs are and they're simple
1b: Sending arbitrary messages in the form of strings via the API, but few games listen for or expose their mechanics by default, you'll need to discuss them with these developers
2: Native AIs and the API are in a holding pattern, there's no new development on the engine side, just fixes when things break in tests
3: The docs for the C API and how its generated are not great, and in most cases nonexistent
4: Most of what you can do without including libraries or multithreading can be done in lua, and is already done in lua. You don't need fancy ML or analysis libraries or threading to build a decent RTS AI for the games in this community, it just takes a little smarts. People building games here have their specialties, but they're either not professional programmers, or they do that in their jobs and want to do other stuff
Post Reply

Return to “AI”