**3. Fundamentals and basic notions**

#### **3.1. Petri Nets**

Petri nets are a "pinball game" for mathematicians (Tado, M., 1990; Peterson, J. L., 1997). It is a particular kind of directed graph, together with an initial state called the initial marking *M*0. The underlying graph G of a PN is a directed, weighted, bipartite graph consisting of two kinds of nodes, called places (P) and transitions (T), where arcs are either from a place to a transition or from a transition to a place. N=(T,P,F) is called a net, iff

$$\begin{cases} \text{(i)} P \cap T = \emptyset, and \\\\ \text{(ii)} \mathbf{F} \subseteq (\mathbf{P} \times \mathbf{T}) \cup (\mathbf{T} \times \mathbf{P}) \text{ is a binary relation} \end{cases} \tag{1}$$

Let N be a net and let *x PT* ( ) , then

$$\begin{cases} \text{'x = \{y | yFx\} is called the set of } pre-conditions\\ \text{'x' = \{y | xFy\} is called the set of post-conditions} \end{cases} \tag{2}$$

Formally, a Petri nets *PN N M* , <sup>0</sup> consists of a structure N and an initial marking *M*<sup>0</sup> , where:

i. N=(P,T,F,W) is a Petri nets structure,

286 Petri Nets – Manufacturing and Computer Science

interactive experience), and

human player.

**3.1. Petri Nets** 

having him feel forced into it?).

**3. Fundamentals and basic notions** 

�

Let N be a net and let *x PT* ( ) , then

 � ∙

i. the balance between writer flexibility vs. user flexibility;

ii. temporal variability (i.e. allowing time to be the key variable for the flexibility in an

iii. transparency (How do we encourage the User to follow a particular destiny without

Moreover, it is necessary to overcome two obstacles (Szilas, N., 2005): technical problem and conceptual problem. This chapter attempts to solve these problems by proposing an integrated framework for deeply combining interactivity and narrative in computer games. The approach is based on separating the actions of the system into two parts, the controllable and the controllable actions. The controllable actions are controllable by the system we model. The system can choose which and when to execute controllable actions. The controllable actions are not controllable by the system, but can occur whenever they are enabled. In this contribution, interactive drama is viewed as a hybrid form of game design and cinematic storytelling for entertainment applications among two skills: artistic and technical. The idea is derived from the study of interactive drama, Petri nets (PN), narrative structures in computer games and game workflow activity process. The main advantages of using PN are that it copes well with branching stories and can evolve in parallel in large virtual world. The proposed idea is supported by some case study called Crazy ball 2. Crazy ball 2 is a platform-type genre, much like the worldwide-known game Mario and the Konami's Castlevania series. It possesses many universally-shared game features such as Hit Points (HP), Game Over, Enemies, and Bosses. One of the advantages of the proposed computer game is the inclusion of the "Freestyle combat system", which allows the user to completely control the attacks of the player using a mouse. Moreover, it possesses a feature which is called an "even game", in which the game challenge level matches the skill of the

Petri nets are a "pinball game" for mathematicians (Tado, M., 1990; Peterson, J. L., 1997). It is a particular kind of directed graph, together with an initial state called the initial marking *M*0. The underlying graph G of a PN is a directed, weighted, bipartite graph consisting of two kinds of nodes, called places (P) and transitions (T), where arcs are either from a place

���� � � = �� ���

�ii�F �P×T� <sup>∪</sup> �T×P� �� � ������ ��������

� = ��|���� �� ������ ��� ��� �� ��� � ����������

�<sup>∙</sup> <sup>=</sup> ��|������ ������ ��� ��� �� ���� � ���������� (2)

(1)

to a transition or from a transition to a place. N=(T,P,F) is called a net, iff


Arcs are labeled with their weights (positive integers), where a k-weighted arc is interpreted as a set of k parallel arcs. Labels for unitary weight are usually omitted.

$$\mathcal{W}: F \to \{1, 2, 3, \cdots\}$$

is a mapping which associates to each arc of the net its weight,

$$\mathcal{M}\_0: P \to \{1, 2, 3, \cdots\}$$

is the initial marking representing the initial state of PN. The state of PN is described by means of the concepts of marking. A marking is a transition function that assigns to each place a nonnegative integer called a token. A token is the main information unit and a primitive concept of PN like places and transitions. If a sufficient number of tokens are contained in specific places, an action is triggered. After firing an action, the tokens that helped to fire this action are removed, and some new tokens are generated. Which tokens fire which action and which action generates tokens to which places is specified by the transition function. In graphical representation, places, transitions, tokens and transition function are represented by circles, rectangles or bars, pellets and arrows respectively. Table 1, illustrates such representations and its interpretations of a PN model. Figure 1 presents an example of a PN model with graphical and mathematical notations.

In modeling using PN, we regard the places as conditions, the transitions as events or actions, and a marking as triggers. A trigger can be associated with an action (action trigger) or a place (place trigger). A transition has a certain number of input and output places representing the pre-conditions and post-conditions of the event, respectively. The presence of a token in a place is interpreted as holding the truth of the condition associated with the place. In another interpretation, "k" tokens are put in a place to indicate that "k" data items or resources are available. Some typical interpretations of transitions and their inputs and outputs places are shown in Table 2.


**Table 1.** Graphical Representations and Interpretations of a PN Model.

State of the Art in Interactive Storytelling Technology: An Approach Based on Petri Nets 289

key concept of WM is task. A task is a piece of work to be done by one or more resources in a pre-determined time interval. A task item is a task that needs to be executed to handle a specific case. Task items are executed by resources. Synonyms for resource are actor or participant. A work item which is being executed by a specific resource is called an activity, which is an actual performance of a work item. The activity contains the rule entities to describe the conditions under which the activity may be fired. A workflow procedure defines a partial ordering of tasks to handle cases of a specific type. A workflow process definition comprises a workflow procedure, a set of resources and a strategy to map task items to resources. Figure 3 shows that a workflow has three dimensions: case, resource and process definition dimension. A number of dots shown represent either a work item (case+task) or an activity (case+task+resource). Note that, work items link cases and tasks.

A "workflow process definition" dimension specifies how the cases are routed along the tasks that need to be executed. Routing of cases describes the lifecycle of a case, i.e., which tasks need to be performed and in which order. Four types of routed are identified as shown in Figure 4: sequential (tasks are executed sequentially), parallel (task B and C are executed in parallel), conditional (either task B or C is executed), and iteration (multiple B's). These four routed types outlined the currently accepted narrative structures used in the creation of computer games (Mark Reidl, O., Michael R., 2005). For instance, linear narrative which corresponds to the sequential routing is a traditional form of narrative in which a sequence

Activities link cases, tasks, and resources

**Figure 3.** A three dimensional view of a workflow

**Figure 4.** Four routing constructions demonstration.

**Figure 1.** An illustration example of a PN model with graphical notation (left), and mathematical notation (right).


**Table 2.** Some typical interpretations of transitions and places.

The dynamics of the net is described by moving tokens among places according to the transition firing rules or enabling test in marking. A transition t is said to be enabled if each input place P of t is marked with at least W (P, t) tokens, where W (P, t) is the weight of the arc from P to t. Once enabled, a transition will fire when its associated event occurs. A firing of an enabled transition t removes W (P, t) tokens from each input place P of t, and adds W (t, P) tokens to each output place P of t, where W (t, P) is the weight of the arc from t to P. Figure 2 demonstrates an example for the transition firing rules of a PN model shown in Figure 1. In the PN of Figure 2, only transition t2 is enabled; t1 is not enabled because it would require two tokens in P1 to fire, since W (P1, t1) =2. When t2 is fired, the tokens in P2 and P3 are removed and P4 receives one token (see Figure 2).

**Figure 2.** PN marking example before and after firing the enabled transition t2.

#### **3.2. Workflow management concept**

Workflows are gaining a lot of interest both in the business and scientific environments for automating the execution of complex IT processes. The term workflow management (WM) refers to the domain which focuses on the logistics of business processes (Van der Aalst, W., 1998). The goal of workflow management is to handle cases as efficiently and effectively as possible by the right resource (e.g. actor, person, participant, or application) at the right time. Workflows are case-based, i.e. every piece of work is executed for a specific case. The key concept of WM is task. A task is a piece of work to be done by one or more resources in a pre-determined time interval. A task item is a task that needs to be executed to handle a specific case. Task items are executed by resources. Synonyms for resource are actor or participant. A work item which is being executed by a specific resource is called an activity, which is an actual performance of a work item. The activity contains the rule entities to describe the conditions under which the activity may be fired. A workflow procedure defines a partial ordering of tasks to handle cases of a specific type. A workflow process definition comprises a workflow procedure, a set of resources and a strategy to map task items to resources. Figure 3 shows that a workflow has three dimensions: case, resource and process definition dimension. A number of dots shown represent either a work item (case+task) or an activity (case+task+resource). Note that, work items link cases and tasks. Activities link cases, tasks, and resources

**Figure 3.** A three dimensional view of a workflow

288 Petri Nets – Manufacturing and Computer Science

notation (right).

**Figure 1.** An illustration example of a PN model with graphical notation (left), and mathematical

 Input Places Transition Output Places Pre-conditions Event Post-conditions Input data Computation step Output data Conditions Clause in logic Conclusion(s) Resources needed Task/job/behavior Resources released

The dynamics of the net is described by moving tokens among places according to the transition firing rules or enabling test in marking. A transition t is said to be enabled if each input place P of t is marked with at least W (P, t) tokens, where W (P, t) is the weight of the arc from P to t. Once enabled, a transition will fire when its associated event occurs. A firing of an enabled transition t removes W (P, t) tokens from each input place P of t, and adds W (t, P) tokens to each output place P of t, where W (t, P) is the weight of the arc from t to P. Figure 2 demonstrates an example for the transition firing rules of a PN model shown in Figure 1. In the PN of Figure 2, only transition t2 is enabled; t1 is not enabled because it would require two tokens in P1 to fire, since W (P1, t1) =2. When t2 is fired, the tokens in P2

Workflows are gaining a lot of interest both in the business and scientific environments for automating the execution of complex IT processes. The term workflow management (WM) refers to the domain which focuses on the logistics of business processes (Van der Aalst, W., 1998). The goal of workflow management is to handle cases as efficiently and effectively as possible by the right resource (e.g. actor, person, participant, or application) at the right time. Workflows are case-based, i.e. every piece of work is executed for a specific case. The

**Table 2.** Some typical interpretations of transitions and places.

and P3 are removed and P4 receives one token (see Figure 2).

**3.2. Workflow management concept** 

**Figure 2.** PN marking example before and after firing the enabled transition t2.

A "workflow process definition" dimension specifies how the cases are routed along the tasks that need to be executed. Routing of cases describes the lifecycle of a case, i.e., which tasks need to be performed and in which order. Four types of routed are identified as shown in Figure 4: sequential (tasks are executed sequentially), parallel (task B and C are executed in parallel), conditional (either task B or C is executed), and iteration (multiple B's). These four routed types outlined the currently accepted narrative structures used in the creation of computer games (Mark Reidl, O., Michael R., 2005). For instance, linear narrative which corresponds to the sequential routing is a traditional form of narrative in which a sequence

**Figure 4.** Four routing constructions demonstration.

State of the Art in Interactive Storytelling Technology: An Approach Based on Petri Nets 291

Computer games are defined as an activity with some rules engaged in for an outcome. Key components of games are goals, rules, challenge, and interactivity. Games are regarded in terms of three levels of temporal design, from simulation at the lowest time scale, through the design of game moves above the simulation level, to the structure of specific narrative patterns at the highest level. The methodology in our approach is based on the study of workflow process under these levels for the structural parts of a computer games and is

The diagram in Figure 7 is composed of three parts: the "Input" peripheral devices allowing the user to enter choices. These choices are then evaluated by the rules of the "Computing" part, in order to produce a "result". This result is finally communicated to the player through the "Output" device. Computer game development is a tremendous task that requires different roles for the storyteller and audience, and a lot of resources including: storytelling elements and elemental interplay. Storytelling elements includes: narrative, plot, and story. The interplay of elements in the game environment consists of: structure, theme and metaphor. The structure describes the influence of plot on narrative. Theme is the expression of the story within the plot. Metaphor is the means by which story is encoded within the narrative. From the technical point of view, game can be seen as a client-server application connected with some data. From the conceptual point of view for game representation and according to (Salen, K., Zimmerman, E., 2003), computer games are defined as an activity with some rules engaged in for an outcome. Therefore, there is a need to develop an integrated framework for deeply combining interactivity and narrative. As a sort for achieving this goal and under the study of workflow management concept, Figure 8 shows a design of a workflow activity process for the conceptual representation of computer

Figure 8 shows how the conceptual representation of a game can be modeled as a series of processes, where each process consists of some activities. Activity is a description of a piece of work that forms one logical step within a process. An activity has one or multiple roles, zero or multiple rules, zero or multiple event and one or more multiple data. Partial order relationships between activities (e.g. sequential, parallel, alternative and looped) are notated with the arc, which links the activity entity to itself. The activity also contains the rule entities to describe the conditions under which the activity may be fired. The rule is used to

**4. Methodology** 

shown in Figure 7.

games.

**Figure 7.** The structural parts of computer games.

(a) Linear Narrative Progression (b) Branching Narrative Progression

**Figure 5.** An illustration for both linear and branching narrative progressions.

of events is narrated from beginning to ending without variation or possibility of a user altering the way in which the story unfolds or ends. Some computer games use branching narrative in which there are many points in the story at where some action or decision made by the user alters the way in which a narrative unfolds or ends. Both narratives are shown in Figures 5(a)-(b).

Since Petri Nets (PN) are a process modeling technique, then modeling a "workflow process definition" onto PN is straightforward: tasks, conditions, and cases are modeled by transitions, conditions and tokens respectively. Figure 6 shows how all these concepts can be mapped onto the Petri net. Table 3 shows the mapping between the workflow process definitions and PN terms.

**Figure 6.** Mapping a process definition onto Petri nets.


**Table 3.** Mapping Workflow process onto Petri nets (PN) terms.
