Jump to content

Further AI development


Recommended Posts

As almost all game mechanics are in JS, switching to a different language is as plausible as writing a new engine. As you see, we have about just as much JS as C++ code: https://www.ohloh.net/p/game_0ad

We have multiple copies of JQuery and some JS libraries for tools which aren't directly part of the engine. Also there's a lot of duplicated code in the different AI APIs. This affects the comparision of the amount of C++ code vs. JS code. But I agree that switching would be way too much work, probably just to get the same issues again in a slightly different way.

Link to comment
Share on other sites

Well if you are going for a big donation push, now's the best time to seek these things, as some things might merit rewriting anyways. Also if enough new code needs to be rewritten vs just maintaining old stuff, the new code can be in the new language and the old stuff kept in the old. Even if something were rewritten, and in the short term the rewriting slowed things down, you may be glad you did it. It's like the US switching to metric, it's annoying, it's painful, but it's only going to get more difficult in the future. Better incremental changes now than a complete engine rewrite for the sequel.

Last I heard (about a year ago), much of 0ad's performance woes could be traced to the fact that it wasn't very parallel. Haskell provide very per formant lightweight (implicitly preemptive) concurrency http://benchmarksgame.alioth.debian.org/u32q/performance.php?test=threadring and unlike, let's say node.js, distributes those threads across multiple OS threads/cores. Additionally transaction memory, and/or immutability means deadlock and the other normal concurrency woes are out of the picture.

Rust also supports similar lightweight concurrency, though I am not sure if it's implementation is as mature. It doesn't support transaction memory for safe shared state, but also allows rigorous use of immutable data structures and additionally offers unique pointers / notions of ownership to tackle the same problem. Additionally it's probably easier to interface with the existing C++ code.

Javascript doesn't support parallelism, so there is little you can do to tackle that problem while staying with it. Even with existing code, I wouldn't say rewriting in C++ is going to be less painful than one of these languages, and without a good preemptive concurrency library you may still not reap all the performance benefits.

Link to comment
Share on other sites

Using Javascript inside C++ may not have been the best choice IMO. I mean, you are going to all this trouble for a JS compiler. Sure its JIT but, it may have just been better to use a compiled language in the first place.

It will be interesting to see if you eventually make it all the way using Javascript and still have top notch performance.

Link to comment
Share on other sites

Using Javascript inside C++ may not have been the best choice IMO. I mean, you are going to all this trouble for a JS compiler. Sure its JIT but, it may have just been better to use a compiled language in the first place.

It will be interesting to see if you eventually make it all the way using Javascript and still have top notch performance.

The nice thing about JavaScript is that it allows us to develop really fast, and since most of the game logic isn't performance-critical speed doesn't really matter. Some stuff that is in JS really shouldn't be though. For example, AIs do pathfinding in JS. :(

We can move performance-critical components to C++ pretty easily, so I really doubt our usage of JS is much of a performance issue.

You guys should consider something besides C++ and Javascript. Haskell, Rust maybe.

Ha! I thought I was the only one that thinks we should have used Haskell!

Link to comment
Share on other sites

Personally I am not sure what sort of development speed issues C++ has. I never felt like it was taking me a long time to add a new feature.

Never seen a dangling pointer, double free, heap corruption, memory leak or platform specific compiler error? Lucky you! :D

But this discussion isn't really productive, nobody is offering to write the AIs in a different language, and even if they could, without a solid design we would run into the same problems, and others that are more annoying to troubleshoot thanks to C++. If you think C++ is always "fast enough", take a look at our pathfinder. Bad algorithms give bad performance, it doesn't matter the language or the hardware involved

Because of JS garbage collection and the fact it's slower than native code, we know we shouldn't be processing a lot of data in JS. That's possible to solve, and we can still get the benefits of a.) new AIs and mods not requiring rebuilding the engine (even if you made them modular, in C++ they become unportable binaries), b.) possible AI script hotloading, change a script and it could instantly reflect the change in-game, c.) lower learning curve to begin developing AIs, if you have a text editor and basic programming knowledge you're ready to go and unlike C++, you don't worry about the machine the code will run on.

Based on contributions to 0 A.D. that I've seen over the years, people find JS (as a scripting language) more approachable and comfortable than C++, and that drives AI, random map, gameplay and UI development more than one guy who knows everything about C++.

  • Like 1
Link to comment
Share on other sites

Never seen a dangling pointer, double free, heap corruption, memory leak or platform specific compiler error? Lucky you! :D

To be perfectly honest, the first four are issues that a modern compiler can easily catch and doesn't hamper development. I've never seen a dangling pointer error without getting a crash beforehand, thanks to VC++ Debug Runtime.

The last issue though - platform specific errors - have been a bane of my existence for the last 2 months. Code that works on Windows, doesn't on OSX/Linux due to driver and compiler differences.

Link to comment
Share on other sites

I don't think you can write on in C++ now, so you have to do it in Javascript. However we're planning to move some things to C++ for performance, so there might be a day when this is possible.

OK, so if I were crazy enough to proceed with developing my own AI---which I assure you, I'm only considering because I don't want to mow the lawn---how would I turn off the fog of war to watch what the AI is doing?

Link to comment
Share on other sites

You could check that by activating the developer overlay (alt+d by default I think) and checking "reveal map".

As for the new AI, I've fixed an important bug regarding naval transport this week but have lacked time. I'll try to work on it more tomorrow, and try to commit it sometimes next week. We'll see.

  • Like 1
Link to comment
Share on other sites

If you plan to to change the scripting language, please please consider Lua prior of any other language. It's the preferred one of the game industry for these type of things*, and for good reasons. Also, it's very efficient and easy to integrate with C++ (enough to copy the sources in a directory of the project). It is used mainly for AI scripting, but it can be used for anything. Of course it's open source (MIT license).

* The list of games that use Lua is quite big, including a pair of the more recent Total Wars, Civilization V, SimCity 4, Crysis and World of Warcraft, to name a few. It's also used in well-known open source games.

  • Like 1
Link to comment
Share on other sites

Us Haskellers are slowly becoming more prevalent!

I admit to snickering a bit while they talked about dangling pointers and whatnot up there.... :D

This week released a new AI, why did not it? :unknw: :unknw: :unknw:

Because it's not finished. :P Expect it in the next few weeks/month, I guess. Ideally we'd like to have it in for Alpha 15.

gameboy, developing an AI this complicated is hard work. I think you underestimate how much effort is involved in something like this, especially since the underlying APIs are still changing while we experiment to try to find something that works well and quickly.

I'd say the current AI works well enough though, at least for the time being. I haven't encountered any particularly weird issues with it in Alpha 14 (although I don't play the AI much any more).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...