Implementing artiﬁcial intelligence: a generic approach with software support

. In computer games, one of the eminent trends is to create large virtual worlds with numerous non-player characters. Usually their artiﬁcial intelligence (AI) is implemented by scripting, which can be a burden for the application developers involved. This paper suggests an approach facilitating designing AI functionalities and striving to reduce, via software tool support, the amount of hand-written AI script code needed. Our approach is suitable for, e.g., creating autonomous agents with personal characteristics, capable of behaving in a natural manner. For instance, the goal-oriented agent paradigm can be applied easily with the approach. The deﬁnitions needed are written using a script language. Therefore, the agent conﬁgurations can be tested rapidly. We have extended an existing AI environment and created a script framework for implementing general-purpose AIs. Moreover, we have implemented software tools capable of generating script code for helping in the AI structure design and for simplifying the actual code-writing task. For demonstrating the applicability of our approach, three example scenarios specialized from the framework are presented.


INTRODUCTION
Over the recent years, virtual worlds of computer games have expanded beyond measure.They have become complicated constructs with numerous nonplayer characters (NPCs) and places.Having a huge number of NPCs makes it possible to offer lots of possible opponents, allies, sources of information, and trading partners.Thus, by increasing the number of NPCs, the game can often be made more interesting.However, this also means more time spent on implementing artificial intelligence (AI) for these NPCs.The NPC AI is a crucial aspect of computer games, but achieving sophisticated intelligent behaviour for a very large number of NPCs is not possible using conventional AI methods or engines [19].The great challenge for the AI is to get the NPCs to behave in a believable, human-like fashion.The player should be able to imagine that interactions between real characters take place.The same facts apply also when considering AI agents (without graphical presentation) for, e.g., playing strategy or board games.
In this paper we propose a novel script-based 1 AI approach for computer game development.It is applicable with several kinds of games, and can be applied also outside the gaming domain.We use a separate AI framework that can be attached to the actual game engine or other program using the AI features.The purpose of the AI framework is to offer virtually all the AI support needed for creating interesting games.Thus, the application developers can concentrate on the real AI problems instead of writing lots of similar scripts for different agents.Scripting is used as a helping method, but most of the actual work is done by the framework.This paper is a derivative of the existing conference article [7], and has been extended with numerous additional considerations, clarifications, and an extra demo scenario.Also the software tool support has been extended and improved since the original paper.
Our approach is based on the famous idea of dividing and conquering: we aim at splitting the problem into smaller ones, and structuring the code accordingly.Moreover, our goal is to facilitate the work of AI developers by making it easier to design the AI structure naturally, in terms of the temporal flow of, e.g., the decision-making process.In addition, our approach is meant to make it easy to take advantage of personalization of the agents and goal-oriented action planning (GOAP) [12] principles.For these ends we have developed a general-purpose scripting framework and software tools for creating specialized AI implementations easily.
Our hypothesis is that using the approach, the productivity of AI programmers can be increased, as implementing AI features requires less work; the tools help in saving time and work in many ways.The ultimate goal of this work is to improve the quality of AIs in digital games by facilitating more efficient use of the AI programmer resources.
The framework was obtained by extending, modifying, and generalizing the AI support part of our existing CAGE game engine [18] and by making it totally independent from CAGE.At the beginning of this work, CAGE supported directly only NPC AIs implemented via state machines, and the application developer had to create more sophisticated AI implementations manually, if needed.Since, CAGE AI framework was extended with GOAP support, before the generalization and separation into our current framework.
The approach of this paper combines the use of finite state machines with the use of new kind of machines for implementing general-purpose AIs.With these machines, e.g., goal-oriented agents can be implemented easily.For testing the applicability of the approach, we have programmed three example scenarios using the framework.For taking advantage of our framework the software tools created for specializing the framework are essential.
The rest of the paper is organized as follows.In Section 2 some background and related work are covered.After that, in Section 3, we present our general AI approach in more detail.In Section 4 we explain the prototype AI framework -a realization of the general idea.Then, in Section 5, the implemented software tools and the benefits offered by them are discussed.In Section 6 we present example scenarios featuring AI implementations created by specializing the framework.The concluding remarks are given in Section 7.

BACKGROUND AND RELATED WORK
Almost all virtual worlds of computer games contain less intelligent NPCs in the form of animals and humans with simple behaviour; there are servants, guards, shopkeepers, and so on.State machines are a suitable method to model their behaviour.According to [12], the most of the decision-making systems in current games are implemented using state machines along with scripting.A problem with state machines is their rigidity: when encountering situations that have not been foreseen, the resulting behaviour can be poor [6].
Game worlds may contain also more intelligent agents, whose behaviours should be as complex as those of the player characters (PCs).Alas, in practice, often AI implementations -and thus, the resulting behavioursof these agents are too simple.It is quite common to just stand still waiting for the interaction initiated by the PC, or to live only to die by the sword of the PC.This kind of simplified behaviour of NPCs can lead to boring, selfrepeating, and unnatural virtual worlds.Therefore, our approach aims at facilitating creating intelligent agents of high quality.
One possibility for a basis of creating a sophisticated AI is to model personal characteristics, moods, and knowledge of the agent for inducing its behaviour.Often the AI can be improved by adding in-game interactions between NPCs.(The significance of them is discussed, e.g., in [17].)Also other methods for making games more interesting, developed over several decades by the multi-agent system community, can be used.However, the basic problem remains: often simply too much work is required to implement the wanted behaviour properly with conventional methods.Our approach strives to tackle this problem.
The usual approach for implementing new computer games is to use game engines; modern games are seldom developed from scratch [12].Instead, a suitable game engine is modified for the new game, which is then implemented using the engine as a framework.Often some scripting language is used in addition to a conventional one.The differences between game engines are huge; their capabilities and features, including AI support features, differ a lot.It is common that the AI implementation of a game is not really supported by the game engine used, but the AI is somehow glued into the main game.On the other hand, many commercially used game engines offer some sophisticated AI support features.However, to the best of our knowledge, none of them use such a personal trait-based2 approach as presented in this paper.
There is a wide array of publications on solving different kinds of AI problems in game worlds by NPCs and other agents.However, most of them seem to be solving quite specific problems in specific environments.Our framework, on the contrary, aims to be very generic.
Despite the genericity, it is as a rule easily applicable in a given task.The exact easiness depends on the case, but the lack of artificial limitations in the framework and tool support for specializing it help a lot.
The "Scripted Artificial Intelligent Basic Online Tank Simulator" (SAI-BOTS) [2] lets the players script the behaviours of their tanks using the Lua scripting language and then fight each other with them.It resembles, for instance, the CAGE system in the sense that its main programming language is C++ and it uses Lua for scripting.When using our approach, the application developer writes definitions for agents, which calculate their actions autonomously.In SAI-BOTS, on the other hand, the behaviour of the tanks is pre-scripted conventionally.Moreover, CAGE is a prototype game engine, which can be used to develop computer games of different genres.SAI-BOTS, instead, is a specific, scriptable computer game.
The AI structure of "being-in-the-world" [4], a multi-user dungeon (MUD) agent, consists of two asynchronously working modules.The reasoning module includes, e.g., logical reasoning and goal maintenance, while the real-time coping module deals with the world.The basic structure of the solution could be implemented using our approach, while it might not be the best possible way to perform ontological reasoning.The solution of being-in-the-world resembles that of the CAGE engine for goal-oriented agents.While our AI framework uses Lua, being-in-the-world has been written in Common Lisp.The framework presented in this paper is general enough to be suitable for different kinds of games and other purposes, but being-in-theworld is a MUD agent created for surviving in a certain kind of MUD.
Basketball Artificial Intelligence Tool (BAiT) [16] is a data-driven software tool system for implementing AI for a basketball game.It aims at offloading work from programmers by transferring some of it to designers.Our approach strives to offer help for generic AI implementation -not only for implementing a finite set of AI features for a single game (or genre).This, on the other hand, means that we cannot offer as high a level of abstraction as BAiT does; we expect the users of our tools to know as much of the target system and its interfaces as if they were to script the AI conventionally.(Of course, application-specific simplified scripting interfaces can be offered to be used via our tools, if necessary.)BAiT takes benefit of the fact that basketball as an activity is sequential by nature.This is the case in most sports.Also our approach is extremely suitable for creating AIs for such sequential activities.

ARTIFICIAL INTELLIGENCE APPROACH
For ensuring suitability for different needs, our approach includes both state machines and more advanced methods intended originally to be used with autonomous agents with personalities.We divide artificial agents into two categories according to the methods used: there are state machine agents (SMAs) and advanced AI agents (AAIAs).Instead of state machines, AAIAs use a new kind of AI machines (AIMs) for behaviour generation.The focus of this paper is on AAIAs, but the support for SMAs is included in our approach, as sometimes trying to mimic complex human-like "thinking" processes for inducing actions can be an overkill.This matter is discussed, e.g., in [10].
In modelling and developing agents, the goal orientation as a paradigm is increasingly recognized [15].AAIAs support fully creating goal-oriented agents (GOAs) that model and use goals and motivations in their action-generating processes.We consider them as a subcategory of AAIAs.The agent types of our AI approach are depicted in Figs 1 and 2.
In our approach, the application developer describes -depending on the type of the agent -either the agent behaviour as a finite state machine or AIMs for generating behaviour autonomously.(This is the original idea of using AIMs, but they can be applied freely and offer benefits also in other kinds of settings.)The descriptions are given using a script language 3 .Scripting allows rapid application development and testing.Downside of this is the lack of efficient debugging capabilities.However, it is possible to implement the needed machines piece by piece and to test each added code block separately, without any need to recompile the framework during the process.Our approach enables the creation of huge virtual worlds with lots of different inhabitants with diverse AI capabilities.
Of course, when the number of agents grows enough, making any kind of individual AI calculations for all of them in real time will become impossible.While our approach cannot solve this fundamental problem, it facilitates and speeds up, nevertheless, the creation of a large number of believable AI implementations.The AAIAs are not only suitable for advanced NPCs, but also for believable and seemingly intelligent co-players or adversaries.AAIAs can even be used in implementing different decision-making systems, planners, and so on.Similarly, SMAs can be used for various purposes.

State machine agents
Although the main focus of this paper is in AAIAs, we have included the support for conventional state machine-based agents as well for convenience.Simple behaviour, after all, is easily achieved using them.Another good side (in some cases) in them is the high predictability of the actions 4 .Moreover, finite state machines are not generally computationally expensive [11].
State machines could easily be implemented using AIMs.However, we choose to use a specific structure for implementing them.They are, after all, rather simple constructs that do not really benefit from being implemented as AIMs.
The application developer describes the state machine models by scripting.This work includes defining the states, state transitions, and inputs capable of firing the state transitions.It is possible to define a separate state machine model for each agent, but several agents having similar behaviour can also share one.This reduces the needed amount of copying and pasting code.An example state machine model is depicted in Fig. 3.
In [7], the general idea was that each agent using state machines has its own state machine instances and can be in a different state than other agents regardless of whether they use the same state machine model or not.Connecting only one agent to a state machine instance was suggested for simplicity and general implementability.However, currently we are focusing on using shared state machines.This requires keeping track of states of individual agents, either by themselves or by the state machine construct, but in many cases considerable space savings can be achieved by not replicating similar machines.

Advanced AI agents
In our approach, every AAIA uses a number of AIMs that may modify its personal parameters, possibly adding also new ones.The application developer defines these attributes for the agent, as well as the set of AIMs to calculate new agent parameters, for example, goals and means to acquire them, and to modify the existing ones.The AIM set establishes the desired AI architecture.
The composition of a single AIM is depicted in Fig. 4.Each machine can contain several layers of calculation nodes (CNs).A CN may perform comparisons, calculations, and basically any program code.However, the idea is to keep the logics of an individual CN as simple as possible.The layers are iterated through in a fixed order according to their numbering (in Fig. 4, from Layer 1 to Layer n).Inside of a layer, the execution order of CNs is not fixed5 .(By executing a CN we mean running its respective code block.)Because of this, the code of a CN must not depend on attributes altered on the same layer.It may only trust that the operations of the previous layers have been performed.Possible common initialization or input filtering code can be run before executing the CN layers.Feedforward artificial neural networks can be seen as special cases of AIMs.
The purpose of suggesting the use of several machines instead one is to simplify the overall AI construction by splitting it into logical pieces.The whole AI functionality is then achieved by chaining the AIMs, as shown in Fig. 5.The arrows pointing downwards in Fig. 5. Overview of the approach.A chain of machines is used to produce new data, like goals and actions to perform.The different rectangle widths depict possible growth of the number of the parameters.
the figure represent the flow of execution.Passing the information from an AIM to another is accomplished by simply modifying the attribute data to which the machines have a shared access.Thus, defining any kind of complex input/output interfaces is not necessary.
Naturally, the usage of AIMs is not limited into this kind of single cascade structures.They are often viable and sufficient, but if needed, several AIM cascades can be run in parallel, or hierarchical AIM structures can be built.
The initial attributes can contain many kinds of data, including the personal traits and the moods of an agent.These parameters are simple key-value pairs.Data requiring more complex representation, like knowledge, other history-related data, and perceptions, can also be present, represented by suitable data structures.In every stage in the process, the existing attributes can be modified and new ones can be added, so the cardinality of the set of the final attributes may be greater than that of the set of the initial attributes.
The AIMs can be easily used to decide goals, generate action possibilities, and eventually produce a priority list of actions (or sequences of them) to carry out.Thus AIMs are a suitable tool for applying GOAP techniques.In Fig. 6, an example machine architecture, the basic GOAP system of the CAGE framework, is depicted.This architecture implements the general idea of Fig. 5 and uses AIMs at three levels.First, there is a machine for generating the goals based on the personality and the environment.The next machine generates tasks to be performed based on the most important goals given by the first machine.Finally, there is a separate machine for splitting the tasks into short-term actions.Effectively all the machines manipulate the importance values of their respective output parameters so that decisions can be made based on priority lists.For keeping the goals Fig. 6.Architecture of the CAGE GOAP system.and tasks updated, the machine chain for an agent is run periodically, always when completing a task, and always when important environmental events occur.

STRUCTURE OF THE F 1 I 2 A 3 FRAMEWORK
For implementing and evaluating our approach, we defined the structure of actual code so that the development process could partly be easily automated.The resulting high-level AI framework is called F 1 I 2 A 3 .The name comes from "Framework for Individually Intelligent Autonomous Artificial Agents".The framework provides support for SMAs and AAIAs.It is also possible for an AAIA to command SMAs and other AAIAs belonging to its group using a simple messagepassing mechanism.
The F 1 I 2 A 3 framework was obtained by extending and generalizing the existing AI framework of the CAGE game engine, so the language of choice is the scripting language Lua [9].It is a dynamically typed popular language, which has been used in several games and industrial applications [8].Lua is also very fast [3].Moreover, Lua is an easy language to bind with other languages.This was an important factor when originally deciding the scripting language to be used in the CAGE AI framework.Thus, F 1 I 2 A 3 -based AI implementations can be easily attached to different game engines or other "main programs".

Implementing state machines
The state machine implementation principles of F 1 I 2 A 3 are basically those of the original CAGE AI framework (although nowadays we use shared state machines actively).For using CAGE state machines, the application developer defines the state machine models consisting of state models, and connects SMAs to them.The state models include the state transitions on suitable conditions, and are written in Lua.
An example F 1 I 2 A 3 implementation of a state model is shown in Fig. 7.The modelled state is an attack state of a simple agent, which could be used, for example, in a first person shooter game.When the agent is in the attack state and sees a PC, it attacks.When there are no more enemies in the vicinity, the agent falls asleep.If injured severely, the agent will retreat.
In Fig. 7, the basic code-level structure of state models can be easily seen: they are implemented as Lua tables with three functions.One is called when entering the modelled state, one when executing corresponding state actions and triggering possible transitions, and one when leaving the state.Besides individual state models, state machine model implementations include functions for creating agent tables, setting agent properties, and running the modelled state machines for different agents.

Implementing advanced AI machines
Besides CNs, an AIM includes some metadata and functions for running and cascading the machines.The most important function is run X(agent), in which X is replaced by the machine name (that serves as a unique identifier (UID)).This function is used for running the code segments of the CNs in the order determined by the machine structure.Using the agent parameter, some suitable information about the agent for which the machine is meant to be run is passed for it.The parameter may, for instance, contain only a string containing the name or the UID of the agent, or it can be a pointer to a complex agent class with methods usable from the Lua code.There are also helper functions (achievable from the CN code blocks) for, e.g., sorting and handling priority lists.
An example implementation of a CN of the CAGE Goal Generating Machine is shown in Fig. 8.The CN is responsible for updating the hunger status parameters of the NPCs.Updating takes place each time the game time passes.Fig. 7.An attack state model implementation.In this case, agent is a Lua table that stores necessary properties and functions of an AI agent using the state machine model.Fig. 8.An example calculation node implementation.The variable agent that has been given to the machine-running function as a parameter can be used inside the CNs.In this case, agent refers to a class instance with a method called get name() callable from the Lua code.

TOOL SUPPORT
In the case of AAIAs, specializing the F 1 I 2 A 3 framework requires fixing the number and the layer structure of CNs and writing their respective code blocks.It is easy to automate the generation of the other parts of a normal specialized AI implementation.So, to help application developers in the creation of AIMs, we have implemented a software tool, called Machine Creator, for building them.Defining the layer structure of a machine and inserting the required script code for the CNs can easily be done via the graphical user interface (GUI) offered by it.A screenhot of the Machine Creator GUI is shown in Fig. 9.
After the structure of the machine under construction has been defined and the desired content of the CNs has been added, one can order the software to generate the AIM in F 1 I 2 A 3 format.In the Machine Creator version used in [7], the agent parameter value initializations had to be added to the script files by hand, but nowadays, an arbitrary initialization code can be added via the GUI.Everything else is generated automatically.The tool support speeds up the machine creating process considerably.
The Machine Creator tool has been implemented using the Qt framework [14] in order to get an easily portable tool for different platforms.It has been successfully used in Linux and Microsoft Windows environments.
Besides adding the possibility of giving the initialization code via the GUI, we have improved the Machine Creator tool in many other ways since [7] was published.The GUI has been enhanced visually, and alternative ways of performing actions have been added.Nowadays, the Machine Creator can also load the generated scripts from files for further modifications.Moreover, a syntax checking feature has been added: the tool can check the syntactical correctness of each code block.This makes debugging -and in the first place, generating bugless machines -considerably easier.Also Lua syntax highlighting support was added for making code-writing more pleasant and less error-prone.
Our AAIA approach would only have little use without the Machine Creator: GUI, syntax checking, and realization of our framework by automated code generation are the means for trying to achieve our goal of reducing the burden of AI developers.The time and work savings come from multiple sources; the main benefits of using the tool (and our general approach) are • the possibility of implementing scripts naturally, based on temporal (decision-making etc.) flows; • the easiness of locating the relevant pieces of code, when necessary; • the easiness of implementing agent personalization and GOAP features; • the savings obtained due to automation of implementing logics related to the execution order; • helper functions offered; • syntax checking in the code block level; and • easiness of writing code to be executed truly concurrently 6 .
Of course, the actual savings in the amount of work or time used when implementing an AI are highly case-dependent.In some cases, our approach might not offer any benefit, while in other cases, the savings could be considerable.We do not try to make any numerical comparison against conventional scripting, as it is impossible to choose a generally applicable and fair baseline; if some AI feature was fixed to be implemented first conventionally and then with our tool, the results would not mean much, as there are many ways to solve a problem in either way.However, based on our experiments (see Section 6), we claim that at least in some cases using our AAIA approach and Machine Creator is truly beneficial.
The size of the script code overhead generated for structuring the AIMs and using them grows a (small) constant amount for each CN and a constant amount for each AIM.Compared to the size of the hand-written code, the size of the automatically generated code may be considerable with simple AI implementations with several AIMs and CNs and negligible with complex implementations with only a few AIMs and CNs.Ideally, all the code written by the AI developer should be "effective" and closely AI-related, but the exact number of the lines of the code needed for some implementation depends on the skills of the programmer and the chosen way to use our tool.
We also have implemented another tool, called State Machine Editor, for creating and modifying finite state machines via a GUI and for generating Lua implementations automatically.The GUI is demonstrated in Fig. 10.With this tool, our goals are to • provide a visual view to the logics and thus help in the design process and • speed up the development: the time savings gained by generating the state machine code automatically are substantial.
The Qt framework has been used also for implementing the State Machine Editor for the same reasons as it was used in the Machine Creator implementation.Also the State Machine Editor runs at least in Linux and Microsoft Windows environments.

EXAMPLE SCENARIOS
We have implemented three example scenarios by specializing the F 1 I 2 A 3 framework to test our AAIA approach.The first one is a scenario called Gunslinger, in which the PC plays a role of a sheriff in the situation in which a group of bandits has stolen a chest full of gold.The purpose of this scenario was to verify the applicability of F 1 I 2 A 3 for its original intended task, creating NPC AI implementations.(The problem domain analysis considering the role of a sheriff is omitted here for brevity because it is not crucial given our goal.) The second scenario is called Gomoku.It was implemented to demonstrate that it is possible to create also a board game opponent AI using the framework.The third scenario, Wargus AI, was implemented to test the applicability of F 1 I 2 A 3 for creating hierarchical manager systems.We created a simple strategy manager AI for playing a real-time strategy (RTS) game.

Gunslinger
In the Gunslinger scenario, initially there are five bandits guarding a chest full of gold.All the bandits use the same AIM, but differ in personal traits.Additionally, one of the bandits is the leader of the group.The leader can command the others, and the commandments are normally obeyed.
State machines could have been used for this basic operation of the bandits.However, the bandits are meant to model human beings, and human beings have different personal urges.For modelling these, AIMs are handy.So, if some personal need of a bandit to do something, for instance to flee, outweighs the authority of the leader, the bandit can also commit "rebellious acts".
The personalities of the bandits are modelled by the following parameters: authority, bravery, alertness, tiredness, and greed.The tiredness value grows as time passes.The observations about the environment affect also: the PC can be seen, as can be the gold chest.Moreover, the bandits are aware of the casualties.In this simple scenario, there are five possible actions the bandits can perform: guarding, sleeping, attacking, alarming, and fleeing.In addition, the leader can command the others to perform these tasks.
As the game engine (providing the graphics, the game loop, etc.) we used CAGE run in Ubuntu 10.04.Attaching the AIM to it was trivial and required only minor modifications as CAGE already was capable of running Lua scripts.A screenshot, in which the PC is attacking a bandit, is shown in Fig. 11a.
By using the Machine Creator tool, the implementation of the scenario, in which the individual characteristics of the bandits are clearly reflected into their behaviours, required roughly 40 hand-written lines of Lua code for the CN logics.There were a total of eight CNs forming an AIM used by all of the bandits.The scenario implementation clearly demonstrated that the Machine Creator tool and our approach in general could be successfully used for speeding up NPC AI implementations.

Gomoku
The F 1 I 2 A 3 framework is meant to be a general-purpose AI framework.Thus, it should be applicable not only in creating the AIs for NPCs, but also in creating AIs that could be used as opponents or co-players.For demonstrating this, an AI for playing Gomoku (also known as Five-in-a-row) was implemented.This scenario was created for a self-made, general-purpose simulator software run in Ubuntu 10.04.A screenshot from a game between an AAIA and a human being is shown in Fig. 11b.
The basic implementation is simple: all the possible places for setting a counter are evaluated each round and the one with the best evaluation score is chosen.The scoring is based on the overall numbers of counters in the horizontal, vertical, and diagonal rows around the potential place and the lengths of continuous rows around it.Immediate victory moves and the rows of three counters with open ends are recognized as the special cases.
For making the AI behave like a human, the evaluation is affected by three parameters: ac, r, and asvm.Their values are evaluated for each ply of the game, using a single AIM, as depicted in Fig. 12.The "attacking coefficient" ac tells how strongly the decisions are biased towards considering only the agent's own counters.If the value of ac is low, the agent will play defensively considering mostly the opponent's possibilities of winning the game.Randomness coefficient r is used for making random mistakes in the counter placement, and the parameter asvm represents the ability to spot places leading to victory.
The base parameters for different player agents are absent-mindedness, interest in playing the game, tendency to get nervous during the game, aggression, and general pedantry.By altering these initial values, the playing style of an agent changes to reflect the given characteristics.
The AIM uses only four CNs, each having only one Lua line of code.In addition, some code was needed for binding the parameter values to the actual game-playing code.Still, the amount of the code and time for creating an opponent AI was minimal, and the resulting AI seems to work as expected.
Based on this scenario, the AI approach presented in this paper seems to be suitable also for non-NPC AI implementations.In this scenario, as well as in the Gunslinger scenario, the benefit gained by using the Machine Creator tool was obvious.Without using it, the corresponding AI features would have required much more time to be implemented.

Wargus AI
RTS games are often seen as ideal test-beds for AI development.They offer a wide variety of challenges to be coped with.Wargus is a clone/modification of the well-known RTS game Warcraft II: Tides of Darkness (Blizzard Entertainment 1995).Instead of the original engine, Wargus runs on an open-source engine called Stratagus.The Stratagus engine has been previously used in different AI studies [13].Therefore it seemed also to be a relevant test environment for our framework and we chose to implement a test scenario for it.We tested cascading and hierarchical use of AIMs by creating an AI implementation for Wargus 2.2.6.It tries to beat its opponent by gathering an attack force and attacking the enemy relatively early in the game without giving the enemy much time to prepare; i.e. it does not rely on supremacy gained by developing technologies, but on speed.The structure of the AI implementation is depicted in Fig. 13.
The AI is two-tiered: there are command and executing levels.The executing level consists of two AIMS in a cascade.The first of them manages the economy, i.e. recruits peasants for workforce and gives orders about how to balance the efforts between gathering different resources, like lumber or gold.The second one issues orders related to constructing buildings, gathering army, and organizing attacks.This machine, however, is not allowed to work totally autonomously, but it must ask permissions to proceed.The command level consists of a single AIM that may give or deny these permissions.
The three AIMs needed were constructed using the Machine Creator.A total of 13 CNs were defined.The normal approach for implementing an AI for Wargus would have been writing a lengthy Lua script giving different orders concerning different things.We, instead, used such a normal AI script only for running our machines (which were implemented, of course, also as Lua scripts).Although the AI implemented was rather simple, it still took hundreds of lines of code.Writing and organizing it would have been more difficult without using the Machine Creator tool, which let us organize the code block execution with visual feedback, check the syntactical validity of each block separately, and split the total AI implementation into several simple machines without practically any additional work: while working already in a Lua scripting environment, the tool was able to generate all the code needed to run the machines automatically.Due to sharing the attribute data between the AIMs of an AAIA -in this case, our Wargus AI system -it is extremely easy to implement systems requiring message-passing between different components.This was also verified in implementing the Wargus scenario.A screen capture taken along the way of developing the Wargus AI using the Machine Creator is shown in Fig. 9.

CONCLUSIONS
In this paper we presented a general AI approach suitable for computer games and different kinds of simulations using intelligent, autonomous agents.The approach can ease the development of computer games containing large virtual worlds considerably.A crucial part of the contribution of this paper was introducing a new kind of artificial intelligence machines.
The approach was organized into a framework.Using the support offered by it, application developers can define their agents and create living virtual worlds with relatively little effort.The applicability of the framework was tested by creating tools for specializing it easily, and finally by implementing example scenarios.The preliminary results are promising: we were able to create believable and naturally behaving AIs quickly and easily.

Future work
The future work includes creating more different test scenarios and honing the framework structure and the Machine Creator tool based on the observations.We intend also to conduct tests with the State Machine Editor and demonstrate its usefulness.(This issue was left out of this paper, as the focus was on AAIAs.)

Fig. 1 .
Fig. 1.State machine agents.Several agents may share the same state machine model.

Fig. 2 .
Fig.2.Advanced AI agents.Goal-oriented agents can be seen as a special case.

Fig. 12 .
Fig.12.Generating the playing parameters from the player agent characteristics using an AIM.

Fig. 13 .
Fig.13.The structure of the AI system implemented for Wargus using AIMs.