Share this project


Share this project

A real-time, class-based strategy game, set in an open world cyberpunk city, from the creator of Syndicate Wars.
A real-time, class-based strategy game, set in an open world cyberpunk city, from the creator of Syndicate Wars.
15,029 backers pledged £461,333 to help bring this project to life.

AI for emergent gameplay

Posted by 5 Lives Studios (Creator)

MikeD here.

I thought I'd write a piece about AI and how I'm coding it up with relevance to emergent game-play.

You may not want to read on if you prefer to think its all done by magic, but if you want to take a glimpse behind the curtain read on.

I like my ai's to react meaningfully to stimulus, which basically means giving them the ability to see and hear.

That may sound obvious, but a lot of ai's in games don't react to anything, they are simply pre-placed in the world, told to go to sleep and are woken up when the player enters a specific trigger box, perhaps halfway down a corridor they are in. So they wake up and start executing their pre given command shoot player. 

You can get away with this in linear games and sometimes its actually the best way if you want to have total control of your game, everything tightly scripted, almost like the ai's are following a movie script. Zombie dog jump through window 3 seconds after player steps into this invisible box. It can make games atmospheric, but the downside is its totally the same every time you play through, you die and restart the level, same guy triggers, same dog jumps through window, Yawn! 

I much prefer games that take a behavior driven approach, you basically code up multiple behaviors make them react to stimulus and give them a bit of decision making capability. 

So lets take a standard behavior, Guard. You can imagine this as a typical security guard, night after night given the duty to guard an area. Lets give him an area he is going to guard some kind of compound, nobody should be entering this secure area. 

The guard has 2 main senses we need to worry about sight and sound, sight has a field of view (FOV), say 150 degrees and a range, the range might be a km, but he also might not care about what anyone is doing 100 meters outside the volume he is guarding. Hearing has no FOV but has a range much shorter than sight lets say 100 meters.Sound travels slow so would take about 1/3rd of a second to travel 100 meters. Then we factor in reaction times too. 

Events, events are the means by which we communicate things happening that ai's need to know about. 

Fire a gun, broadcast that event to everyone within 500 meters say, here's the key though, the sound of the event goes into a queue for everyone within range. They will receive the event when the sound has correctly reached them, the visual of the event will reach them instantly, but if its outside their FOV or something is blocking their line of sight (LOS) they won't react to the visual cue. So really 2 events are created and are propagated at different rates, Gunshot audio event and visual event. Audio Events also are less precise they may only provide the listener with a possible volume for the source of the sound and the volume will be bigger the further away the sound is, and again if there's no LOS maybe the sound had to bounce off a few surfaces to reach the listener so its even less accurate where the source is.

How people react to events is decided by their current behavior as well as various stats they may have.So back to our guard, a gun shot outside his guarded area is probably going to raise his attention if its close enough, what's some of his basic responses we may have actions for.

  • Go investigate 
  • Take Cover 
  • Sound an Alarm 
  • Run Away and hide 
  • Simply turn and look in that direction and wait 
  • Ignore it 

With a bit of fuzzy logic we can decide which of these options the guard is going to take, we might factor in his boredom levels/ tiredness/ bravery perhaps its a violent area where gun shots are frequently heard outside his compound. 

To decide which action we take, we look at a set of essential properties that the AI is looking to maximize such as Financial, Safety, Food, Sex, Excitement, Sleep, Respect.

These properties generally decay over time, people get hungrier,sleepier,hornier..Doing something heroic might increase your respect levels and excitement levels.Running away might decrease respect a little but increase your safety but decrease finance (you are not paid to run away). 

Now each of the 6 actions above can have a +/- value assigned to each of the 7 essential properties for each of the type of events that might happen. 

Investigating a gunshot might increase heroic and excitement and decrease safety a little. 

The amount these essential properties changes can be scaled based on distance of the event, and also base stats such as how brave the ai is, or intelligence, or monetary greed etc. 

So now this Guard can compare the scores for all his choices choose the highest scoring option, compare it perhaps against his current activity and decide what to do. 

For extra dynamics the essential properties feed into each other, too much excitement can be detrimental to safety, sleep and hunger. 

Too much food can make him sleepy. We can factor sleepiness into reactions 

Everything feeds into everything else causing a chaotic system, but also a believable system, a systems where the Guard will go get some food because his hunger level got too high, or he fell asleep on the job because he got to sleepy, or he decided to run away from a shoot out because he’s basically a bit of a coward and the financial gains of defending the compound didn't out-way the risk of being killed. 

These stats can also factor into taking a bribe, or being distracted by an attractive member of the opposite sex, or what the guard is going to do when his work shift finishes. 

Of course the event might not be a gunshot, it might be a car crashing through a gate, or having a gun aimed at you, or being offered a bribe, or an explosion, or a bullet ricochet, or a near miss from a laser beam, or a muffled grunt or a soft foot fall behind you, the lights cutting out, a siren blaring, discovering a dead body... 

The bottom line is by giving AI’s behaviors, and a behavior being set up with lots of possible reactions to lots of different events, and factoring in base genetics of each AI with their current state and needs, we can make the world react to the player in a believable way, and can remove the scripted feel to the game as the AI reacts different depending on how you break into the compound to steal the computer equipment, by stealth, by explosives, by sheer gun power, perhaps you just offer the guard enough money, perhaps one of your female agents seduces him.     


Only backers can post comments. Log In
    1. WP - Member, Mutant League on

      When the AI works very well, this game will stand above most single player games with its AI.

    2. Drakol on

      What of AI Orientation? Is it going to be Simpler for the game, just to program the AI to be either A or B (Male / Female) and then Randomize the Skin they're given? (I.e. A Male AI in a Female Body) Or are you going to create multiple AI Archetypes that incorporate multiple Orientations with Fuzzy Logic? - What of stranger things, like Technophiles or something else. For example, if your Agent is Tech'ed out to the nines with Cyber Impants that are Overt, the Guard regardless of gender could take a Platonic interest in them, etc. Then again, this would of course make it too unwieldy, right?

    3. Missing avatar

      Casuals on

      Please use a light touch with any seduction (forgive the awful pun) or 'sex drive' content. This tends to mean 'gratuitous sexism justified via game mechanics'. We see enough crass exploitation of women in AAA games - it doesn't need to be the same for the indie elite.

      Everything else sounds amazing!

    4. Michael Zautner on

      A cool look at how you're doing the AI. I've done a bit of programming (like, 2000 level, tops) before, but never anything dealing with AI, but this is roughly how I figured it would need to be done to get something that felt fairly real. Still, hugely complex and I can hardly imagine actually making it function as a whole and putting proper weights and feedback cycles that didn't result in infinite loops (Hey, hunger went down, that means sleepiness goes up, that means desire for action goes up, that means horniness goes up, that means hunger goes up.... wait...)

      I am curious how, or if, you would factor in terrain for sound. I suppose much like vision, but with walls reducing range instead of blocking it entirely like vision? But of course sound doesn't go in strait lines, so that might be a bit too simple (though it would make it very manageable)

      Also, since you're going to all this work to model things in such detail, I figure there'll be some way to actually figure out at least some of this information about a person. I mean, the guard accept the bribe because he is poor instead of a random roll is cool, but if you have no way to figure out that he is poor, it isn't any different to the end user. I am hoping it'll be a bit more complex than a bunch of bars just showing up whenever you hover over someone though (until you have acquired said information for said individual)

    5. Missing avatar

      Wright Johnson

      This update definitely did not coax a high-pitched squeal of joy from me, nor did it give me goosebumps. I totally just nodded in approval and allowed myself a small smile before going back to doing manly things like chopping wood and, um, stuff.


      I'm not in denial. YOU'RE in denial. ;)

    6. Paal Joachim Romdahl on

      Heya Mike and everyone else!
      I just became a backer as this game looks really cool and has a good concept behind it! I really like this AI update, and it is something that should also be shared on on your own web site. Creating awesome AI seems to be one of the most tricky parts in all the games I have played! I look forward to testing out how alive your world becomes!

    7. Missing avatar

      Stefan V

      Cold, rainy weather and not enough cash to buy a new pair of thermonuclear underwear because the ex-wife takes most of the paycheck... I didn't hear anything.

    8. Christian on

      This sounds awesome but ... how do you even start balancing something like that?

    9. Navagon on

      This sounds like it could be amazing. In practice it will probably be chaos. But then that's exactly what it should be.

    10. Silver on

      Who had the order of pizza [laced with sleep meds]? You, sir? It's already paid for.

      Access to secure areas has never been cheaper.

    11. fedsoatk on

      Very interesting update, thanks!

    12. twincast ~ Mangy WoOS-DOoD Mage

      @SD & 5LS: Sounding good. *nod sagelily*

    13. Seth Burnette on

      That is excellent. I love the simulation style of game AI design. It reminds me of that old "Illusion of Intelligence" presentation that the Bungie guys gave years ago about modeling limited AI knowledge in the first Halo.

      Is there any way we can see the test of your ideas implemented in a rough white box level or something?

    14. S.D. on

      @bracknellexile, @hendawg: I agree, regarding representation. Best way to handle it in a tactical, stats & strategy driven game (like a Syndicate successor) would be to reduce sexual preference to a gameplay mechanic, determined when the parameters for the NPC are rolled. Perhaps preference could be an integer between x & y (like a sliding scale), and then that determines a stat for seduction, the magnitude of which is determined by their sexual drive (desperation?) stat. That way, sexual preference is only a modifier for seduction (leaving the way for interesting outcomes, like a sufficiently charismatic agent having a chance to seduce a guard who's "horny" enough to sleep with anything that moves, regardless of preference!)

      @Gillsing: Sexy Pizza Delivery is the name of my new band ;-)

    15. Missing avatar

      Mikael on

      And some you just shoot to scrap :)

    16. Missing avatar

      Mikael on

      And Robot guards of different classes have different approaches.
      Some are set to kill on sight, some to warn user to leave.

      Some can be hacked
      Some can be disabled (emp weapon or sneak up behind and "turn off")
      Some can easily be fooled, distracted by a decoy
      Some you can convince/fool that you are part of the guard force or an employee

    17. Missing avatar

      Mikael on

      This is so great.
      And adds more realism to the game.
      Just hope that taken to consideration that it will not be as easy as "picking-off-one-by-one" or the "shot-one-guard-and-instantly-all-enemies-jumps-at-you" in a millisecond.

      If a guard sees or hears something it will not just go investigate but the option that the guard will call in the event to base or to its group, should be a variable.
      Also that you can take out guards without killing them. Just knock them out, tie them up and hide or persuade them :)

      When the guard has seen you the option should be:
      Make you go away or Make an arrest (disarm & interrogate) or Shoot (call in backup) take cover. Anything but shooting opens up to dialog, bribe, intimidate, make an offer that can't be refused :)

      Also if/when the shooting starts.
      Not let all guards swarm you like guided missiles.
      Let them flank, support fire, and some guards will not leave their area unprotected unit they are needed.
      Also let them give up instead of die to the last man.
      Most will give up instead of dying if its just a paycheck.
      Perhaps in some missions when you are so infamous guards will not fight but surrender and give you the scientist & prototype weapon or money.

    18. Brett Koochin on

      I became happier and happier as I read this.

      So excited.

    19. Missing avatar

      Luke Smith on

      That was a very interesting read! You could write a whole book on the subject and I'd read it all.

    20. Shadowbreed on

      Extremely good article.
      Thank you very much for sharing those details.

    21. Gillsing on

      Sounds very promising. The good thing about a game like this is that few NPCs should be so important that the game can't afford to have them do unexpected things. And perhaps if the player starts to depend too much on one way of doing things, news will spread, and guards will watch out for that particular modus operandi? "Sexy pizza delivery? Uh oh, that's bad news. Get your weapons ready!"

      Same thing could apply to weapons: If the player often uses the same weapons, the corporations could prepare for that weapon by employing countermeasures.

    22. Blackstaff on

      That was a great read !

      Gotta remember some old games where AI were so dynamic :)

    23. Missing avatar

      Mirko on

      Hi, I´ve worked in this area for some time and got the feeling that the most difficult parts, beside the potential performance impact, are the comparability of events and personal knowledge of agents.
      1. How can event A with vector (2, 0, -4, 1, 4, 0, 3) be compared with dozens of other events in a meaning full way so that the guard does not decide in an unwanted manner.
      2. Does a guard have certain knowledge, compared to other guards, which affects his knowledge? E.g. the guard remembers our agent from ten minutes ago shooting around before he got out of site and therefore attacks him now. Or do you magically compile this information into the vector above?

      Thank you for sharing these insights!

    24. Ber on

      @Adrick: Wow I love your idea. The whole idea of giving each guard an actually rudimentary personal life and the ability to mess with it would be amazing. I'm guessing to make that work in-game it would probably be fairly hard to get the full guard roster for a big company, but as a really good hacker you could, or just by roaming the streets you might happen upon the guard coming home from work and thus find your angle of attack for a future raid. You could even just take him out on his way to work, leaving them short-staffed! So, so awesome.

    25. Ber on

      @Chris Doak: putting up a Paypal before they hit the base target works against getting this game happening, as Paypal funds don't count towards the Kickstarter goal, and if they don't hit the goal, they don't get any Kickstarter money. There will be plenty of time for Paypal donations later...

    26. Adrick James Trotter on

      I'm curious, will you be able to do things like. Find out where a guard lives. Keep him up all day, (rent next apartment and blare music or something like that) so he them falls asleep at work?

    27. Paul Hempenstall on

      Thanks for the update. I love thinking about AI of characters in games, like how to get this sort of behavioural AI going, how to make it reactive, different each time, how to keep complex things as simple as possible. So this kind of update is right up my street.

    28. Chris Doak on

      This is going to be so awesome if it launches!

      Speaking of, have you got a paypal account or similar up yet? We've just over two weeks left.

    29. Missing avatar

      bracknellexile on

      Thanks for the quick reply. I know it's a minor thing in the grand scheme of AI design but it's good to know you're taking everything into consideration and embracing the full diversity of people. it's tough to get things like homosexuality into gaming sometimes (hell, it's tough to even get female characters half the time!) but I think it's an important thing to do so it's much appreciated.

      Can't wait for release day :)

    30. Ber on

      Very interesting update, nerd factor 11 updates get the thumbs up from me! :)

    31. hendawg_ofthemiddle on

      Can male guard seduces him ? Not everyone has the same tastes ;p . But sounds cool if they have a lot of depth. Hope female agents use, isn't just seduction though!

    32. 5 Lives Studios Creator on

      @bracknellexile The hacker has a perfect opportunity to use their abilities to snoop on base stats, even check sexual preference.

      This guard is extremely hungry, distract with a delivery of pizza's :)

    33. Jai Nelson on

      I read on anyway, and it still seems magical to me :)
      Thanks for the peak at the wiring under the board, really interesting to get a view of how the AI is done. Doesn't detract from the experience/appreciation, if anything it enhances it. Really looking forward to playing this game even more now!

    34. Missing avatar

      bracknellexile on

      Loving the fact that you're trying to make the AI as realistic as possible and the insight into how it will work is much appreciated.

      Will you be considering sexual preference when it comes to things like seducing guards? Sending a female agent to seduce a male guard (or vice-versa of course) could be an automatic fail if the guard is not that way inclined, leading to unforeseen consequences for the player trying to use these techniques if, for example, they didn't have advance info on the personnel of the area they're trying to infiltrate (I don't know if scouting / hacking for advance info that would effectively give the player some insight into those AI stats is something you have planned).

    35. Dablue

      H o r n y was the word

    36. Dablue

      Lol so appearently we can have horny guards. Do you have to worry about them humping your leg?

    37. 5 Lives Studios Creator on

      I should probably do another post in the future about AI's for cities.

      Unfortunately we don't have enough processing power or memory to simulate tens of thousands of active people in a city.

      But essentially anyone who cant possibly affect gameplay can be hibernated (go into a no cpu usage state), as they approach the players bubble of activity they can be periodically woken up to see if there's anything they should be doing.

      Time slicing AI you can update their stats factoring in the amount of time that has passed.

      You can also do aggregate processing of city regions, so that life does go on but at a broader scale.


    38. Missing avatar

      Noam Weiss on

      This is amazing! Thank you. I'm trying to get into game AI myself and this is literally one of the main things I want to be doing - character behaviors. So it's always great to hear about what people are doing out there. (Even more awesome would be a talk on AIGameDev about the challenges and approaches involved with this :)
      Anyway, good luck on this campaign, can't wait to get to play this!

    39. Anton on

      This simulation is for whole city? Or only around player? Fully simulated city would be awesome! Of course if it will not require a computer cluster :)

    40. Aelius on

      *makes homer drool sound*

    41. Philippe on

      Really nice's just great what you want to do and I really hope it will be funded and we could play it next year on time. In the jungle of video games, we need more professionals like you guys!

    42. suppafoxe on

      Awesome read! Tech insights like will always be appreciated (by fellow programmers at least ;))

      How do you plan to simulate ALL the people in the various city blocks? Will some very distant AI (where the player has yet to go) sleep, or get updated just sometimes?

    43. Felix on

      The more I read about this game, the more I want it right now!