Designing for believability requires a virtual pet to react as much like a real animal as possible. For this reason, the pet’s behaviour needs to be predictable enough to not seem completely random, but unpredictable enough to be believable as an independent thinking agent. As a real life example, a cat will behave mostly predictably when it’s hungry – meowing, running to its food bowl, etc. – but it won’t meow at the exact same time or run the exact same route to the bowl. Catbox needed to emulate this kind of behaviour in order to suitably represent a real, thinking animal in the eye of the player.
Designing A.I. to react in a natural way is a challenge – A.I. programs tend to be good at being completely random or completely predictable, but less so at portraying a convincing level of unpredictability. For Catbox, I initially tried out a machine learning approach to developing natural behaviour. While initial results were promising, this approach ultimately turned out to be unsuitable for this project.
The solution settled on for Catbox employs series of personality ‘curves’ which track the pet’s internal state over time and adjust its behaviours according to both its inbuilt tendencies and input from the user. This allows Catbox’s behaviour to change over time, according to his immediate needs, his pre-set nature, and the types of interaction he’s had with his user. This article covers the details of developing this behavioural approach.
Network based approach.
Early attempts to develop A.I. for Catbox were made using an experimental application of a supervised learning method called support vector machines. Using this method game A.I. is trained using a dataset, in this case based on the various needs of the virtual pet – unhappiness, hunger, tiredness, bladder, dirtiness and sickness – to choose an appropriate action from a range of pre-defined behaviours. The system is trained with a Unity plugin called CoAdjoint Orbit, which exports a .dll file that can then be imported into the Catbox project and accessed to select behavioural responses.
This system was moderately successful, in that it did select behaviours approximate to those predicted based on the pet’s various needs, but had a number of drawbacks. Firstly, supervised learning methods are good at selecting a single correct response from a dataset, but their nature is to eliminate unpredictability, resulting in the virtual pet performing the same ‘correct’ action over and over again. A large degree of randomness had to be introduced before the pet displayed the desired degree of unpredictability, which undermined the usefulness of deploying support vector machines in the first place.
Secondly, the need for the system to be exhaustively trained outside of the game places limitations on what can be achieved and deployed. Training a single personality type to a reasonable degree of accuracy required over 1000 manual data inputs – introducing differences in personality would require a huge amount of manual input. Additionally, once a dataset has been trained, that data is then fixed; any changes to variables or inputs would require the system to be entirely retrained.
Thirdly, the resulting A.I. proved incompatible with mobile devices, with the .dll files unable to compile on iOS. This platform restriction, coupled with the drawbacks outlined above, led to the machine learning approach being abandoned despite some initially promising results.
Curve based approach.
The A.I. approach used for the Catbox prototype is based on a series of curves, which dictate how the Catbox’s needs change over time as well as how he responds to these various needs. His behaviours are controlled by four curve arrays, each representing values for it’s six key needs. ‘Nature’ curves dictate the simple increase of these needs over time, as defined by Catbox’s pre-determined personality type, while ‘age’ curves control how this nature changes as he ages. ‘Threshold’ curves dictate at what point a certain need will begin to affect his overall happiness, and these also change with age. ‘Nurture’ curves are effected by interactions with the user, allowing Catbox’s personality to change according to a user’s actions over time.
This system roughly emulates the ‘nature and nurture’ paradigm believed to influence real animal behaviour. At any point, the system can check the time passed against the age of the pet, and retrieve an average of the four curves to make a decision about how it should respond to a given need. Potential responses are added to or removed from a list class as the curve value requires, with Catbox’s actual response being selected at random from this pool.
A C# script tracks the position of all the curves whenever the game requires Catbox to perform an action, and adds or removes potential actions from the list class as required.
This system proves flexible and dynamic, with responses being random enough to seem believably unpredictable whilst the curves ensure the the range of possible responses remains true to the pet’s age, personality type and the current state of its needs.
At initialisation Catbox is assigned a particular personality type which dictates the shape of his behaviour curves. A ‘greedy’ type pet might have a steeper ‘hunger’ curve for example, while a ‘lazy’ type pet might have a higher threshold for dirtiness due to a general unwillingness to wash itself. These behaviours can then be reinforced or altered depending on the user’s actions; frequently feeding Catbox treats will increase his demand for food, while brushing him regularly encourages him to keep himself clean.
The prototype currently features seven possible personality types for Catbox, selected at random on initialisation; greedy, lazy, fastidious, playful, depressive, particular and easy-going types, each with their own different behaviour curves. Future versions of the software could introduce a degree of randomness or noise to the curve generation process based on pre-defined archetypes like these, ensuring that every user’s pet has a subtly unique personality.
Modular script design.
The behaviours that result from this A.I. system are controlled by a series of cross-referenced C# scripts, applied in a modular fashion. This approach allows different behaviours to be developed independently of the rest of the game’s code, then integrated with existing scripts as required. This makes it relatively simple to keep track of which scripts are currently acting on Catbox, and allows new behaviours to be developed and integrated quickly without the risk of compromising existing code, making an iterative development approach easier in the future.
The game’s scripts are divided into four categories; system, controller, behaviour and input scripts. System scripts deal with high-level software functions such as monitoring the passage of time and saving and loading data. They count time passing and evaluate the behaviour curves accordingly, and can also track how much time has passed while the game is closed, ensuring Catbox’s behaviours stay consistent while the software is inactive.
Input scripts monitor the user’s physical interactions with the device, such as taps, swipes and pinches. Input data is compared to other scripts in the system to check the state of Catbox at the time of input, and trigger a behaviour that responds appropriately to the user’s input.
Controller scripts apply to Catbox directly and monitor its various variables, activating and deactivating behaviour scripts as required. These take data from the input and system scripts, compare it to Catbox’s internal states, then select and trigger the correct behaviour.
The behaviour scripts control what Catbox actually does in the scene, the actions and reactions depending on inputs from other scripts. These can be triggered as part of his natural behaviour or at a specific input, and they run the movement, animation and sound systems that make up Catbox’s potential actions.
The cumulative effect of these scripts gives the impression that Catbox has his own personality and intelligence, and meets the design goal of creating an unpredictable yet convincing virtual agent. The advantage of such a modular approach is that it’s easy to add more scripts into the system, expanding Catbox’s behaviour range in future versions of the software.