Modeling Games with Petri Nets
Total Page:16
File Type:pdf, Size:1020Kb
Modeling Games with Petri Nets Manuel Araújo Licínio Roque Departamento de Engenharia Informática Departamento de Engenharia Informática Faculdade de Ciências e Tecnologia Faculdade de Ciências e Tecnologia Universidade de Coimbra Universidade de Coimbra Coimbra, Portugal Coimbra, Portugal [email protected] [email protected] ABSTRACT game systems. We will then discuss some of their This paper describes an alternate approach to the modeling advantages and disadvantages when compared to the other of game systems and game flow with Petri nets. Modeling modeling languages. languages usually used in this area are of limited efficiency MODELING IN GAME DESIGN when it comes to validating the underlying game systems. Natural language is easy to read, but it is not easy to review We provide a case study to show that Petri Nets can be used a large natural language specification [15]. For that reason with advantages over other modeling languages. Their we use charts and diagrams to explain things visually and graphical notation is simple, yet it can be used to model synthetically. This kind of communication can be as complex game systems. Their mathematically defined expressive as and easier to understand than the verbal structure enables the modeled system to be formally descriptions used for the same information [15]. People analyzed and its behavior’s simulation offers the possibility doing game design make intensive use of visual of detecting unwanted behaviors, loop-holes or balancing communication [9, 10, 12, 13, 19]. The flow of the game is issues while still in the game design stage. usually depicted visually instead of a pure textual approach Keywords [10, 13, 19]. We will now take a look at some of the most Game design, Petri Nets, game flow modeling, simulation popular diagrams in this branch of software design. INTRODUCTION Unified Modeling Language (UML) is a modeling language Visual communication is an essential part of software widely used in software specification and design. As of design. In game development projects, this sentence version 2.0, it comprises 13 diagrams, divided into 6 remains true. Be it for identifying and constructing use categories [21]. A number of these can be of great use to cases, charting the flow between menus, modeling a game design [9]. Use cases are used to represent actors sequence of events or showing the relationship between (player, external systems, etc.) and their actions or actors in the game, diagrams and charts are extensively interactions with the system. They can be used to identify used throughout the conceptual and design phases of game and collect requirements in the early stages of conception. development [9, 10]. The representations used for this Other diagrams, like sequence, class and activity diagrams, purpose, however, present a number of limitations when it can help game designers further document and structure comes to the verification, validation and simulation of the ideas and later help the programmers structure their code in underlying system [11, 17, 18]. This prevents designers the development phase. from using these diagrams in a more effective way, such as As proposed in [9], although with a bigger focus on use for finding balancing issues or problems within the game's case diagrams, UML makes the game designer divide flow. his/her project in a number of different kinds of diagrams, In this paper, we will explore Petri Nets for modeling a each one serving its purpose. Those who are going to read game’s systems and flow. We will try to show that this those diagrams have to be able to understand all of them approach can be as simple and yet more powerful than other and cope with possible semantic inconsistencies [18], since graphical tools used in this domain. they define a range of possible interpretations instead of conveying an exact meaning [18, 20]. UML diagrams, We will begin by analyzing modeling languages used in especially when used at the conceptual level, lack formal game design. Next we will describe Petri Nets structure, semantics that prevent them from being used in rigorous how they work and some useful extension to their basic model analysis [11, 17, 18]. In large, complex models this structure. In the following section we will develop the case can present a problem since validation can be study to show how Petri Nets can be used in describing compromised. Although there are tools for analysis and Breaking New Ground: Innovation in Games, Play, Practice and Theory. Proceedings of DiGRA 2009 © 2009Authors & Digital Games Research Association (DiGRA). Personal and educational classroom use of this paper is allowed, commercial use requires specific permission from the author. simulation, these use intermediate models like graphs or amongst events or the existence of appropriate Petri nets [11] or focus more on syntax and consistency synchronization [1]. They can also be used to measure the checks [17]. There are also a number of proposals for the performance of the underlying system [1, 7]. definition of formal semantics [11, 17, 20], but none of Petri nets can be described both mathematical and these are yet part of the UML standard. graphically. For the sake of simplicity, this paper will not Other popular diagrams are flowcharts. As the name states, feature the mathematical description. Most of the Petri net it is a chart where one can model the flow of events in a diagrams present in this document were made using Yasper system. They are made up processing steps, conditional [5]. To illustrate a difference in notation, another diagram branching nodes and arrows connecting them. Flowcharts was made using Woped [6]. can be used to explain the steps needed for a certain action Graphically, Petri nets are described as a diagram with to occur or simply to document the flow of the game [10, circles (places), bars or squares (transitions) and arrows 12, 13, 16]. Decision trees are a type of flowchart that (arcs) connecting them. Depending on the interpretation the branch on every situation where the player can make a designer wishes to give them, places can represent decision, effectively mapping all the possible decisions and conditions, input/output data or resources. Transitions can outcomes in a game [16, 19]. be interpreted as events, tasks or clauses, among others [2]. Flowcharts are limited to the modeling of sequential, non- Places can have multiple arcs from and to transitions and concurrent systems, which is something most games are not. transitions can have multiple arcs from and to places. A Simulation can be done only in a case-by-case fashion, as transition can have arcs going back to its input places, there is no way to actively insert, for instance, conflict or symbolized in figure 1 by a double arrow. A place can hold concurrency for resources. While they can be used to chart one or more tokens, symbolized by one or more dots. simple decision based systems, when decision depends of Depending on the interpretation given to places, a token can external processes running in parallel their capabilities are represent resources or whether a condition is true or false limited. [1]. In its basic incarnation, a transition is enabled and can Petri nets are both a mathematical and a graphical tool for fire when all the places that are connecting to it hold at least modeling, analyzing and designing discrete event systems one token. When the transition fires, it removes (consumes) used in many different industries [1]. When compared with a token from all the incoming places and adds (produces) behavior modeling based on Statecharts, e.g., [15], Petri another token in all the outgoing places. Nets tend to be, in general, a more economic representation In the example given in figure 1, T1 has one input place when state-space complexity increases. (P1) and two output places (P1 and P2) and it is enabled In [22], Brom and Abonyi describe a technique for because all of its input places have tokens. In figure 2, T1 "authoring a nonlinear plot and managing a story" has consumed a token from P1 and produced another in P1 according to this plot using Petri nets. This technique makes and P2. The transition can fire again indefinitely because use of both the formal and graphical natures of Petri nets P1 will always have a token. for drafting, simulating and building plots for a story-driven More complex behaviors can be modeled by adding places virtual reality application. It was later applied successfully and transitions to the diagram. In figure 3 we have a to the story manager of serious games Europe 2045 [24] situation where a F1 car is making a pit stop to change all and Karo [23]. We believe that Petri nets can be applied to of its tires. When the Stop transition fires, the places other areas of game design, not just plot description or story managing. OVERVIEW OF PETRI NETS Petri Nets were created by German mathematician Carl Adam Petri for the purpose of describing chemical processes [3]. They can be applied to many different areas, Figure 1: Simple Petri Net with two places and one such as the modeling of production lines, distributed- transition database systems and communication networks or the design and analysis of workflows and business processes, among many others [1, 2]. They can also simulate such processes with the help of a number of computer applications [4, 5, 6]. Figure 2: Result after transition has fired Due to the fact that Petri nets can be described as a set of algebraic equations [3], they are considered as a powerful representing the tires – front and rear, left and right – analysis tool [1, 2, 7]. Petri nets can be used to check for receive a token.