Mindflock.com
Social Game Artificial Intelligence
Social Game Artificial Intelligence
Sep 8th
If you ask anyone with a passing interest in AI and more specifically in AI in games what is the most important aspect, you will probably be answered with something relating to logic. Logic and decision making seems like the most important aspect because it drives behaviour after all.
But in this post, I want to put the case that actually logic is really not a problem for games.
Of course, we rely on some system of decision making to exist, but what specific flavour it is doesn’t much matter. A good number of games have been created using simple finite state machines, although these days you would expect those to be heirarchical. A lot of more action oriented games use Behaviour Trees, which is the system we have implemented for StoryBricks and you can learn more about them here. Other approaches use goal based systems such as Goal Oriented Action Planning and Heirarchical Task Networks.
But no matter what structural system you choose to represent the problem, it essentially boils down to a simple statement:
if <condition> then <action>
Of course, the number of conditions and actions available can be very high and the conditional tests and the execution of actions can be quite complex. But we have this fundamental architecture of the above statement.
Ultimately, the structure we choose doesn’t matter, we are simply executing a program which controls flow of control. With more or less efficiency and ease of authoring.
So if we accept (any not everyone reading this will, granted) that action selection is not the core problem, then what is?
My assertion is that what is key AI especially for “believable agents” work like StoryBricks is animation and movement.
Imagine, if you will, the following scenario. You are walking across a field and come across another fellow. He is looking intently at the ground. He does nothing except look at the ground. So the question is, what is he thinking? Why is he looking at the ground? Is it:
Which of those statements is true? Unfortunately given so little context, you simply cannot know why he is looking at the ground.
What if I said “he is the queens geologist and has been tasked with finding gold for a new crown”, would that allow you to choose from the list?
What if I said “he is your sworn enemy and has no means of defending himself”?
The point is, that without context, it is impossible to understand the intent of the action. For all the complexity we could put into the <condition> part of a if <condition> then <action> statement, we have to be able to understand the <action> part in context in order to understand the <condition> part.
Thinking about traditional media
Now if you think about cause and effect in other media like books and film, it is pretty easy to understand the cause, because it can be explicitly expressed. Consider the following narrative:
“The gunfighter put the empty whisky glass down on the bar and stepped out of the saloon. He walked down the creaky wooden steps and out onto the hard dirt. Dust kicked up with each step as he walked, his spurs chiming on the ground with each footfall. When he got within pistol range of his opponent he stopped. For long minutes he stood silent and still, his only movement a slow flex of his hand above the gun in its holster. A bead of sweat drifted down the side of his face, he was at a disadvantage he knew, because the sun was in his face. But the wide brim of his hat sheltered his face from the harsh blinding rays of the noon day sun. He waited and watched, coiled like a spring, a deadly serpent ready to pounce at the slightest movement”.
(apologies for any real authors btw).
So, given that narrative, you can picture a scene. You understand there is a gunfighter and he has an opponent. You can start to evoke a sense of the scene and what it might be like using your own knowledge of that context, which has been learnt over time from other examples of this behaviour. What you can’t get from this narrative is exactly why he is having this gunfight.
If we continue:
“He had thought of this moment for a long time. His had played the scene out many times in his mind, ever since he had heard about how his wife and children had been brutally murdered. He had spent many years tracking the band of outlaws that were involved in the killing. One by one he had silenced them, with only this last foe remaining. It wasn’t “justice” he was seeking, even though he wore a badge that legitemised his handiwork. This was pure sweet revenge, the brutal slaying of his innocents met with equally brutal punishment.”
Adding that context to the narrative makes you understand the motives behind the actions. It is one of the most powerful aspects of books, in that it can go into great detail and really involve the reader in understanding the psychology of the actions.
Films have a different vocabulary, with a more visual way of telling the same tale. Consider this set of storyboards:
The placement of camera, use of lighting to set the mood, adding music and all the many different aspects that cinematography bring to the table to express the same notional scene still allow the same story to be told.
Now consider this scene in a game. By this I mean in an actual interactive scene, not in a cutscene. Hard to imagine isn’t it? When the player can look anywhere, you can’t rely on them seeing anything. If you place the player as the protagonist, you will most likely have a hail of gunfire within a few seconds. If you place them as a bystander watching the scene, the player will most likely stand in front of the protagonist or just generally “get in the way” of the scene.
The fundamental problem, is that scenes like this are really evocative in the traditional linear narrative media like books or film, but fail entirely in games unless they are controlled as they are in cutscenes. Interactivity simply breaks down too many notions that are evoked in scenes like this.
The language of interactivity
So if we accept that some forms of dramatic content are simply not useful for interactive storytelling, what do we put in its place? That is where StoryBricks comes in. The conceptual issue that StoryBricks addresses is the interactivity relationships between NPC’s, players and objects.
In the interactive medium, you are not simply watching a narrative unfold, you are the narrative. Your actions and interactions are the fundamental control scheme for the narrative of the world as you experience it.
Consider this. If you were the lawman/gunfighter from the scene above and had been going around the land taking part in pistol duels with the people who killed your family, what would it look like to an observer who was casually watching your actions? What if you actually roleplayed the gunfighter? Would the observer understand the narrative of the world as it unfolded and what kind of experience would they have had?
Going back to the case of the man looking at the ground for a moment. What I am saying is that there is an issue with the players understanding of the intention of the actions of an agent. So my suggestion is that the important part of game AI, especially for believability, is that. The understanding of the intent is the key, not the actual formulation of the intent.
Let me give you an anecdotal example. In this video Wil Wright talks about one bug they had in “The Sims” where NPC’s would randomly set on fire. The players of the game made up different explainations about why it was happening. Was it spontaneous combustion? Was it something they had done?
We joke in the game AI community that the best initial approach is a random one. But this is actually true, in that we can often convince players that actions have considerably more behind them than is actually the case.
I once saw a fantastic presentation by Baylor Wetzel that highlighted this issue. He took a number of different algorithms for choosing patterns of attack behaviour in a wizard duelling prototype he had written and asked his students to identify them. It turned out that we are actually pretty poor at judging the cause of actions when any reasonably complex pattern is used. In this case, random is almost as good as complex pattern because if the pattern is complex enough, players will have trouble discening the pattern to the point where is essentially *is* random to them.
So when we are trying to make players understand the actions we give our NPC’s, we have to be doubly sure that they are capable of understanding the motivations for them.
How do players understand characters?
The player’s reading of any given action is coloured by many things. One of the strongest being the actual visual look of the NPC. We had a team at the University do some work a few years ago where they looked at the interactions between a group of test players with a number of differently designed NPC’s. The theory was that empathy could be induced by character design and behaviour. It turns out that a large part of the empathy players had for characters was based on their appearance.
In traditional animation, this is actually formalized as a concept called “appeal”. The psychology of this is quite well understood. Most appealing characters have open faces with large eyes and round heads. Often animation will use childish or “cute” proportions. But aspects such as clothing,posture and gender will also contribute to the appeal.
The second most obvious and important factor is movement. When I say movement, I am talking about things such as posture, gaze, gesture etc. The fact is, we communicate a vast amount of our character non verbally. We communicate with our facial expressions, with our gestures, our gaze and our posture far more than we communicate with actual words.
The psychologist Albert Mehrabian suggested that we communicate a huge amount of our emotional intent non verbally. He spoke of a 7%-38%-55% split between verbal, vocal and visual language respectively. The suggestion being that we use more than just words to understand the true intent of an interaction. Which is confusing, given that most games rely on textual or verbal dialogue to communicate intent.
Think about RPG’s and how dialogue heavy they are. Think also about how often you simply click away these dialogue items. Simply “hoovering” the options to set some flag for later progress.
If we accept the notion that players understand characters intention through movement, then how can we improve the players understanding of the man looking at the ground?
Let’s consider each case in turn:
He is interested in the composition of the ground
This one is relatively easy. You could have him walk around, looking at different areas of ground. Occasionally stooping to pick up a sample of dirt. You can use a prop that he brings out to look more closely at a sample. You could have him lift up stones on the floor and look under them. You could have him holding a book and comparing the sample to a page in the book.
He is afraid of you and is looking at the ground to avoid your gaze
Again, this one is relatively easy. You would have him use occasional glances up at you and quickly back down again if you are looking in his direction. You could alter his posture to be more wary and frightened. Perhaps supplicating himself with gestures and hand wringing. He would seek to avoid eye contact, but would definitely look up often to make sure you weren’t about to attack.
He is somehow compelled to look at the ground
This is the easiest one of all. You would fix the bug that made him look at the ground.
Conclusion
There is a great deal we don’t know about this whole conceptual area of interactive storytelling and drama. We intuitively feel that traditional media approaches to narrative break down fairly quickly, but as yet we haven’t built up a good enough knowledge of the principles we need to apply to the new medium of interactivity. We can definitely learn a lot from psychology and the principles involved in other media, like film, books and animations. But there is still a lot to explore.
StoryBricks as a concept, is a step towards exploring this new space. Of course the bricks themselves are just a small part of that space. We must investigate new methods of understanding the animation, behaviour and psychology of interaction.
Hopefully some of you reading this will come along with us as we explore this space together. As we develop the toolset, we will learn a lot about our understanding of characters, our ability to create performances that are comprehensible to others and perhaps as importantly we will learn how to create deeper and more meaningful experiences because of what we learn.
Sep 8th
It’s taken some time, but the squad code is now almost completely reworked. Originally I was thinking that I would use a central squad manager for all of the squad control, but in the end I didnt like that sort of implementation. Now I have a squadmanager (arranges who is in a given squad), a squad (the actual meat of the squad implementation) and a squadmember (the individual agent within the squad).
What that means, is that I can do things like add members to multiple squads, add new members to squads on-the-fly and generally allows the squad code to be a lot more focussed.
The other side to the squad code, is shown in the video above. Squad control is an important part of the game. I’ve been looking at the “move” control first, because its one of the most important. Here you can see some work on the cursor that controls the move. Starting off in third person (press space to enter third person with time stopped) you can select squad members, assign them to squads etc. You can also select squads (1..n) and then activate the move cursor to set where the squad is going. I’m going to try out a “facing” element to the cursor soon too. In the vid you can see me switch to first person and do the same thing. The idea of first person squad control is basically taken from Brothers In Arms, which was a really interesting game design-wise for me. I felt like it offered a nice mix of first person and squad control, but lacked some of the micro you sometimes want to do and occasionally felt a bit stunted in terms of real FPS feeling. Almost like you couldnt just blaze away, which is not a bad thing necassarily but sometimes you just want to blaze and I’m damn sure I’ll allow that in Damzel (which consequences of course).
Now that movement works ok, I’ll concentrate on adding the other commands (attack, defend, investigate etc), such that I’ll have a basic version of them all done asap, because they’ll take a lot of iteration to get right.
.
Mar 20th
There was a discussion on this during the AI roundtables at GDC about the Assasins creed not using IK for pushing characters. Well, here’s the video to prove it DOES use IK. Clearly the arms are IK’d towards certain points on the character to be pushed. Interestingly the people touched then play a reactive “move backwards” animation which is where you find the oscillation going on here I think. Anyway, score +1!

Enjoy.
Feb 7th
So, we promised that we would release the colonisation prototype from the global game jam (and AI game marmalade). Well, we’re doing just that. But before you get to having a look, we should discuss what you’re looking at.
Right now, this is a really rough prototype. It is also incomplete. The main issue is that colonies simply expand with no consequence for that expansion. The initial plan was to have four different types of AI entities (well, 5 if you count colonies), these were foragers for gathering resource, attackers (pretty obvious what they do), defenders (same) and finally pioneers. Pioneers are the expansion mechanism for colonies. So the plan was to have each colony contain resources. These resources would then be “spent” on the various population types. During development it seemed fairly obvious what pioneers did, in that you spawn them and they go out and try and create a new colony of their own. If they cannot start a colony (perhaps it is too close to another one) they simply join the colony that is closest to them, thus adding back to that colonies resource pool. At the current stage of development of the prototype, we have a bit of an issue with controlling colony expansion. Colonies simply increase their resources over time, this needs to be scaled by the number of foragers in the population. The other issue is that when colonies come into contact with one another, currently they simply overlap, whereas the design really calls for some aspect of competition here. The plan was to inititally spawn attackers and defenders and to have a mass skirmish, but that is a bit overkill. What we really need to do is to simply figure out the result of the competition between colonies, either a merger or a conflict.
Conflict should be decided on the balance of attackers to defenders. The winner of any conflict should take on the resources of the loser and the loser should disappear. Currently none of this happens as we’ve not quite figured out unity’s method of having colonies trigger each other when they touch. In all, as our first project using unity to prototype and considering we knew nothing about unity, C# or javascript (the languages used by unity to script the prototype) it went pretty well. Certainly it doesn’t achieve much yet, but we certainly made progress and have a clearer understanding of unity usage so things should speed up development wise when we next get time to work on this.
So right now the prototype is pretty dull, with just a few things you can alter.
1) You can change the rate at which population increases, 1 second delay is faster, 10 second is slower.
2) You can set a maximum population for pioneers. This controls wether pioneers can spawn (its safer to keep this number low).
3) You can set the maximum number of colonies. This helps make sure that the simulation doesnt completely collapse under the CPU load.
To be clear, if you set these sliders too high (for max pop/col counts) you WILL kill your CPU. It generally tends to be gradual, but just take care when using the webplayer version.
Controls in the prototype are WASD and right mouse button for looking around (we plan on using left mouse to select colonies later).
So, just so you can see where we’re at. Here are the different versions:
This is the standalone executable version zipped up.
Please take care when running these. They are very rough and ready.
Normally we’d end with “have fun”, but it doesn’t really count with the current prototype. BTW: No idea why these are now called population instead of colonisation. Temporary schizm.
Jan 30th
Ok, so colonies are setup. They spawn pioneers and you can control some options from the GUI (took a while and had to switch from C# to Javascript, neither of which we’ve used before).
Right now the pioneers just set off in random directions. They travel for a set amount of time and at a set speed. Then when they time out, they attempt to place a new colony. If the colony is too near another colony, they simply dont place the new one.
Next task is to add the colony sizing (colonies grow as resources allow) and the integration of pioneers such that if a pioneer cannot place a colony because of its proximity to a new one, the pioneer simply integrates back into the existing colony, adding to its population. Once we get that up and running and fix up a few UI issues so that there’s a maximum population and colony cap, we’ll put up a webplayer version. Never tried that before either 
Fun!
Jan 30th
So last time we talked about doing some social simulation. As ever time is tight, so we put off actually doing the work until this weekend.
We’re taking part in both the Global Game Jam and the Global Game Marmelade: http://aigamedev.com/open/upcoming/2009-marmalade/
As a fun little learning experience, we’ll be using Unity3D for this little test. Plus we’ll try and release some interim builds here on the blog. You’ll have to install unity web-plugin if you want to try them out, but I think the faster access to a demo build should be worth it.
So anyway, on with the show! First up is some kind of colony structure and the initial “pioneer” implementation. Colonies are representations of groups of people, pioneers represent the types of people who move away from the colony to start their own. Sounds like some kind of ant farm initially!
More soon.
Jan 20th
Right now there are a lot of reasons why we should be rethinking our approach to society. With the meltdown of international finance has come a need for re-evaluation of our social structures. Not least here in the UK where we are in a very poor position.
It started a chain reaction of thought, that led from the outer edges of the nations politics, to the very core of socialism vs capitalism and then deeper still.
Ultimately it led to this question:
Does land ownership lead to fundamental inequalities?
In order to explore that question, we’re putting together a prototype game concept that explores the absolute basics of population. It starts off with a model of a single civilised dwelling space and then models the spread of population from there. Here are the rules so far:
These simple rules should form at least the basis of the starting phase of population. There are other small rules involved about how far pioneers travel and how big populations can grow, but roughly the idea is that a certain amount of population is sustainable, but the concept of “growth” which is used throughout capitalist economies suggests that populations inevitably rise. This should in theory lead to imbalances in the population and more importantly the rise in increased population density in a concentrated mass of population.
It really is just a simple little prototype experiment. No particular goal other than to see what happens. If it turns out anywhere near interesting we’ll try and make it available somehow (maybe do a unity web-player version).
Anyway, need to go and work on population growth now. Video soon!