Sign in to follow this  
LeventeZs

RTS AI workbench

Recommended Posts

LeventeZs    100
I'm working on an RTS workbench tool, that is: minimalist graphics, 2D world, units have hitpoints, attack points, range, speed (these are the default attributes). The intended use is to extend the basic unit class, and override the behaviours/game rules you don't like (default rules mimic a run of the mill RTS). So you can concentrate on experimenting both with unit level ai and player level ai.

It's all in really infant phase (0.1), there's no documentation besides some Javadoc (hands-on no getting started guide). But I have some code that runs, and it might give some idea where I'm heading.

I also plan to build in some tools for evolutionary algorithms (yeah, I know, sounds ambitious), so you write a player's code, define a sequence of evolutionary attributes and their range, and the in some points in your Player code you read those attributes. The framework will "breed" the player and mutate (e.g. simulated annealing), and cull the population (different specimens of "Player strategies" fighting against each other). I know, there are already projects like this out there, but they ...
1, have weird rules and not resemble regular RTS
2, use C/C++ (I think that's too level language to progam an AI in)
3, are tied to proprietary game (e.g. Starcraft)
4, only provide a server and not an IDE like environment where you experiment, aggregate and visualize data

I'd like to hear suggestions/feature requests from you, or just comforting cheering :)

The project is BSD licensed, however I'm not recruiting contributors, so if you like what you find feel free to fork. I'd like to get my planned features and documentation get done till October/November. (My schedule has been quite hectic in the last 1.5 months).

The project is hosted on Sourceforge and is humbly called [url="https://sourceforge.net/projects/infinite-wisdom/"]Infinite Wisdom.[/url]

Share this post


Link to post
Share on other sites
ApochPiQ    23063
I wouldn't write AI in Java unless I had a gun to my head.

Of course, I wouldn't write [i]anything[/i] in Java without similar extenuating circumstances, so take that for what it's worth.


The idea has potential, but has a few critical shortfalls from my perspective:
[list][*]Java. Nobody writes high-end RTS games in Java. You need at the very least to build a scripting framework that can drop into a C/C++ engine if you want anyone to take this seriously.[/list]
[list][*]Too much emphasis on evolutionary algorithms. This might be a fun diversionary project for some research, but it isn't how real AI is developed. Real AI in the RTS space is generally heavily focused on things like utility maximization and build order scripting. Some of the more complex issues are things like path planning for masses of units (think Zerglings in Starcraft II) and those aren't going to be solved by GAs any time soon.[/list]
[list][*]You don't seem to account for the fact that every RTS is going to have a very different set of rules. What made Total Annihilation a great game was vastly different from what made Dune 2 a great game, or Warcraft, or Command and Conquer. Those rules and design decisions shape the AI far more than code ever will. What you really need here is more like an end-to-end toolkit for designing and implementing an RTS; ability to define and implement rule sets for resources, unit and building production, movement controls (think air/sea/land), and so on. There's also a horde of small details to consider, like units that can dock to each other/inside each other (transports), how buildings and static defenses might affect gameplay, units that can transform between various states (e.g. siege tanks), and so on.[/list]

I like the concept in principle, so don't take this as anything more than constructive criticism; in fact I think it'd be cool to have a prototyping tool for RTS games that worked very similarly to what you seem to be envisioning. But to make it really kick-ass, I'd suggest shifting focus a bit: build a scripting or other high-level data driven system that lets a designer prototype an entire game from start to finish (sans graphics, sound effects, whatnot) and see how it actually plays. Build in rich support for AI scripts written in, say, Python or Lua, and provide a set of hooks for built-in stuff like a pathfinder and so on.

What you could end up with is a great tool for designers of RTS games to sit down and hammer out all the rules for their game first and foremost, then have AI engineers rough out the gameplay logic for the computer players, and then ideally just copy/paste their scripts into a C/C++ framework that integrates into custom rendering engines and so forth. You could bootstrap an entire game like StarCraft in a matter of days with such a toolkit, and I think it would be truly cool to have something like that available.

Do it right, and you might even get guys in the AAA industry space using your tool for prototyping.

Massive bonus points for including a rudimentary network code implementation that can be used for playtesting PvP combat...

Share this post


Link to post
Share on other sites
DvDmanDT    1941
[quote name='ApochPiQ' timestamp='1307312970' post='4819882']
... Build in rich support for AI scripts written in, say, Python or Lua, and provide a set of hooks for built-in stuff like a pathfinder and so on. ...

What you could end up with is a great tool for designers of RTS games to sit down and hammer out all the rules for their game first and foremost, then have AI engineers rough out the gameplay logic for the computer players, and then ideally just copy/paste their scripts into a C/C++ framework that integrates into custom rendering engines and so forth. You could bootstrap an entire game like StarCraft in a matter of days with such a toolkit, and I think it would be truly cool to have something like that available.

... Massive bonus points for including a rudimentary network code implementation that can be used for playtesting PvP combat...
[/quote]

Last two weeks I've been working on an RTS game written in C# using Xna. It's a slightly simplified Age of Empires clone right now with almost no content, but it does feature about 75% of all low level game elements of a such game. I was about to implement the (high-level) AI interface today actually, as the game currently features only PvP multiplayer battles for 2-4 players. Since I'm using .NET, AI modules can potentially be written in any .NET language such as VB.NET or JScript, but my initial release will feature just C# and IronPython support.

While the game is an AoE clone, the engine was designed to be extremely flexible in most areas. I could probably create a 'Civilization' that would play almost like a StarCraft race already using Python scripted civilizations. I could drop in any Xna-compatible rendering engine as long as it supports rendering to texture and/or rendering to a specific viewport.

My goal is however different from this project in that I'm trying to create a fun game.

Share this post


Link to post
Share on other sites
LeventeZs    100
[quote name='ApochPiQ' timestamp='1307312970' post='4819882']
[list][*]Too much emphasis on evolutionary algorithms. This might be a fun diversionary project for some research, but it isn't how real AI is developed. Real AI in the RTS space is generally heavily focused on things like utility maximization and build order scripting. Some of the more complex issues are things like path planning for masses of units (think Zerglings in Starcraft II) and those aren't going to be solved by GAs any time soon.[/list][/quote]
The idea is to spice up scripted AIs with GA. (The GA framework finetunes the "constants" in your scripts.)
Also, don't confuse Genetic Algorithms with Genetic Programming. I don't intend to build in support for Genetic Programming.
[quote]
[list][*]You don't seem to account for the fact that every RTS is going to have a very different set of rules. What made Total Annihilation a great game was vastly different from what made Dune 2 a great game, or Warcraft, or Command and Conquer. Those rules and design decisions shape the AI far more than code ever will.[/list][/quote]
As I said, the gamerules are flexible. The default rules are what generic RTS-es does (HP, shield, splash damage), but should be easy to override. Also you're supposed to write the rules in Java (the horror) by extending/reimplementing the gameplay class.
[quote]

I like the concept in principle, so don't take this as anything more than constructive criticism; in fact I think it'd be cool to have a prototyping tool for RTS games that worked very similarly to what you seem to be envisioning. But to make it really kick-ass, I'd suggest shifting focus a bit: build a scripting or other high-level data driven system that lets a designer prototype an entire game from start to finish (sans graphics, sound effects, whatnot) and see how it actually plays. Build in rich support for AI scripts written in, say, Python or Lua, and provide a set of hooks for built-in stuff like a pathfinder and so on.
[/quote]
I'm already working on a grid based path finding utility that integrates smoothly with the rest of the framework.
[quote]
What you could end up with is a great tool for designers of RTS games to sit down and hammer out all the rules for their game first and foremost, then have AI engineers rough out the gameplay logic for the computer players, and then ideally just copy/paste their scripts into a C/C++ framework that integrates into custom rendering engines and so forth. You could bootstrap an entire game like StarCraft in a matter of days with such a toolkit, and I think it would be truly cool to have something like that available.
[/quote]
That's the vision. However on the short term (next 1-2 years) I plan to concentrate on the gameplay features, the shiny stuff should come later.
Even if it will be a prototyping tool/testbead for new ideas, it could be immensly helpful. As I heard, AI is bolted on in a rush on the later phases of developement in a lot of games. This tool would allow to test AI ideas in earlier phases.
[quote]
Massive bonus points for including a rudimentary network code implementation that can be used for playtesting PvP combat...
[/quote]
The idea is to be able to train the GAs without networking overhead, and then running them in networked tournaments, with non-cheatable server (no gameplay rules deferred to clients).
Also, if you have many machines, you should be able to train them on the network too.
But at the moment I concentrate on local stuff, but design interfaces with networking in mind. (Not an easy task.)

Anyway, this started as "a fun diversionary project for some research", so I will content even if it remains that. If I can gain some new insights as an RTS player, it was worth it. Edited by zslevi

Share this post


Link to post
Share on other sites
CadetUmfer    234
Really? I'm working on an RTS AI as well, using potential fields and behavior trees. Both of these end up with lots of tunable "weights". For example, when a force encounters an enemy, they can choose to attack, defend, retreat, or bypass. These are each behaviors chosen by a weighted random selector, where each weight is a sum of a weighted value for the enemy's strength, a weighted value for friendly strength, a weighted value for how favorable the terrain is, etc. When a unit is moving, its potential field utilizes many different factors as well (how much to prefer cover vs speed, for example).

A GA seems like an excellent candidate to handle this sort of combinatorial explosion. You have a multitude of different variables, with no precise right answer. As long as you can measure the results in order to perform selection, shouldn't a GA be able to work here? I'm hand-tuning everything now, but I was hoping to be able to serialize these behavior trees into chromosomes and run them through a GA while the AI plays millions of games against itself.

Share this post


Link to post
Share on other sites
LeventeZs    100
[quote name='typedef struct' timestamp='1307453174' post='4820502']
Really? I'm working on an RTS AI as well, using potential fields and behavior trees.
[/quote]

I already have some nice classes to visualise custom potential fields. (Overlays)
Yeah, I see you get the idea. I'm happy to find some like minded fellow, not just C++ snobs :)


[b]
[/b]

Share this post


Link to post
Share on other sites
IADaveMark    3741
You might want to ponder the "C++ snobs" bit a little more. I was a VB guy and went out of my way to learn C++ specifically because that's what the industry used. Whether I liked it or not, nothing I wrote in VB was going to be worth a crap to anyone else. If I was going to actually work in the biz, then I needed to break away from what I was comfortable and play along with the rest of the kids.

When in Rome...

Share this post


Link to post
Share on other sites
LeventeZs    100
[quote name='IADaveMark' timestamp='1307653755' post='4821483']
If I was going to actually work in the biz, then I needed to break away from what I was comfortable and play along with the rest of the kids.

[/quote]

Well, I don't want to work in the "biz", and this is a mere hobby project. On the other hand in academia quite a few people use java in AI related fields (see Weka, Jess or Pellet), and C++ is less popular. Also, I don't think Java programmers are less intrested in modding a game, it's just the AAA shiny engines are in C++/Lua for performance (shininess) reasons.

By the way it wouldn't make sense to make the core in C++, and create Python bindings, as the AI will be in user "scripts", and that's where the computational heavy lifting will be (especially in the offline learning mode; remember the goal here isn't shininess). Also, I'll heavily rely on the reflection API to create IDE like features ( Inspector widget e.g. for user defined units).

Share this post


Link to post
Share on other sites
LorenzoGatti    4450
[quote name='zslevi' timestamp='1307705191' post='4821669']
[By the way it wouldn't make sense to make the core in C++, and create Python bindings, as the AI will be in user "scripts", and that's where the computational heavy lifting will be (especially in the offline learning mode; remember the goal here isn't shininess).
[/quote]
A bizarre misconception: any "computational heavy lifting" in Python code should be as efficient as it would be in C++, or possibly even more, because it relies on Numpy, or similar efficient libraries, or your own C/C++/FORTRAN extensions encapsulating your own learning algorithms.
Implementing linear algebra operations on large inputs with thousand of separate heavyweight Python objects instead of arrays is mere idiocy, not a problem with specific programming languages.
[quote]
Also, I'll heavily rely on the reflection API to create IDE like features ( Inspector widget e.g. for user defined units).
[/quote]
Another bizarre misconception: the planes of user defined units (more generally, of game rules scripts) and of AI scripts for specific game rules should be completely separate, and there's no reason to implement rules and game state views with impoverished and cumbersome tools like ad-hoc classes and primitive "poking" with reflection instead of a general object model and a UI layer that takes advantage of it.

Share this post


Link to post
Share on other sites
LeventeZs    100
[quote name='LorenzoGatti' timestamp='1307954688' post='4822661']

A bizarre misconception: any "computational heavy lifting" in Python code should be as efficient as it would be in C++, or possibly even more, because it relies on Numpy, or similar efficient libraries, or your own C/C++/FORTRAN extensions encapsulating your own learning algorithms.

[/quote]

1, If you use default Python arithmetic it's much slower. (And not only the arithmetic is slower.) If you want fast arithmetic, you have to explicitely use numpy, and it only benefits matrix operations.
2, "[color=#1C2837][size=2]Implementing linear algebra operations on large inputs with thousand of separate heavyweight Python objects instead of arrays is mere idiocy, not a problem with specific programming languages."[/size][/color]
[size="2"][color="#1c2837"]I would benefit fast matrix oprations, if I would use neural networks (MLP/RBF/SVM) for training, but I use a genetic algorithm framework.
[/color][/size]
[size="2"][color="#1c2837"]
[/color][/size]
[size="2"][color="#1c2837"]"[/color][/size][color=#1C2837][size=2]Another bizarre misconception: the planes of user defined units (more generally, of game rules scripts) and of AI scripts for specific game rules should be completely separate, and there's no reason to implement rules and game state views with impoverished and cumbersome tools like ad-hoc classes and primitive "poking" with reflection instead of a general object model and a UI layer that takes advantage of it."[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]The only use of reflection is to display the custom properties of user defined units to the user, which is exactly what reflection was invented for. There's no reflection in game rules/AI part. [/size][/color]

Share this post


Link to post
Share on other sites
IADaveMark    3741
[quote name='ApochPiQ' timestamp='1307982333' post='4822821']
Actually, Python has pretty crappy performance characteristics for truly heavy computation, and even worse characteristics for multithreading.
[/quote]
Aaah... but remember, C++ "is too low level a language to program AI in". (There's a rationalization statement if I've ever heard one.)

Share this post


Link to post
Share on other sites
ApochPiQ    23063
I have to be careful with this one lest I hang myself with my own words, especially after the GDC talk :-D

I wouldn't say Python is unsuited to doing AI - in fact, there's plenty of counterexamples in shipped games. Rather, to be strictly literalistic about my earlier post, Python is problematic for heavy computation and multithreaded scenarios. If you can run your AI in a single thread, cool; write it in Python (or Lua, or your own DSL, or whatever else). Otherwise... if you need to do low-level stuff, do it in a low-level language.

Share this post


Link to post
Share on other sites
LeventeZs    100
I made some progress and some documentation.
Now there's pathfinding, and a very simple computer opponent, a map editor and you can load/save a game. There's no networking or machine learning stuff in it yet.

You can check it out here the 0.2.1 version stuff:
[url="https://sourceforge.net/projects/infinite-wisdom/files/"]https://sourceforge....e-wisdom/files/[/url]

The documentation (at the moment embedded in Javadoc):
[url="http://infinite-wisdom.sourceforge.net/doc/overview-summary.html#overview_description"]http://infinite-wisd...iew_description[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this