Wednesday, 18 May 2011

Final Dissertation


 Believable Characters that influence

a games storyline.

 

Alan Hepburn 0701628

 

Computer Games Technology

 

Institute of Arts, Media and Computer Games

University of Abertay Dundee



Table of Contents

Abstract                                                                                                         2
Introduction                                                                                                   3
Literary Review:        
AI                                                                                                                    4
Story                                                                                                              6
Personality                                                                                                    8
Emotions                                                                                                       12
Methodology:
Finite State Machine                                                                                   12
Decision Trees                                                                                             13
Personality Class                                                                                        14
Emotions Class                                                                                           16
Analysis:
Analysis                                                                                                         17
Results                                                                                                          17
Problems/Solutions                                                                                     18
Future Work                                                                                                  19
Conclusion                                                                                                   19

Appendices                                                                                                  21
References/Bibliography                                                                           25




Abstract
As computer game characters become more realistic in appearance the need for their actions to become more realistic increases. Modern role playing games(RPG) have made great advancements with the amount of options a player has to drive a storyline forward, however they are still having trouble with giving that same freedom, or at least the appearance of freedom to the non player characters(NPC) that often surround the player in RPGs. The player currently has the ability to manipulate the choices a NPC has, so that the player makes a choice and the NPC reacts, but what if the player did not have to make a choice before the NPC reacts, what if the NPC had the ability to react to the player's choices and the environment around it by making its own decisions.
This study has many different areas that could be explored and as a result this study should be focused on one of them.
·         Character Personality
·         Character Emotions
·         Decision Making
·         Dialogue
·         Character Relationships
·         Character Reputation
However this study's focus is on decision making with reference to multiple areas. To narrow down the scope of this study the multiple areas delved into were defined as a believable character. Believable characters are NPCs with personality and emotion that have aspects of character relationships and reputations. These believable characters are then applied to a storyline, the decision making aspect of this study, culminating in a decision making system that can influenced  a games story.
The results of this are quite interesting, seeming to imply that, the player would allow the NPCs to do whatever they need too, to move the game forward while when it comes to being the hero/main character and making the important decisions the player wants to be in complete control.
















Introduction
Modern computer games have one goal, to be as immersive as possible. The advancement of graphics and game play has come a long way since the first computer game was created, for the purpose of making games more entertaining. However as graphics and game play have become more realistic and more entertaining the immersive aspect of games has fallen. This is a result of artificial intelligence(AI) in games being left to become dated in comparison. AI is used in many areas of computer game programming, from creating challenging enemies to creating believable companion non player characters(NPC) and badly programmed AI can seriously damage the immersion a computer game is trying to create, ruining the game's entertainment value. The main problem with bad AI is not the enemy AI, even badly programmed enemy AI can be defeated, giving the player some sense of satisfaction, but a badly programmed companion NPC can become more trouble than their worth. This view has been supported in the work of Ernest Adams(2008).  Adams(2008, p.2) quoted Shawn Lucas(2008) for giving examples of poor companion AI:

"...a good example from The Elder Scrolls IV: Oblivion: "I remember a quest where the player was tasked with rescuing a peasant girl who had been kidnapped by a group of cultists. After journeying to their hideout and freeing the girl from her cell, I attempted to flee with the prisoner. However, it seemed that the girl was more interested in attacking the hostile cultists than she was in getting to safety. The second she spotted one of the cultists she attacked him and drew other enemies to our position... it put me off from playing the game"

Companion NPC's are required to be realistic and act like whatever they represent, human or animal alike. Acting like a human or animal might be described by the way they move or interact with the environment, however their ability to make decisions are what really define a realistic or believable character. Believable NPCs are essential for creating an immersive environment for the player. NPC's, especially those that have an active role assisting the player, must be believable so that the player can maintain a willing suspension of disbelief, the player would perceived it as lifelike, a real being(Zammitto, DiPaola and Arya 2008).

Creating believable characters, was usually done by creating better graphics so when a player looked at a NPC they saw a detailed character staring back at them and that, at the time was good enough. However today graphics show very realistic characters and players now expect these characters to not only look realistic but to act realistic as well. To do this NPC's have become more human. Taking human aspects such as personality and emotion and programming NPCs to emulate these aspects. Emotions are a key factor humans use to recognise other humans (Lankoski, 2007 and Björk, 2007), as such they are a fundamental requirement of believability. They are expressed through outward appearance and behaviour and used internally for perception, reasoning and decision making and as a result share a connection with a character's personality (Baillie 2002).
Personality represents a character's behaviour, how they react and express emotions. Each character can have a unique personality, which would influence the characters decision making process and what emotion the character is feeling. This would allow for each character to be an individual and to produce different emotions for the same situation.

To show these individual personalities and emotions characters must be introduced to a situation. Computer Games provide these situations in the form of a story. Many genres of computer games, such as first person shooters and strategy games, have a linear storylines so a characters personalities and emotions are often scripted, not allowing characters to make their own decisions. In a genre such as role playing games(RPG) on the other hand NPC involvement is a key factor in a players immersion into the game world. As a result these NPCs are capable of having a much greater influence over the storyline.

These decisions however are still limited, the goal of this study is to explore ways in which a believable character could further influence a storyline.

            "Can a believable character, with personality and emotions be created that can
            actively and realistically effect consequences in a game's story?"

To do this a variety of AI techniques and methods will be used along with an interpretation of psychological techniques used to define personalities and emotions. The following are the AI techniques that will be used in this study:
·         Decision Trees: Used to define the story, producing different choices for the player and the NPCs to decide how the story progresses.
·         Finite State Machines(FSM): Used to allow the NPC's to use their emotions and skills to make decisions.
The following are the psychological techniques that will be used in this study:
·         The Big Five Personality Factors: Used to determine a NPC's personality.
·         The 16 personality factors(16PF): Specifically the factors that relate closest to emotions to add more relevance to the big five in determining emotions.
·         The 6 basic emotions: Used to influence decisions.
It is the aim of this study to produce a way that a NPC can have an active influence over a games storyline, that is realistic but still leaves the player feeling like they are the main character of the story.

Literary Review:
AI
The need for realism in games has grown over the years. Usually that realism is restricted to the way a game character looks however there is now a need for them to not only look real but act real and that is where AI comes in. AI is a fairly resent term, formally referred to as "game play programming" because there was not anything intelligent about the behavior of CPU-controlled characters(Schwab. 2004). Pong would be an example of a game with no real AI even though the player is against a computer and could be classed as game player programming rather than AI. However as games evolve so does the methods and techniques for creating realism. Space invaders shows the next step in the creation of AI where patterns are used in an attempt to make enemies more challenging, allowing them to move and attack the player. Although not truly AI the patterns in these early years shows the potential for further research and eventually the modern day AI is created. Doom has the first real example of AI with creatures able to attack and move freely, with different attributes for each type of enemy and varying degrees of difficulty. This is an example of FSM and modern day AI. With the creation of FSM there came the ability for computer games characters to have choices, to be able to react to the players actions and to perform simple tasks leading to other techniques, expanding AI to what it is today. Schwab (Schwab. 2004) gives the following examples:
·         Battle Cruiser: 3000AD is the first use of neural networks.
·         Half-Life, praised for its AI,  used scripting to make it feel more intelligent.
·         Black and White, with its in-game creatures that use reinforced and observational learning to bring about highly emergent behaviors.
AI is the way programmers add the illusion of intelligence to a character(Scott, 2002). It is defined as the theory and development of computer systems able to perform tasks that normally require human intelligence, such as visual perception, speech recognition, decision-making, and translation between languages. The problem with trying to represent human intellect is that humans are very complicated, so the time and cost associated with creating a human intelligence is far beyond what is necessary for a game character. The compromise is to use AI techniques and methods to imitate human intelligence enough so an NPC acts like a human and convinces the player that it has human intelligence. 
For an NPC to act like it is human it must be able to do certain aspects a human can do for example primitive behaviour, the ability to pick up objects or make gestures, movement, the ability to move from one point in a room to another or move from one town to the next and decision making, the ability to use high-level decision making to take actions, accomplish tasks and in what order to do so(Champandard, 2004).  This gives way to many different areas of AI such as:
·         Path finding: This is where a game character finds its way from one point to another avoiding obstacles in the terrain.
·         Combat AI: This is where a game character attacks a player while avoiding the player's attacks and devising strategies for defeating or in some cases helping the player.
·         Emotion: This is where a game character uses high level decision making to determining what emotion it should be emulating and as such what action to take.
All of these factors are necessary when trying to create a believable character for modern games. The future is giving these characters the ability to act on their own rather than having their reaction scripted for example games such as Mass Effect, Fallout 3 and Dragon Age, while heavily scripted do try to give the NPCs the ability to act. While this could mean having them move quicker when scared or attack more fiercely when angry it all adds to the illusion of intelligence. In the game Dragon Age 2 they have also giving the NPCs a choice, although still controlled by the player. The player has the option in some cases to allow the NPC to make their own decision or act the way they want to. If a NPC thinks that another NPC should be killed the player has the option to let them kill it. Giving the NPCs this choice greatly increases the realism of the game and the way the player reacts to these characters. To do this various AI techniques, such as finite state machines(FSM) and decision trees and methods such as the personality formula and "pancaking" scripted sequences, are used.

Story
The story is an important part of any game, however it is more so in some than in others. Puzzle games for example may have no story at all except to solve the puzzle while a story is the main part of an RPG. Unlike other media such as books and movies which have linear storylines, a game is interactive so the player can have many choices as to what to do even if they are following a linear storyline. The player may find multiple different routes to get to the same point on a map, but reaching that point is the only way to continue the story. For replay ability in games, especially in RGPs there must be multiple routes in the story not just in the game play and in essence this is the true advantage games have over other media. By making choices in games, they change the effect they have on a games story, allows for the player to experience the game in different ways each time they play. As a result of this choice there is a distinct problem with a games story compared to other media, the plot, referencing Freeman(2003, p.200) states: 'Plot suggests events moving in a straight line, it suggests external control, and it suggests order. Game suggests something open-ended and chaotic. It suggests fun and play. Putting "plot" and "game" together is like trying to combine order and chaos.' As such when creating a story for a game you must think in terms of moments. Rather than a linear story in movies and books, games need a moment where the player attains information and direction but then it is up to the player to take that information and move onto the next moment in any way they see fit. For example the player learns that there is a door that needs opening, in a book or movie the only way to open the door is the way it is written, however in a game the player can find multiple ways to open the door like finding the keys, breaking down the door or even finding a way to get round the door without opening it. Freeman(2003, p.202) gives examples of the different type of story structures used in creating a game story:
Structure
Scenario
Linear
I want to get to the 7-11, which is a mile away. I can only walk only along one path. Along the way, I'll encounter obstacles and enemies.
Nonlinear
I walk out of my front door, but can go any direction. There are many things for me to do that are fun and adventurous. At some point, I'll learn that there is such a thing as a 7-11, which I may elect to visit, or may never visit.
Linear/Nonlinear
Halfway between home and the 7-11 is a bridge I need to cross. I go there but it's blocked. I need to find a number of objects, pieces of a
code, clues, etc. to be able to get across the bridge.
So I go back and explore my neighbourhood, enjoying various adventures, collecting clues, fighting enemies, and polishing my skills.
These activities can be done in any order. Eventually I learn, retrieve, or attain whatever I need to get over the bridge.
Multi-mode
I can make it to the 7-11, but laying in wait are a spectrum of enemies and obstacles. I have a wide range of weapons and spells I can use for offensive or defensive purposes, and I must select among them.
Furthermore, I have different styles of making it to the 7-11. For instance, I can sneak there and try to not alert attention. Or I can unleash my firepower and act like the Grim Reaper's bastard stepchild.
Linear/Multi-path
I can go to the 7-11, but when I come to the bridge, I find that there are actually two bridges, going off in different directions. I have a choice, but they'll both end up at the same place in the end.
Linear/Multi-endgame
As I get toward the 7-11 along a linear path, near the end, I have a choice of which direction to take. One takes me toward the 7-11, and the other takes me to its arch-rival, the notorious Circle-K store.
Modular
I can make it to the 7-11, fighting all sorts of baddies along the way. There are other missions to run as well. They can be run in any order. Each is a complete adventure unto itself. The missions are only loosely related to each other.

Most games are a combination of these structures, plus an added twist or innovation added by the game designer. While using these structures there are many different methods that can be implemented to add to creating a story. One such method is pancaking scripted sequences. This method has been implemented into this study. Pancaking scripted sequences involves using multiple options to alter the story as it goes along. For example the application created for this project starts by being given the background, which is to get through a door, and three options:
·         Check the surroundings.
·         Talk to the people.
·         Talk to your companions.
By choosing option one the player get a description of the surroundings and more choices which, in this case, are added to the previous list minus the option to check surroundings. However when choosing option two the player will talk to the people around them and gain a certain amount of information from the different sets of options which, in the end will produce similar results as if they were to have chosen the first option. From the first "moment", where the player begins, the application uses the pancaking method to produce different story options that all lead to the same or a similar, second moment. This gives the illusion that the player has a choice with what happens, giving them a greater feeling of control. This gives games a replay ability as on the second play through the player can choose a different option from the first play through and experience the same game in a different way. Other methods can add depth to characters through the story such as allowing the other characters to read the players mind, about what they want to do next, also they can share a common goal to try and cause the group to bond. All these methods add to the immersion of a story and creates a better environment for the player as their choices really matter.

Personality
Personality is not an easy thing to define. While most of us have an intuitive understanding of the meaning of "personality", defining this term is considerably more difficult (Ewen,1984 p.2). The problem is that a person's personality covers a wide range of factors such as how a person appears to others, which is an observable factor while it can also involve what type of upbringing they have had and the uniqueness of a person, which are unobservable factors. For this study, how a person appears, is perfect as the player will react to what they can observe while things like uniqueness and upbringing can be implied through dialogue or story. To many psychologists, the acid test of any theory is its ability to predict future events(Ewen, 1984 p.3). If a capable personality is implemented in a game it would add, not only unpredictability but a more natural predictability .For example if a character was angry about an event and a similar event happened the player would assume that the character would be angry. However a character could learn from his past actions so might not get angry at all but the player will know that the character wants to be angry. This example shows that both predictability and unpredictability can be achieved by implementing a personality into NPCs. To add a personality to a NPC there must be a structure and a formula to determine the effects of the personality. There are three personality theories that are intertwined that would help structure a created personality:
·         The Big Five Personality Traits.
·         The 16 Personality Factors.
·         The NEO(Neuroticism, Extraversion, Openness)-Five Factor Inventory.
The big five personality traits was determined by a group of prominent researchers, Lewis Goldberg, Naomi Takemoto-Chock, Andrew Comrey, and John M. Digman, who analysed the personality tests of the day and discovered a correlation between certain factors, they grouped those factors together to give the big five personality traits.
1.       Extraversion: This factor is the combination of extrovert and introvert. Extrovert is characterized by positive emotions and a tendency towards being social and perceived to be energetic. Introvert is characterized by a lack of energetic tendencies and being quiet and less social, this can also be related to shyness and depression.
2.       Agreeableness: This factor is a combination of agreeable and disagreeable. Agreeable is characterized by a tendency to be compassionate and cooperative rather than suspicious and antagonistic towards others. Disagreeable is characterized by self-interest and scepticism, with a less likely chance that they will help others.
3.       Conscientiousness: This factor is characterized by self-discipline and self-control and shows a tendency to plan rather than take spontaneous action.
4.       Neuroticism: This factor is characterized by negative emotions, also referred to as emotional instability. A high neuroticism factor will increase the likelihood of becoming easily upset and vulnerable to stress. A low neuroticism factor are less likely to become upset and tend to be calm and free from persistent negative feelings.
5.       Openness: This factor is characterized by who open someone is to emotion, adventure, unusual ideas an imagination. This is the factor that is the difference between imaginative people and down to earth people. A high openness factor tends to imply a more creative person with unconventional beliefs while a low openness factor tends to imply a more conventional, straightforward person.
The big five is a conceptual tool that permits psychologists to describe personality with precision, relevance and simplicity(Monte, 1999 p.25). Although there is a consciences among psychologist about the relevance of the big five there are limitations and weaknesses one such being that it is surprisingly open to creativity and subjectivity(Monte,1999 p.24). As such, to use this model efficiently there must be other considerations to take into account.
The 16 personality factors(Cattell, 1946) are the basis of the big five, the sixteen factors can be grouped together into each of the categories of the big five.  
Descriptors of Low Range
Primary Factor
Descriptors of High Range
Reserve, impersonal, distant, cool, reserved, impersonal, detached, formal, aloof (Sizothymia)
Warmth
Warm, outgoing, attentive to others, kindly, easy going, participating, likes people (Affectothymia)
Concrete thinking, lower general mental capacity, less intelligent, unable to handle abstract problems (Lower Scholastic Mental Capacity)
Reasoning
Abstract-thinking, more intelligent, bright, higher general mental capacity, fast learner (Higher Scholastic Mental Capacity)
Reactive emotionally, changeable, affected by feelings, emotionally less stable, easily upset (Lower Ego Strength)
Emotional Stability
Emotionally stable, adaptive, mature, faces reality calm (Higher Ego Strength)
Deferential, cooperative, avoids conflict, submissive, humble, obedient, easily led, docile, accommodating (Submissiveness)
Dominance
Dominant, forceful, assertive, aggressive, competitive, stubborn, bossy (Dominance)
Serious, restrained, prudent, taciturn, introspective, silent (Desurgency)
Liveliness
Lively, animated, spontaneous, enthusiastic, happy go lucky, cheerful, expressive, impulsive (Surgency)
Expedient, nonconforming, disregards rules, self indulgent (Low Super Ego Strength)
Rule-Consciousness
Rule-conscious, dutiful, conscientious, conforming, moralistic, staid, rule bound (High Super Ego Strength)
Shy, threat-sensitive, timid, hesitant, intimidated (Threctia)
Social Boldness
Socially bold, venturesome, thick skinned, uninhibited (Parmia)
Utilitarian, objective, unsentimental, tough minded, self-reliant, no-nonsense, rough (Harria)
Sensitivity
Sensitive, aesthetic, sentimental, tender minded, intuitive, refined (Premsia)
Trusting, unsuspecting, accepting, unconditional, easy (Alaxia)
Vigilance
Vigilant, suspicious, skeptical, distrustful, oppositional (Protension)
Grounded, practical, prosaic, solution orientated, steady, conventional (Praxernia)
Abstractedness
Abstract, imaginative, absent minded, impractical, absorbed in ideas (Autia)
Forthright, genuine, artless, open, guileless, naive, unpretentious, involved (Artlessness)
Privateness
Private, discreet, nondisclosing, shrewd, polished, worldly, astute, diplomatic (Shrewdness)
Self-Assured, unworried, complacent, secure, free of guilt, confident, self satisfied (Untroubled)
Apprehension
Apprehensive, self doubting, worried, guilt prone, insecure, worrying, self blaming (Guilt Proneness)
Traditional, attached to familiar, conservative, respecting traditional ideas (Conservatism)
Openness to Change
Open to change, experimental, liberal, analytical, critical, free thinking, flexibility (Radicalism)
Group-oriented, affiliative, a joiner and follower dependent (Group Adherence)
Self-Reliance
Self-reliant, solitary, resourceful, individualistic, self sufficient (Self-Sufficiency)
Tolerated disorder, unexacting, flexible, undisciplined, lax, self-conflict, impulsive, careless of social rues, uncontrolled (Low Integration)
Perfectionism
Perfectionistic, organized, compulsive, self-disciplined, socially precise, exacting will power, control, self –sentimental (High Self-Concept Control)
Relaxed, placid, tranquil, torpid, patient, composed low drive (Low Ergic Tension)
Tension
Tense, high energy, impatient, driven, frustrated, over wrought, time driven. (High Ergic Tension)
Contributions and Limitations of Cattell's Sixteen Personality Factor Model, 2004, Heather M. Fehriinger. Available as:<http://www.personalityresearch.org/papers/fehringer.html>[Accessed 12 March 2011]

As these factors are involved in the big five any formula created by using the big five can be tailored to specific means for example using emotion as a defining feature, by taking all the personality factors that correspond to emotion from the 16 personality factors, Dominance, Liveliness, Apprehension, Sensitivity and Abstractedness we can have the personality formulas, also used by Cattell, to determine a person's emotional state. Even though Emotional Stability is relevant to emotions it is a generalized factor and is included in the big five, also the other factors can be assigned a corresponding emotion(s). The specification equation used by Cattell is as follows:
            P1 = b1T1+b2T2 + ... + bnTn
P1 is the result predicted by a given situation. Tn is the Trait and is repeated for whatever traits are relevant to the situation and bn is the magnitude or intensity of each trait. This brings up the question of how to define the intensity of an event.
The Neo-Five Factor Inventory was developed by Paul T. Costa, Jr. and Robert R. McCrae to determine the effect of personalities on age. The brought to light the importance of the big five personality factors but also the need for the lower factors to be included when determining results. These "lower" factors were split into six facets for each of the big five:
1.       Neuroticism
1.       Anxiety
2.       Hostility
3.       Depression
4.       Self-Consciousness
5.       Impulsiveness
6.       Vulnerability to Stress
2.       Extraversion
1.       Warmth
2.       Gregariousness
3.       Assertiveness
4.       Activity
5.       Excitement Seeking
6.       Positive Emotion
3.       Openness to experience
1.       Fantasy
2.       Aesthetics
3.       Feelings
4.       Actions
5.       Ideas
6.       Values
4.       Agreeableness
1.       Trust
2.       Straightforwardness
3.       Altruism
4.       Compliance
5.       Modesty
6.       Tender mindedness
5.       Conscientiousness
1.       Competence
2.       Order
3.       Dutifulness
4.       Achievement Striving
5.       Self-Discipline
6.       Deliberation
By using these factors we can add them to the formula by saying that for every situation some of these facets will be used. Depending on how many are used the intensity can be determined for example if someone is has been stolen from this would involve, Anxiety, Hostility, Depression, Self-Consciousness and Vulnerability to Stress, five of the six facets of neuroticism which would make the intensity of neuroticism 5/6 which gives 0.833.
Using these three personality theories will give enough of a specific answer that personality can be defined. Once defined the information can be used to create a character with its own unique personality.

Emotions
By adding emotions to AI it is possible to have game characters react in a more believable way. AI is all about the choices made by the game and the game characters, usually they are not really choices but what the designer thinks the character should do, but giving the AI emotions with give it the ability to make these choices on its own. For example having an enemy general that cares about the troops he sends to battle will make it feel more realistic to the player rather than an enemy performing the perfect strategy and sacrificing lives. On that note however they may find this unusual as they perceive an enemy general as being cold and willing to do anything to win. This could also be countered by giving him a short fuse so if he suffers a setback he gets angry and retaliates more ferociously which would give way to a need for the player to think differently when fighting that enemy. For people it is relatively easy to determine what emotion a person is feeling however scientific evidence suggests that measuring a person's emotional state is one of the most vexing problems in affective science(Mauss, 2010; Robinson, 2010). While referencing Darwin (1872/1997) Ekman (1972) theorizes that there are six basic emotions, six emotions that are clearly visible on a person's face.
·         Anger
·         Disgust
·         Surprise
·         Happiness
·         Sadness
·         Fear
As these emotions are clearly visible they can be used to demonstrate a reaction to an event, not just through their facial expression but through their behaviour. Having a character act on their emotions is what can bring them to life. Being able to relate a character's actions to a humans can create a bond between the player and his companions. For example in a online first person shooter, where there are teams of between two and five real humans interacting one may feel anger at one of their friends or team mates dying where they may take revenge focusing on killing the players that killed their team mate rather than simply killing for points. Having the same emotional response in NPC would allow for the player to feel anger for the NPC's death just as the NPC had for theirs.   

Methodology:
Finite State Machine
Finite state machines(FSM) are a industry standard in decision making algorithms. It is the basics when it comes to having a NPC choose actions to take in games. The NPC has different states, such as attacking, wandering or idle, also can be based on emotion, such as angry, happy or sad. If these states are true or false the NPC takes an action. There are two forms of states when it concerns the if then statements normal states and transition states. The normal states are usually changed by the FSM itself such as switching from attacking, wandering and idle. Transition states are usually changed by variables in the application such as if the enemy is out of sight or out of range. For example if a NPC is in the attack normal state then it takes the action of attacking the opponent and if a NPC is in the angry transition state then it can take the action of attacking. When actually programming this FSM it is easier to create a switch block to manage the actions. Creating a set of if then statements and setting the resultant action to be a case in the switch block. As in the example above the if then statement is, if attack then and if angry then, both could result in the switch block case of take attack action. In relation to the application FSM is used to create an initiative system where each NPC and the player is given a randomly generated number. This number is a state, defined in the application as if the randomly generated number is greater than the previous character's generated number and once all characters have been checked, they can take an action defined by the switch block. Whatever case in the switch block is chosen results in a second FSM where there is a check for emotion. If the characters state of emotion is not normal it can take an action. In this system there are no normal states, as the FSM does not change other states, however there are two transition states.

Transition State of Highest Random Number for:
Transition States
Has a strong Emotion
Doesn't have a strong Emotion
Character 1
Character 1 take action.
Player takes action.
Character 2
Character 2 take action.
Player takes action.
Character 3
Character 3 take action.
Player takes action.
Character 4
Character 4 take action.
Player takes action.

Implementing a FSM allows the illusion of intelligence from a NPC, in this case it gives the illusion of a NPC acting on its emotion, when actually it is taking an action based on mathematical calculations.

Decision Trees
Decision trees are a hierarchical graph that structure complex Boolean functions and use them to reason about some situation (Bailiie-de Byl, Penny. 2004. pg. 265). This AI method can be used to create different paths for a games story and is used in the application. It can and most often is used to enable NPC learning by allowing the NPC to determine different reaction. With determining what a NPC would like to eat, there are boolean values, true or false, similarly used in the creation of a FSM and variables that can be used with a decision tree to determine if a NPC will eat something. For example, a cow will have a boolean value for hunger if it is true then it moves on to choosing a variable for food in this example rock, if rock has a taste variable of over zero then the cow will eat. If the result is not over zero the decision tree moves back a step changing the food in this case to grass if it has a number over zero then the cow will eat. Using this method for creating a story is slightly different.
First, instead of a boolean value for determining hunger the player is given part of the story. Once the player has read and understood this part of the story, you could say that the boolean is now true and the player is given options much like choosing the variables for what food to eat. The player makes his choice of where the story is heading and gets the next part of the story. Here is where the taste variable comes in but this time its whether the players choice has continued the story or has just received information. If the player has continued the story the cycle starts over, giving the player more of the story and more choices while if the player has just gained information the decision tree moves a step back and the player gains access to the previous list of choices much like with the food variable the player has the option to choose a different option (grass instead of rock). The advantages and disadvantages of using decision trees are:
Advantages:
·         Provide a simple representation of complex boolean functions.
·         Can be updated to include new information as the program is running.
·         A better way of navigating states than using FSM.
Disadvantages:
·         They are unique so the same tree cannot be used for other purposes.
·         They require more coding than a FSM.
·         Take up more memory than a FSM.
·         Have a Higher CPU cost than a FSM.
Even with the disadvantages decision trees hold the possibility for real in game learning. Applying this to creating a story could have many positive results other than its efficiency, such as, in the applications case the ability to the player to gain information to be used at another stage in the decision tree.  An example from the application is when the player talks to the Guard Captain they have to convince him to let them into the castle, if they have chosen other paths before talking to him, such as talking to the barman, they will have learnt they can convince him they are merchants which would not have been there if they had not chosen to take that path of the decision tree first.

Personality Class
Implementing the personality model(s) described above needs two functions, one to determine the intensity of each personality factor and one to implement the intensity. Also the personality factors need to be initialized for each NPC. When the personality class is created the personality factors are coded. As above there are ten factors that need to be initialized the big five personality factors and the five emotional factors from Cattell's sixteen personality factors. This is determined by whatever type of personality you want to invoke, each factor is set between zero and one. For example Character 1 has the following factor values:

Personality Factors
Factor Values*
Negative(0.1-0.4)
Neutral(0.5)
Positive(0.6-1.0)
Description:
Description of Low Range.
Description of High Range.
Extraversion
0.5
Neutral
Character is not easily depressed.
Character is not especially social.
Agreeableness
0.5
Neutral
Character is not especially selfish.
Character is not easily compassionate.
Conscientiousness
0.9
High Positive
Character is not spontaneous.
Character has a lot of self control
Neuroticism
0.5
Neutral
Character is not especially calm.
Character is not easily upset.
Openness
0.2
Medium-High Negative
Character is down to earth.
Character is not very imaginative.
Sensitivity
0.1
High Negative
Character is very Objective.
Character is not Sensitive.
Dominance
0.5
Neutral
Character is not especially submissive.
Character is not especially Dominant.
Liveliness
0.7
Medium-Low Positive
Character is not especially serious.
Character is rather cheerful.
Apprehension
0.3
Medium-Low Negative
Character is rather confident.
Character is not especially insecure.
Abstatedness
0.4
Low Negative
Character is kind of practical.
Character is not especially imaginative.
*There is no value for 0 as no one has a personality factor that does not affect them.
This shows that for each personality factor they have a low range and a high range. Determining these values for each character creates the values. Working backwards, decide if the character is at the low range or high range of the personality factor, then determine to what effect, a low negative range, a neutral range, a high positive range or anywhere in-between. Finally produce a value that corresponds to that effect, to get the personality factor value used in the personality formula.
Even though the factor values are defined they are not all influenced the same way by the same situation. This is where the intensity of the factors comes into play. For each situation the intensity of each personality factor is different, to determine the intensity, as stated above the NEO-five factor inventory is used. Taking the six facets of each factor and determining if they are true for the event can determine the intensity. For example, if an event would cause anxiety, hostility, depression, self-consciousness, impulsiveness or a vulnerability to stress, for each one that is true the intensity value is increased then a percentage, out of a hundred, is defined, so if five of them were true the intensity value would be 5/6 to give 0.833 or 83%. This percentage is then used with the personality factor to give the true personality factor for the event when compared to character 1 this would give 83% of 0.5 giving the true personality factor as 0.415. For the application these facets were generalized to make it simpler to implement. A high negative event for example would have high Neuroticism, low Extraversion, a high Openness, a low Agreeableness and a  low Conscientiousness. For the five emotional factors from the sixteen personality factors they each correspond to a member of the big five so their intensity was determined by the intensity of the corresponding big five personality factor intensity. This fulfils the first part of Raymond Cattell's personality formula where each relevant personality factor is multiplied by a intensity(referred to by Cattell as a weight).



Emotion Class
To determine a NPC's emotion the formula devised by Cattell can be tailored to produce a result for an emotion. As stated above the emotions used are all the emotions visible on a person's face, anger, disgust, fear, happiness, sadness and surprise. The personality formula for each emotion are as follows:
·         Fear:Neuroticism-Extraversion+Openness+Agreeableness-Conscientiousness+Apprehension.
·         Anger:Neuroticism-Extraversion+Openness-Agreeableness-Conscientiousness+Dominance.
·         Happiness:-Neuroticism+Extraversion+Openness+Agreeableness-Conscientiousness+Liveliness.
·         Sadness:Neuroticism-Extraversion+Openness-Agreeableness-Conscientiousness+1-Liveliness.
·         Surprise:Neuroticism-Extraversion+Openness-Agreeableness-Conscientiousness+Abstractedness.
·         Disgust:Neuroticism-Extraversion+Openness-Agreeableness-Conscientiousness+Sensitivity.
The formula for fear is based on the idea that fear is a negative emotion so neuroticism is the first factor then as extraversion is a person's positive emotion it is subtracted. Openness and conscientiousness are constant for all emotions as openness is how open you are to all emotions and conscientiousness is the self-control of a person, so openness is always added and conscientiousness is always taken away. The final of the big five is agreeable and in the case of fear it is added as when a person is scared, feeling fear they become more agreeable and self-interested. The final part of the formula, as stated above, is the personality factor from the sixteen personality factors that corresponds with fear which is apprehension which represents worry and guilt as a result is added onto the formula.
The formula for happiness is similar, however neuroticism, the negative emotions are subtracted from extraversion, the positive emotions and the factor that corresponds with happiness, liveliness which in a sense is the representation of happiness.
The formula for sadness, disgust and surprise are the same, except for their corresponding emotional factors, neuroticism first then extraversion is subtracted from it adding openness, subtracting agreeableness and conscientiousness then adding either, one minus liveliness as it is the opposite of happiness, for sadness, abstractedness which represents absent mindedness for surprise and sensitivity which represents how tough or tender minded a person is for disgust.
The personality factors used for these formulas are the result of the personality class, which include the result of the previously stated intensity factor. The result of these formulas gives a value to each emotion. As a result, the emotion the NPC is feeling, is found by determining the highest value returned by these personality formulas.
  




Analysis:
Analysis
The purpose of this project was to see if a believable character with personality and emotions can influence a games story. To do this there needed to be a way to determine what a believable character would actually do. This was done by playing a tabletop game where there are human players that can all influence the game's story. As a tabletop game produces the same system that was to be created, only with human players rather than NPCs, it is a good way to determine the successes, failures and drawbacks of the system.
Also influencing a game's story is usually done by the player or a scripted event, the system that was created needed to be compared with what is usually done for creating a game's story. So an application was created to be the base, with the typical system, of the player controlling events and the NPC responding but taking no action. This would help determine what effects having a NPC taking independent actions would have on the way the game is played, to what the player thinks and to what the player feels.
The final system created allowed for NPCs to take independent action controlling the way the story progressed in the same way the player could. Although mostly a random choice generator it would still allow for the NPCs to show they have control as all the options are a viable choice to produce a result from the story. As previously stated this application is based on the no action application but with the added FSM that decides if the NPC will take actions.
Throughout both applications there are constant classes, they are the event, personality and emotions classes. Through these classes the NPCs produce an emotional result that the player can see and can influence the player in multiple different ways for each system. The no action application can show what it is like to have NPC demonstrate emotion, just like the player would to an event. The action application can show what it is like to have others in the game that can take actions, just like the player.
The result of this project is determined by a comparison between the three games played. Having a real account of what multiple players can do, compared with an application where a single player is supported by other characters, both of which are also compared with a programmed application replicating the real game.
   
Results
Tabletop Game Compared to No-Action Application
The results that were observed when comparing the tabletop game to the no action application are as follows:
·         With each character/player showing emotion it increases the immersion of the game. As with the tabletop game having every character expressing an emotion allows for a connection to be made with the other characters over their shared experiences.
Tabletop Game Compared to Action Application
The results that were observed when comparing the tabletop game to the action application are as follows:
·         Scripting all possibilities that could come up in the table top game would be far too time consuming and expensive to implement in a games story line.
·         The creativity of players and their ability to work together and interact is impossible to completely recreate in a game.
·         Having the NPC perform simple actions or make simple decisions adds to their believability as with the table top game, any player can make the obvious decisions. This also gives an opportunity for writers to have the NPCs direct the story the way they need it to go rather than having the player find the right way or come up against dead ends.
·         Taking control away from the player for major decisions damages the game as with the tabletop game all players can come to a consensus or have an idea about where the other players want the game to go, this same feeling cannot be reproduced with NPCs as they cannot sense or feel what the player is feeling and programming all the possibilities that player may think of, so the NPC can react to them, would be far too difficult on top of everything else that would be necessary to program it efficiently.
No-Action Application Compared to Action Application
The results that were observed when comparing the no action application to the action application are as follows:
·         Even when an NPC takes action, under an emotional influence, it is still not as realistic as it should be. Having all the possible variables to determine what action to take would be a necessary step in determining the right action for the right emotion. However this produces a cycle that would result in an NPC taking a scripted action every time, resulting in the whole process being irrelevant. Even if AI methods were implemented, such as fuzzy logic or decision tree learning, to produce different actions it would still not be truly realistic and would result in unpredictable behavior that was wrong or predictable behavior that results in the games story becoming linear and boring for the player.

Problems/Solutions
There were two main problems that arose during this project, one concerning creating the application and one concerning determining how to interpret the results. While programming the application, it was found that creating a decision tree for the games story was far more problematic than first theorized. First there was the way devised to navigate the nodes of the decision trees. Using choices to move from one node to the next brought up the problem of how to check to see which choice was chosen and how to make sure the same choice was not chosen twice. This was resolved by applying boolean values to each choice, one for if the choice was chosen and one to determine if it is permanent or not. After fixing this problem another, and probably the most difficult problem to get around was the fact that to program all the possible events and choices and determining which choice lead to what event would be very time consuming, even with the different methods for creating a games story that were researched. The problem was overcome by determining a system for the programmer where each event was given a number and the corresponding event was put underneath the current one, for example event number 1 had event 2, 3 and 4 put underneath it. Then event 2 had event 5,6 and 7 put underneath it with a tally being taken to determine which event to continue on from. Although an efficient method, it does become complicated the more events are created.
The problem for the project, when determining the results was that there are no numerical values that can be interpreted differently. So without a numerical method for determining the result of the project it was left to find results from the observation of the application and to find something to compare it to. Having determined observation to be the way to gain results parameters had to be specified to determine the relevance of what was observed. The solution to this problem was a tabletop game as it was a similar idea to what was trying to be accomplished. Also as a control method a similar application would have to be created that was what is already used in the games industry. These two parameters were suitable to determine results that would give a relevant indication of the success or failure of the project.

Future Work
There are many areas relating to having an NPC act more human like. However there are two that are really shown to have potential as a result of this project. Mood and prediction.
During the analysis of the no action application it showed that having the NPC produce emotions for each event add a believability to the NPCs, as a result, it can be assumed that if they produced a mood at all times and had that mood added to their actions and reactions would also increase the immersion shown by having the NPCs show emotion.
What was also observed is that, rather than NPCs acting on their own, having the NPC act with the player is more believable and more achievable. As a result being able to predict what the player is thinking and having NPCs use this information would be greatly beneficial. By learning what a player is thinking, possibly by testing them early on in the game would allow the NPCs to take actions the player may have decided to anyway allowing for the NPC to bond with the player as they "think" alike or subverting this by having a NPC do the opposite to what the player would do, to cause conflict between the player and the NPC.
These methods would apply the concept of emotions and NPC personality but retain the ability for the programmers and writers to have control, possibly even greater control than before.   

Conclusion
To conclude this project showed how effective a NPC with personality and emotions can influence a games story. Trying to program a human-like intelligence into a game character is a difficult thing using psychology and programming together is like putting a square block into a triangle hole. Psychology is based in theory and the unpredictability of peoples personalities and emotions while programming is logical and maths based. Trying to merge the two, although necessary for creating a human like intelligence, cannot be done properly with such little understanding of a human's thought process. The best that can be done is to give the illusion that an NPC has human-like characteristics and a hope that the player will hold a willing suspense of disbelief.
On that note, including in games, the ability or even the illusion that a NPC has control can be a great benefit to not only the player but also the writers and programmers. Having the illusion of emotions in NPCs can increase the bond one has to the player, their shared emotions, in relation to an event can really make a player immersed in the problems and dangers a game can impose on the NPCs. For the writers and the programmers, the benefit from this is, scripting a game's story is very time consuming and expensive, having the NPCs have the ability to influence a games story allows the writers and programmers to control the NPC to direct the player where he should be going rather than hoping the player finds his way on his own.
Overall, it seems that when it comes to NPCs making decisions the player is ok with them making the small decisions, which result in gaining information or moving the story along. While when it comes to the big decisions that influence the ending and make the player look like a hero, the player wants all control over those event themselves so they are in the spot light.






























Appendices

Honours Project Proposal



                                   
AG1081A Honours Project Planning and Reporting
Alan Hepburn
0701628
Computer Games Technology
Honours Project – Final Proposal







Introduction

It is very rare in games that character other than the player can influence the consequences of a game's storyline. The goal of this research is to find if not only the player character(PC) but also the non-player character's(NPC) can be able to move a storyline forward. Graphic improvement has been a focus in recent years, AI has been neglected, as a result the now realistic graphics have caused games to need more than just graphics, and many think AI is the answer. Focusing on populating these games with better AI for the companion NPCs that accompany the PC will benefit future games especially role playing games (RPG). Many people believe that a good AI character would use many of the AI techniques currently available today, as each refers to a way in which the human mind tackles a problem in reality, a believable character must use multiple techniques to show its realism. As a result  a set of believable characters will be tested against a character created with a standard finite state machine(FSM), used widely in the industry. A simple story will be created and different scenarios will be played out by both the believable character and the standard character and the emergent behavior will be assessed and analyzed to give an answer to whether a believable character can be created that can influence a game's storyline.

Motivation
Games nowadays have impressive graphics built up over decades of research however when you look at your very detailed, realistic companion they stare lifelessly back at you. Even more so in games now the companions you collect to assist you on your quest/journey/adventure have nothing to do with it, they are just collectible or interchangeable. 

Many games out at the moment have begun to put your companions into the game but usually their actions are mechanical and game driven rather than from the characters own personality and feelings. For example Dragon Age: Origins places your first companion into the story as a key character, however the things he does or says such as telling you to go somewhere or giving you information still feels mechanical. It feels, rather than being his idea based on his feelings, it's just another way to move the plot along shattering the suspense of disbelief needed in games. Also the "choices" that it appears he has, can always be easily manipulated by the player, such as finding a ruler for the kingdom after the final battle, you can convince him to marry his brother's wife for the good of the kingdom or make him king, both ideas of which he detests right up until you "convince him" and even afterward but he accepts it based solely on you being the main character. Mass Effect 2 built collecting characters into the game but then that's all they were, collectibles, there value in the game are of tools. Something for the player to collect to upgrade their ship or use as a way to finish the game, rather than being a part of it. Also Fallout New Vegas, these characters are interchangeable, so you don't get the feeling that you need them as they can be swapped, they also try and put them into the game, but just into situations that build a relationship, they have no actually effect on the game's main story.

Although games have taken a step forward there still is a long way to go before believable characters are at your side in a game. That is why further research is needed into creating believable characters and finding better ways for them to interact with the game. AI is an ever increasing area of study and is becoming the focus of a lot of attention in the industry today as a result of research like this.
Research question

The research question for this project could be:
               
                "Can a believable character, with personality and emotions be created that can actively and        realistically effect consequences in a game's story?"

The objectives relating to this are:
·         To create characters that in certain situations of a story would react believably based on their personalities and emotions.
·         To allow the characters to take control of where the storyline is heading without needing input from the player.
·         To create believable personalities for these characters.
·         To create believable emotions for these characters.
·         To compare one system created using finite state machines and one created using various techniques so as to see if the latter produces a more believable character.

Addressing the Question

Firstly a story must be created this story will have four main point, a beginning, a middle, a climax and an ending. Between these points the story will be driven by the NPC's personality and emotions with each NPC able to make choices about what happens in the story. Before the story is created each NPC will have an individual personality and emotional base created for them, the story will be created around these attributes to make the best use of them. 

The first standard experiment will use FSM as the primary AI algorithm so the choices in the story will be based on the FSM and allow for minimal emergent behavior. Switching between the different states of the FSM will be controlled by an appraisal model based on the characters personalities and emotions, which will influence the behavior model and this will be used to determine the actions that the characters take. The actions will then be used to modify a master event list which will then update the appraisal model with the new information about the next instances of the storyline. Obviously this creates a continuous loop which must stop at certain places so that the story can be read by the player and their actions can be decided. This is also a good place for the exchange of information. Using a ability system like the ones used in table top games and such games as Fallout 3, each NPC will have a better understanding of certain things such as the environment or a greater perception of events, so NPCs will have to exchange information. This system will also be used to determine who acts first and will also determine conflict between NPCs. If one NPC's action is against what another character wants to do they can argue or even fight about it. These actions, in some way, will be determined by the FSM.

The second experiment will use the same personality and emotion model as the first but will be created using a hybrid of AI techniques all based on the best algorithm for the specific situation. The hybrid system will experiment with techniques such as goal orientated behavior for self motivation of the NPCs replacing the FSM in this instance. Genetic algorithms for creating the initial appraisal model running though the different scenarios of the story to build an believable initial attribute base, rule based systems for group co-ordination by focusing the groups goals and fuzzy logic and fuzzy state machines as the initial advancement to the FSM.

The two will then be compared and analyzed for any emergent behavior and the differences the story takes. To test as accurately as possible the same scenarios will be used, which will try and fully utilize the different personalities and emotions. 

Through experimentation with the different AI algorithms and the different personality and emotion bases there should show that a believable character can be created that can be fully integrated into a story, giving a much more realistic atmosphere to a game and taking the control of the story somewhat out of the hands of the player, to make it more like real life.

Plan/Schedule and Resource Requirements

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhj2_TR9lVDOCDpjOXt3aHVzW6ebSrRUoDi9aOM7p3ukfYdbfVYW7X6dluXPEFdevEkw7cD1vD6alDD2PD4YFNjIMOfjsai9JnF4o1nPKXlH0TERdQOdtmgEAMDwq006TSc5iVB2G8OVbs/s320/GChart+HP.bmp


Above is a detailed breakdown of what is needed to complete the practical portion of this project with the red bar representing the time the task should be completed and the green bar representing the extended time after that can be used to complete the task. One should note that from creating GUI to integrating remaining FSM will all be done together rather than after each other but each section should be completed by the allotted time. Also the testing tasks are done while creating the hybrid system. They signify that in the initial testing it may not work but by the final testing it should be working and almost finished.
As to what resources will be needed, the project will be hand coded for the majority of the project. Only a computer with visual studios should be required. A graphics engine may be used depending on, if there is enough time to create a 3D world, but for the moment a graphical user interface of a text based story with simple images and faces will be used.










References/Bibliography
Game Programming, 2010. Amit’s Game Programming Information. Available at:<http://www-cs-students.stanford.edu/~amitp/gameprog.html> [Accessed 09 November 2010]

Bringing emotions to video games, 2010. msnbc.com. Available at:<http://www.msnbc.msn.com/id/4038606/>[Accessed 09 November 2010]

Adapting the Tools of Drama, 2001, Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/3037/adapting_the_tools_of_drama.php>[Accessed 30 September 2010] 


Alexander Nareyek, 2007,Game AI is Dead. Long Live Game AI. Intelligent Systems. Available at:<http://www.ai-center.com/publications/nareyek-07-ieee.pdf>[Accessed 12 November 2010]


John Laird's Artificial Intelligence & Computer Games Research, 2009. John Laird's Web page. Available at:<http://ai.eecs.umich.edu/people/laird/gamesresearch.html>[Accessed 12 November 2010]


John E. Laird and Michael van Lent, 2000. Human-level AI's Killer Application: Interactive Computer Games. University of Michigan. Available at:<http://ai.eecs.umich.edu/people/laird/papers/AAAI-00.pdf>[Accessed 12 November 2010]


The Dust of Everyday Life: The Art of Building Characters, 2010, Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/4283/the_dust_of_everyday_life_the_art_.php>[Accessed 12 November 2010]


Peter Molyneux: The Essence of Interaction, 2009, Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/4011/peter_molyneux_the_essence_of_.php>[Accessed 12 November 2010] 


Constructing Artificial Emotions: A Design Experiment, 2007, Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/1992/constructing_artificial_emotions_.php>[Accessed 12 November 2010] 


Anticipatory AI and Compelling Characters by Bruce Blumberg, 2006, Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/2563/anticipatory_ai_and_compelling_.php>[Accessed 12 November 2010] 



AI Middleware: Getting Into Character, Part 2: DirectIA, 2003 Gamasutra.com. Available as:<http://www.gamasutra.com/view/feature/2824/ai_middleware_getting_into_.php>[Accessed 12 November 2010] 

Baillie-De Byl,P, 2004.Programming Believable Characters for Computer Games. Hingham, Massachusetts: Charles River Media, INC.

Dickheiser,M ed., 2006. Game Programming Gems 6. Hingham, Massachusetts: Charles River Media, INC.


Jacobs, S ed., 2008. Game Programming Gems 7. Boston, Massachusetts: Course Technology.

Rabin, S ed., 2002. AI Game Programming Wisdom. Hingham, Massachusetts: Charles River Media, INC.

Rabin, S ed., 2004. AI Game Programming Wisdom 2. Hingham, Massachusetts: Charles River Media, INC.

Rabin, S ed., 2006. AI Game Programming Wisdom 3. Hingham, Massachusetts: Charles River Media, INC.

Rabin, S ed., 2008. AI Game Programming Wisdom 4. Boston, Massachusetts:Course Technology.

Freeman, D. 2003. Creating Emotion in games. USA, New Riders.

Ewen, R. 1984. An Introduction to Theories of Personality. Orlando, Florida, Harcourt Brace Jovanovich, Inc.

Burger, J. 2004. Personality. USA, Wadsworth.

Monte, C. 1977. Beneath the Mask. Orlando, Florida, Harcourt Brace Jovanovich, Inc.

De Houwer, J and Hermans, D eds., 2010. Cognition & Emotion. USA, New York, Psychology Press.

Ekman, P and Davidson, R eds., 1994. The Nature of Emotion. USA, New York, Oxford University Press, Inc.