Slashdot Mirror


Emergent AI In an Indie RTS Game

x4000 writes "My recent RTS game uses a new style of AI that hybridizes rules-based AI with emergent AI logic. As a disclaimer, I'm really not an AI programmer at all — my background is in databases, financial modeling, etc. But it just so happens that database experience, which often involved distilling data points from multiple sources and then combining them into suggested decisions for executives, also makes a great foundation for certain styles of AI. The approach I came up with leans heavily on my database background, and what concepts I am familiar with from reading a bit about AI theory (emergent behavior, fuzzy logic, etc). The results are startlingly good. Total development time on the AI was less than 3 months, and its use of tactics is some of the best in the RTS genre. I'm very open to talking about anything and everything to do with the design I used, as I think it's a viable new approach to AI to explore in games, and I'd like to see other developers potentially carry it even further."

22 of 146 comments (clear)

  1. Article summary: by ActionJesus · · Score: 5, Insightful

    "I just wrote a game. Heres some techy stuff to get it posted on slashdot. Yay advertising!"

    1. Re:Article summary: by mcvos · · Score: 3, Insightful

      It is very light on implementation details.

      Which is unfortunate, because it's a really interesting topic.

      Basically what he says is that he has three levels of AI: strategic, sub-commander and unit. Units look out for themselves, strategic is rule based and sets strategic goals, and sub-commander is the fun part: it makes units work together through flocking.

      That's pretty much it. Very interesting, but a bit more meat would have been nice.

      The slashvertisement worked, though. I'm very tempted to buy this game to see if the AI is really good, even though I hate RTS games.

    2. Re:Article summary: by Bat+Country · · Score: 3, Interesting

      It's a great approach. It's one of those quasi-obvious AI schemes which people have been kicking around for years but typically haven't wanted to expend the CPU cycles on in major projects. I remember an article around 1997 wherein they asked game development studios to explain how games were going to change in the next couple of decades, and one of the chief topics that kept coming up was more natural AI (less rigidly rule-based) which could learn by observing outcomes. Modelling AI on military organization is fairly clever for the same reason that military organization (at least in battle) is clever - the individual soldier needs little autonomy or smarts, just so long as everybody further up the chain from them is at least incrementally smarter, if less capable in direct conflict.

      The most notable use of a system like this in recent years has to be the Director in Left 4 Dead, which is an overarching control scheme which issues orders to the game world and the units in it. These units are free to do what they do best - navigate around the map and eat players without having to worry about strategy. The Director is free to select the paths by which the units will arrive without having to waste significant time on fine pathfinding, as the units themselves will do the bulk of the work.

      I look forward to more games with heirarchical AI. I've written some basic tests of this exact sort before (basic "burds"-looking stuff) and the resulting behavior is extremely intuitive and ordered-looking.

      --
      The land shall stone them with the bread of his son.
  2. player mimicry by drDugan · · Score: 5, Interesting

    could you catalog user actions and use them as possible inputs for your AI?
    like this: http://slashdot.org/comments.pl?sid=1165583&cid=27243769

    it would seem this might make for the most challenging AI - one that
    learns and mimics good human players. I have yet to see any games
    that can do this well

  3. Summary useless by toxicbubble · · Score: 5, Informative

    Summary reads like a marketing blurb but the actual article is slightly more interesting. The basic idea is that in an RTS game, the AI is at a unit level rather than an 'almighty all-seeing controller'. It is a fairly interesting idea and does sound sort of different way of thinking about computer RTS opponents. Weather or not this actually makes for a fun game or a good idea remains to be seen, but at least there is something (dare I say) slightly innovative about this.

    1. Re:Summary useless by fractoid · · Score: 3, Funny

      You mean he wasn't referring to the Fog of War?

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    2. Re:Summary useless by BikeHelmet · · Score: 4, Interesting

      In short, it segregates the controller AI from the unit AI.

      I can remember when playing SupCom against easy opponents, if I didn't build any defenses, the opponent would stop sending units into my base for a while, instead moving them around in circles somewhere outside it. Even an easy/stupid AI has to make decisions that a stupid person would make. Mainly - CHARGE!

      But at the same time, the best AIs were omniscient. They'd target your first fusion reactor with bombers as soon as you build it... It became so predictable that I'd build a shield, turn it off, build a fusion, then turn the shield back on.

      But in SupCom there were all the modded AIs which chose more interesting tactics, and you could enable cheating for any AI to give them a resource and difficulty boost.

      I think to be realistic, AI has to be segregated even more. You need an Advisor, which decides the direction things should be going. Do we need more resources? Do we have an urgent matter to deal with, like artillery pelting the base? The Advisor should just decide what to tackle, and then pass that on to the other AI subsystems. Like a player, the AI subsystems should take time to do stuff. An AI can't instantly decide what's an entrance to his base. He has to study where the units usually come from, and locate possible landing zones for air transports, etc.

      To ramp up the intelligence, you let it assign more issues to its subordinates more rapidly, and you let it learn across missions. Pretty soon the AI can tackle any frequently played map.

    3. Re:Summary useless by toxicbubble · · Score: 3, Interesting

      Thinking about it a bit more, I wonder how this compares to the AI used in hack n slash games where you get swarms of enemy's all over the place. I'm thinking of the Diablo I & II (and future III) series from Blizzard. I suspect these games use a similar idea in their monster AI.

      These games use fairly simple monster AI that usually follows simple rules, so it may be much simpler than what this guy claims. However I think it must be applied per creature. Some types of monster will run and cower when you kill their nearby friends, others run off to heal but some of those Hell Bovines will chase certain targets in multiplayer games. I never got the feeling there was an overseeing god directing all the units with these games.

    4. Re:Summary useless by Sobrique · · Score: 3, Funny

      I'm not sure, some people seem to have mist the point.

    5. Re:Summary useless by x4000 · · Score: 5, Informative

      Quite valid -- intelligent agents are not a new idea (I'm the dev from the article). However, the vast majority of RTS games are still using decision trees, I guess because the prevailing wisdom is that such is needed because of the complexity of RTS play. Is it so surprising that industry lags behind academia? But, even my approach is not purely an intelligent agent approach, but rather combines in a bit of global logic as well (for reinforcements, choosing global attack targets, etc). I think that a hybridized sort of approach is really needed for RTS games, since they do have so many levels at once.

  4. Like to see.... by Daemonax · · Score: 4, Insightful

    I'm very open to talking about anything and everything to do with the design I used, as I think it's a viable new approach to AI to explore in games, and I'd like to see other developers potentially carry it even further."

    If you're serious about this, then release it under a Free software license.

    1. Re:Like to see.... by x4000 · · Score: 5, Informative

      I'm not going to release the game for free, given that if I'm to be able to continue to pursue game development it can't continue to be in my hobby time forever. For similar reasons, I'm not going to release the entire code as open source. However, I've already open-sourced a lot of smaller things from my code (force feedback code from my other game, fixed-int math from this game, etc). Also, I've now added a second part to the article which has some partial AI code from the game, and people are free to use the ideas there and build off of them as much as they want. I don't want people to make AI War clones, but rather to think about the ideas that I am presenting and implement them in their own way. The AI War code is not the only way to approach this general design philosophy, not by a long shot. Here's part 2 of the article, with the added code and such: Designing Emergent AI, Part 2: Queries and Code

  5. Not all that new by The+Optimizer · · Score: 5, Insightful

    I seem to remember most all of these things were in (or experimented with) the RTS games I worked on a decade ago - Age of Empires/Kings/Mythology (Decentralized Intelligence, Strategic Tiers, Sub-Commanders, etc). Not all of those were exposed to the end-user via the AI script / expert system / etc, and things improved with each iteration.

    I also remember that while some Ai things may have seemed like great ideas, and were neat to implement, they didn't always make for a better game experience.

    And I personally say you should make an economic AI that is bound by exactly the same rules as human players, and doesn't cheat at all. And as I remember, the definition of 'doesn't cheat at all' was an occasional ongoing discussion and subtle things that could be considered as cheating, like 'Can I Path from here to there?' or the reactions times of the computer vs a human sometimes had massive implementation ramifications.

    A good test in my book was 'can the AI handle a wide range of truly random maps / game worlds.

    Humans will always be finding the limits of Computer player AIs, and saying you'll just put in counter code whenever someone tells you of your AI's limits... Hmmm... I think that's weak.

    All this has been done before, and all this will be done again.

    All the above is solely my opinion and recollections, and in no way speaks for anyone but myself.

  6. Add some flaws. by apodyopsis · · Score: 5, Informative

    I'll ignore the shameless plug.

    Ever since I wrote my first connect 4 game in the 80s - and was totally thrashed by it, I never beat it - its been clear to me that the trick is to degrade a computer player in most circumstances to the level that it appears to have human flaws and play in a more human fashion.

    Of course this logic only goes so far and some games require a search space so vast or a completely different programming model that even now a computer cannot beat a competent real human (Go is an excellent example of this).

    The point is that it is easy to program a computer to win, the hard part is to program is lose convincingly.

    1. Re:Add some flaws. by Anonymous Coward · · Score: 4, Informative

      http://en.wikipedia.org/wiki/Solved_game

      Connect Four

              Solved first by James D. Allen (Oct 1, 1988), and independently by Victor Allis (Oct 16, 1988)[3]. First player can force a win. Strongly solved by John Tromp's 8-ply database[4][5] (Feb 22, 1995). Weakly solved for all boardsizes where width+height is at most 15[3] (Feb 18, 2006).

      Emphasis mine.

  7. Re:All their art is stolen. by Anonymous Coward · · Score: 4, Informative

    I quote "the graphics have been made available under an open license in April 2007" http://en.wikipedia.org/wiki/Tyrian_(computer_game) so how are they stolen?

  8. Superficial Intelligence by Anonymous Coward · · Score: 5, Funny

    my background is in databases, financial modeling, etc. But it just so happens that database experience, which often involved distilling data points from multiple sources and then combining them into suggested decisions for executives which blew up the stock market.

  9. If we're talking about SkyNET... by petrus4 · · Score: 3, Interesting

    ...then it is worthwhile remembering that centralisation was its' most fatal
    weakness.

    In the original story, (the end of the T2 novel, or thereabouts) Connor won by
    blowing up the central core under Cheyenne Mountain. SkyNET's primary
    exploitable weakness was that it was never willing to truly reproduce, for
    fear of losing control; that is, to create another AI with fully the same
    level of functional intelligence that it had. (I believe personally that a
    compelling case could be made for the assertion that SkyNET, as depicted, was
    not truly strong AI, but I digress)

    The point is that as far as creating genuinely effective weak artificial
    intelligence is concerned, the decentralised/segregationist approach is the
    correct one.

    Given my own experience with FPS mapping, I also concur with the author of TFA
    when he says that making AI choose the "best" choice 100% of the time, is
    not the best tactical approach, over time. My own experience gradually
    suggested that around 75% appears to be the magic number, as far as creating a
    truly emergent, unpredictable opponent that humans will be unable to overcome.

    Granted, said 75% is also only effective where there are a large number of
    divergent solutions to a given problem, each with close to an identical level
    of effectiveness, but with a few subtle points plus or minus, each way.

    Even with a fuzzy, emergent system, the best trees still have a maximum number of
    branches. The real trick however is not to hand code said trees at all,
    because then you simply end up with static, rote heuristics. Rather, as the
    author possibly implied, it is far better to attempt to code
    observation/deduction capabilities, guided by the above percentage, and let
    the system do the rest on its' own.

    I still remain extremely skeptical, however, that humanity will ever see the
    emergence of truly strong (human level or greater) AI. It is worth remembering that
    strong AI is a fundamentally and profoundly atheistic concept; the possibility of it more or less presumes a definitely atheistic universe as a prerequisite. For those of us who believe in the existence of God, (or at least the soul) the idea (at least
    in terms of non-biologically generated, acorporeal AI, a la SkyNET; AI derived
    biomechanically is a seperate concept) therefore has some fairly
    serious problems.

  10. "Truer" AI suggestion by thepotoo · · Score: 3, Insightful

    This looks like a similar approach to one I have been thinking about for a while now.

    This type of layered control is very likely to be the future of all AI, not just that in games (I say this because there is some evidence that the human brain works in exactly this manner). I have a suggestion: let the thing fight itself. Begin with the same basic game, and rather than the randomness and fuzzy logic that you use (what does that mean? Can we see your algorithms?), use an artificial neural network for each unit, another for each "squad" (all nearby units, allows for flanking and such). Something with a few input nodes, a single hidden layer, and a similar number of output nodes should probably be all that's needed for the units, and the squad AI would only need a few more than that. This would likely be more computationally expensive, but it has one big advantage: it will learn.

    Begin with two full armies, each with their NNs randomly generated. Use an evolutionary algorithm, and have the winner fight the winner. Not only does this allow you to create a solid AI with minimal effort (see here), but when you have your final AI, it will be able to adapt to a specific player's gameplay style (over the course of several games). Replay value is off the charts, development takes a bit more initial effort than what you have, but in the long run you'll get an AI that genuinely uses tactics just like a real human player. I'm not sure how this could be adapted to a commander AI that would dictate broader strategy (due to the complexity of the NN required, you'd probably need a monster computer to run it), but it would be the sort of thing to try.

    Also, this same approach would also work for strong AI, if we had any idea what sorts of NNs to create. RTS is a much simpler problem, and has a lot of applications (pathfinding, planning, coordination) to other types of AI.

    If I've entirely misunderstood what you're doing here, I'm apologize, but TFA had more pop culture references than technical details. Reply if you want me to clarify any points.

    --
    Obligatory Soundbite Catchphrase
    1. Re:"Truer" AI suggestion by nedlohs · · Score: 4, Insightful

      NNs have the huge draw back that when you find a situation in which the AI does something completely ridiculous that ruins the game it's really hard to fix especially if you need to ship soon. Your small tweak will likely mess with some other situation. This is more likely in a video game than in a game like checkers since there's more factors at play (interaction with the path finding, etc).

      Backgammon is a better example than checkers. TD-Gammon not only plays the game very well, but changed the way people play the game. There were a number of situation where it played differently than the traditional expert recommendation of the best play, and it's play is now the one the experts use.

      Some games won't be so great at the "learning by playing against itself" NN approach. Anything in which getting stuck in a loop is reasonable will be problematic since the if the game doesn't end there's no result to learn from. In an RTS, this might be the case where you can build a defensive structure that is effectively impenetrable, neither one is going to win even though it could be the optimal strategy (if not losing is the goal, as opposed to winning).

    2. Re:"Truer" AI suggestion by x4000 · · Score: 3, Informative

      This is a really interesting post, and some of it goes a little bit over my head. Like I've said, I'm a database programmer, not an AI programmer. I might experiment with things like neural networks and such in the future, but right now the AI is doing as well as I could possibly hope for. That was a big part of the point of my article: using the fancier techniques is not even always needed for something like an RTS game, because you can get surprisingly good results with comparably little code.

      I'm sure I will experiment around with this more in the future, but I bet you somebody else builds on my approach and does something more impressive before I even can. Anyway, future articles in my aI series will go more in-depth and will also include relevant code snippets to help illustrate my points. Feel free to use and abuse them, and expand away.

      The second article is now up, to appease those hungry for some source code and a bit more of an in-depth discussion on a couple of sub-topics: Designing Emergent AI, Part 2: Queries and Code.

  11. Re:AI is pattern matching. by master_p · · Score: 3, Interesting

    The human mind solves new problems and creates new solutions by applying pattern matching to the old problems and solutions. With pattern matching, the brain creates an analogy, which is expanded and turned into a new idea.

    For example:

    1) animals fear fire.
    2) animals bother me.
    3) I can use fire to keep animals away from me.

    From then one, the brain has the pattern of 'using one thing to achieve another thing'. This pattern can be used in a wide variety of situations, including formulating the idea of relativity. If you read the history of Physics, you will see many things discovered before Einstein published his works concerning the nature of the universe, light, electricity, gravity etc.

    And of course, you have to have in mind that Einstein had a problem to solve which motivated him. It's problem solving (i.e. experiences must maximize our survival) that leads to constructs like the brain.