<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Using Petri Nets for Analysis of Navigation Paths in Constrained Graphs - Application to Roguelike Games</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Luis Gomes</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
          <xref ref-type="aff" rid="aff3">3</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>José Ribeiro-Gomes</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>João-Paulo Barros</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
          <xref ref-type="aff" rid="aff4">4</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Center of Technology and Systems (CTS)</institution>
          ,
          <addr-line>UNINOVA</addr-line>
          ,
          <country country="PT">Portugal</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Instituto Superior Técnico</institution>
          ,
          <country country="PT">Portugal</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Intelligent Systems Associate LAboratory (LASI)</institution>
          ,
          <country country="PT">Portugal</country>
        </aff>
        <aff id="aff3">
          <label>3</label>
          <institution>NOVA University Lisbon, School of Science and Technology</institution>
          ,
          <country country="PT">Portugal</country>
        </aff>
        <aff id="aff4">
          <label>4</label>
          <institution>Polytechnic Institute of Beja</institution>
          ,
          <addr-line>Beja</addr-line>
          ,
          <country country="PT">Portugal</country>
        </aff>
      </contrib-group>
      <fpage>283</fpage>
      <lpage>298</lpage>
      <abstract>
        <p>In many areas of application, graphs have been used to support path planning addressing navigation challenges in dynamic environments. Applications target very diverse areas, ranging from manufacturing and robotics to video games, including georeferencing applications in our daily lives considering real-time trafic conditions. This paper focuses on applications where navigation through a predefined map consisting of distinct areas (rooms or nodes) connected by pathways needs to be defined. Roguelike games, a genre defined by procedurally generated environments and random map creation, are used to validate the proposal. Navigation is constrained by resource availability and specific conditions that allow or block movement between adjacent areas. Players can collect specific resources in visited areas, which can be used to allow/unlock passages. The main goals include determining whether, given a specific randomly generated map/graph, along with all associated constraints and resources, the game is inviable (when it is not possible to reach the final area of the game), nonviable (when depending on the player's options, it is possible or not to reach the final goal), or viable (when the ultimate goal area can always be reached regardless of user's choices over time). This paper proposes a strategy for translating the map and associated graph into a Petri net model. Then, the viability level of the game can be determined by constructing and analyzing the associated reachability graph from the Petri net model. A set of examples are presented illustrating typical situations.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Procedurally generated games</kwd>
        <kwd>Graph Analysis</kwd>
        <kwd>Reachability graphs</kwd>
        <kwd>Petri nets</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>In several areas of application, selecting a strategy for navigation is of paramount importance. In
this sense, path planning is a crucial consideration in navigation. A significant number of strategies
(probably the most used ones) rely on a characterization of the environment by a set of nodes and known
costs associated with traversing from one node to another. This directly supports the construction of a
graph, facilitating the determination of the optimal path from an initial node to a destination node.</p>
      <p>
        Graph-based algorithms, being easily processable [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], are extensively employed in addressing
pathplanning challenges. In these algorithms, the space is characterized as a collection of cells, and each
connection between cells is assigned a weight representing its associated cost. These costs may account
for various constraints, such as distances, energy, time, resources, or other types of resources, depending
on the specific area of application.
      </p>
      <p>
        Dijkstra introduced a pioneering algorithm in 1959 [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], which remains highly relevant for determining
a specific path with minimized associated costs. Various adaptations of Dijkstra’s algorithm have been
proposed. Best-First-Search [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] associates cost with the distance to the goal. A* [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] is an extension
that combines Dijkstra’s algorithm and Best-First-Search, evaluating paths based on both cost and the
distance of the node to the goal. Dynamic A* [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] extends A* to dynamic environments by accommodating
changing costs over time.
      </p>
      <p>Several alternative approaches have been proposed to tackle path planning in diferent application
areas. Some still consider static scenarios, while others cope with dynamic scenarios (such as
georeferenced trafic applications). Some are bio-inspired, while others consider some physics-related
features.</p>
      <p>
        In the first group considering bio-inspired alternatives, particular reference is given to the ant colony
optimization algorithm, which mimics the behavior of ant colonies [
        <xref ref-type="bibr" rid="ref5 ref6">6, 5</xref>
        ]. This algorithm seeks to find
the shortest path from a nest to a food source and back by emulating ant behavior, which involves
the release of pheromones. These pheromones are detected by other ants, guiding them towards the
established path.
      </p>
      <p>
        In the second group emphasizing physics-inspired approaches, one can find the artificial potential
ifelds method introduced in 1985 [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. This model utilizes potential fields, where the selected path for
the movement is influenced by two forces: attraction towards the goal and repulsion from obstacles.
The combined efects of these forces determine the direction to follow.
      </p>
      <p>As in Dijkstra’s algorithm and other referred algorithms, the focus is on the shortest path between
two specific nodes; one node in the path is visited once at most. In applications where additional
constraints (other than costs) need to be considered, those approaches would need severe changes (if
not wholly inadequate). This is the case when the movement along the path needs the possession of a
specific resource, which in turn can be obtained in some node not belonging to the shortest path to
the destination. For instance, while at node A, it may be necessary to visit some other node to bring a
specific resource, which will be used afterward to unlock some movement between nodes and return to
node A to proceed toward the goal. In this sense, immediate applicability of the referred algorithms is
not possible.</p>
      <p>This is the case for the application area of roguelike games, where the game’s map is randomly
generated and can be represented using a graph. Movements between rooms in the map could be
constrained by some doors, which can be unlocked using specific resources (keys, weapons, or others);
those resources can be obtained in some other room (node). Fig. 1 shows two simple maps sufering
from an ill-formed condition.</p>
      <p>(a) An inviable map.</p>
      <p>(b) A nonviable map.</p>
      <p>In Fig. 1(a), to go from RoomA to RoomE, it is necessary to move along RoomB to RoomC. However,
for this movement, the player needs to have a specific resource (key K1, in this case), which in turn can
only be granted when reaching RoomD. In this case, the game is inviable, as it cannot be concluded.
Another annoying situation is illustrated in Fig. 1(b), where the movement from RoomA to RoomG
needs the possession of key K1 (to move from RoomD to RoomE). However, if the player chooses to
move away from RoomC without visiting RoomB, they will be blocked in RoomD. In this case, the final
room might not be reached depending on the player’s options (actions over time). This is considered as
a nonviable map. Only maps allowing the player to reach the final room regardless of their options are
acceptable (as in roguelike games, resetting the game halfway would lead to an entirely new generated
map/graph, resulting in loss of player progression).</p>
      <p>This paper analyzes potential navigation paths within a randomly generated map, where navigation is
constrained by particular conditions associated with specific movements between rooms. This scenario
is particularly relevant in roguelike games, which are procedurally generated, and where a significant
challenge lies in ensuring that, following the random generation of maps and constraints, players can
always reach the ultimate goal without encountering deadlock situations.</p>
      <p>
        The proposed approach involves translating the constrained map into a Petri net model, a strategy
previously suggested in other works [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], and complementing and extending the work presented in
[
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. By constructing the Petri net model associated with the map/graph of the game, the associated
reachability graph is generated, and its analysis answers the questions mentioned earlier. To the best of
our knowledge, this is the first work tackling the classification of possible navigation paths between
two nodes in graphs, which in turn were generated as representing constrained maps.
      </p>
      <p>The paper is structured as follows. In Section 1, the motivation for the work identifying the challenge
to be addressed is presented, while Section 2 briefly describes diferent approaches to building a roguelike
game map/graph, as well as introducing a simple map/graph random generator used for validation of
the approach afterward. Section 3 presents the proposed approach to perform the analysis of the map
characteristics, while Section 4 is devoted to presenting the steps to obtain the Petri net model from the
map/graph, and Section 5 focus on the analysis strategies. Section 6 is dedicated to the validation using
a set of examples, and Section 7 concludes.
2. Building the map and the graph of the roguelike game
The proposed approach relies on a graph representation of the map, so it can be translated to a Petri
Net representation and benefit from associated analysis techniques.</p>
      <p>Though relying on a graph representation may seem like a too-limiting requirement, in this section,
we present a non-exhaustive list of map generation techniques used in roguelikes and show that this
is not the case and how they can be mapped to a graph representation. In fact, some map generation
techniques already rely on defining a map graph as a starting point, and others may be translated to a
graph representation afterwards. Consequently, we aim to show that the proposed approach is suitable
for diverse implementations of map generation.</p>
      <p>We structure the section into techniques that rely on defining a map graph beforehand and then
translating it into a map, and techniques that define a map straight away but may then be represented
as graphs. All shown techniques have been used in games, and none consider including conditions to
constrain movements between nodes/rooms (such as the need to unlock doors between rooms).</p>
      <sec id="sec-1-1">
        <title>2.1. Graph First</title>
        <p>The following approaches start by defining a graph structure that represents the map only after
populating the actual playable map.</p>
        <p>
          One approach is Binary Space Partitioning [
          <xref ref-type="bibr" rid="ref10 ref11">10, 11</xref>
          ], which recursively divides a space into smaller
spaces. The random subdivisions can be interpreted as rooms with diferent layouts, sizes, and
connections between them. They inherently have a hierarchical, tree-like structure.
        </p>
        <p>
          Another technique consists of defining a Voronoi diagram using a set of points to subdivide the
map [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ]. The regions inside the diagram might correspond to diferent areas of interest, and the edges
may correspond to connections or transitions.
        </p>
        <p>Lastly, some games have a pre-defined, manually created graph specifying the map’s layout. This
approach usually relies on a set of pre-made rooms that are randomly selected to instantiate the graph.
One such game is Enter the Gungeon1.</p>
      </sec>
      <sec id="sec-1-2">
        <title>2.2. Map First</title>
        <p>Contrary to the approaches above, the following approaches focus on generating the map straight away.
Some approaches may be translated to a graph afterward, while others may be more dificult.</p>
        <p>
          A common approach is to use cellular automata [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ]. It considers that the map is a grid of cells, each
belonging to a specific group or state, such as room, door, wall, water, . . . . Starting from an initial cell, it
iteratively considers the neighboring cells in order to populate the world in a way such that a series of
rules are followed.
        </p>
        <p>Perlin noise is also prevalent for map generation. It is a gradient noise function that produces smooth,
continuous patterns. Randomness is introduced through noise generation, creating natural-looking
variations in terrain. An example of a very popular game that uses Perlin noise to define its world is
Minecraft2.</p>
        <p>
          Random Walk and Drunkard’s Walk [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ] are both approaches that involve placing tiles in the world
by iteratively moving through the map in a random direction at each step. These techniques create
winding paths, favored for cave systems, paths, roads, or rivers.
        </p>
        <p>Yet another approach is Wave Function Collapse3, which uses an input pattern (such as an image
or small region of what the world such look like) and a set of constraints. One game that uses this
technique is Caves of Qud4.</p>
      </sec>
      <sec id="sec-1-3">
        <title>2.3. Map/graph random generator used for validation</title>
        <p>In order to validate the proposed approach on randomly generated maps/graphs associated with
roguelike games, a simple map/graph generator was used. It is used in the examples in the validation
section. As stated, there is no loss of generality, as all implementations that produce a graph map are
compatible with the proposed approach.</p>
        <p>
          The adopted technique for the implemented simple map/graph generator was inspired by an online
tutorial 5, and can be seen as an extension of cellular automata. The code of the developed map/graph
random generator is available at https://github.com/miguelmtsvitoria/RandomMap, which is a result of
[
          <xref ref-type="bibr" rid="ref12">12</xref>
          ].
        </p>
        <p>In this simple map/graph generator, a grid map was considered, where cells may contain a room.
These rooms may be connected to adjoining rooms by means of doors placed North, East, South, and/or
West, so that no room may have a door that connects to nothing. Furthermore, each room may have
more than one door, provided there is only one door in each direction and that all rooms are connected.</p>
        <p>The implemented map generator starts by defining a central room with four doors, one on each side.
Afterward, it iteratively checks each available door and adds a compatible room. For example, for the
East door, we must add a room that has a West door and may have additional doors. Each room added
may contain new doors, which allow the map to develop and expand from that central node.</p>
        <p>One key concept in this approach is that we may define a passage between two rooms as bidirectional
or unidirectional or as requiring a key (or other constraint) to open a door.</p>
        <p>The size of the map, the overall number of connections per room, restrictions on doors, and so on
may be controlled to change the dificulty of the game.</p>
      </sec>
      <sec id="sec-1-4">
        <title>2.4. Representing the graph</title>
        <p>The representation of the map layout randomly generated by the application described in the previous
sub-section is a simple XML file storing the list of rooms (dungeons) and the list of transitions between
rooms, as presented in Table 1, which stores the information associated with the (very simple) map of
Fig. 2. In this example, one key is available (at RoomB), which is needed to unlock the transition from
RoomD to RoomE (the final room).
2https://www.minecraft.net
3https://github.com/mxgmn/WaveFunctionCollapse
4https://www.cavesofqud.com
5https://www.youtube.com/playlist?list=PLBIb_auVtBwA-qr2-WnWX0LjZXkqKu5Aj
3. Proposed approach for analysis of the game’s map/graph
The proposed approach to support the analysis of the map/graph randomly generated for a roguelike
game starts with the translation into a Petri net model.</p>
        <p>The player (there is only one player) starts the game in one specific room (the initial room), and
the goal is to reach the final room. Some rooms may contain some items (called keys in this paper),
which can be collected by the player when visiting the room. These items can unlock some movements
between rooms, which means that some passages between rooms can be constrained by the possession
of a key.</p>
        <p>Petri nets modeling was selected due to its support for the representation of resources (the keys, in
this case) and further evolution of movements between rooms constrained by those resources in a very
natural way (benefiting from local evaluation when executing the Petri net model).</p>
        <p>Considering the type of maps/graphs to analyze, the state space associated with the Petri net model
is finite. This means that building the reachability graph is a viable solution to fully analyze the
map/graph’s properties.</p>
        <p>Fig. 3 presents the proposed flow to allow identification of the viability level of the generated
map/graph, considering the following possible classifications:</p>
        <p>• inviable game: where the final room cannot be reached.
• nonviable game: where the final room can be reached or not depending on the player’s options
(for instance, if the player chooses to follow a one-way direction dead-end, they will be stuck
there, and the final room will not be reached).
• viable game with inaccessible rooms: where the final room is always reachable regardless of the
player’s options, but there are rooms that cannot be visited (which represent resource consumption
without purpose); in this case, pruning those rooms from the map is recommended.
• viable game: where the final room is always reachable regardless of the player’s options, and all
rooms can be visited.</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>4. Generating the Petri net model</title>
      <p>The first step of the proposed approach is the generation of the Petri net model, which describes the
possible player movements through the map. Two steps are considered to obtain the Petri net model:
• Applying a set of translation rules to each of the map/graph characteristics into Petri nets
constructs. The rules are applied separately to each map/graph characteristic, leading to a Petri
net model composed of several disjoint sub-models.</p>
      <p>• Applying net addition operation of the disjoint sub-models to obtain the global Petri net model.
The Place-Transition Petri net class is considered for the models to be produced.</p>
      <p>The translation rules are divided into two groups:
• One group focused on translating the rooms (the graph nodes). Table 2 shows (four) rules applied
to:
– the initial room.
– the final room (the goal of the game).
– an intermediary room.</p>
      <p>– a room holding some resource (for instance a key, or other resource used in the game)
• Another group focused on translating the movements between rooms/nodes. Table 3 shows five
rules applied to:
– the transition between two rooms (unidirectional).
– the transition between two rooms (bidirectional).
– the transition between two rooms (unidirectional) constrained by the possession of a resource
(e.g., a key).
– the transition between two rooms (bidirectional) constrained by the possession of a resource
(e.g., a key).
– the asymmetric transition between two rooms (bidirectional) constrained by the possession
of a resource in one direction and unconstrained in the other.</p>
      <p>More translation rules could be defined to model additional features of map/graph transitions.
Examples may include other types of asymmetric transitions or consider a cost on a specific resource
instead of the possession of a key (leading to the consumption of parts of the resource).</p>
      <p>
        After applying the set of translation rules to all components of the map/graph, a set of disjoint
sub-models is obtained. The generation of the final Petri net modeling of the whole map/graph can be
summarized in the following steps, illustrated in Figure 4:
• Generate a sub-model for each room considering the rules of Table 2. While places will keep the
names, the names of the transitions needed in the sub-models will be unique and sequentially
generated (using a sequence number, such as t1, t2, ...). These steps are numbered from 1 to 5 in
Figure 4.
• Generate a sub-model for each transition considering the rules of Table 3. While the places
associated with rooms of the instance of the sub-model are updated with the names of specific
rooms, transitions will be generated, keeping the unique names strategy (continuing the sequence
numbering). These steps are numbered 6 to 9 in Figure 4.
• the last step in the process of generating the final Petri net model associated with the randomly
generated graph/map (step 10 in Figure 4) uses the net addition operation [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ], where all places
with equal names will be fused into one with the same name holding a marking that is the sum
of all tokens in the fusing set (in this sense, only place fusion is used in the referred net addition
operation).
      </p>
    </sec>
    <sec id="sec-3">
      <title>5. Analysis of the map</title>
      <p>
        The overall strategy to determine the viability level of the randomly generated map/graph can be
described using Algorithm 1. As previously mentioned, the generation of map/graph examples for
validating the approach is performed using the application described in sub-section 2.4, which generates
the XML file describing the map, as well as the associated PNML file associated with the generated
Petri net model after applying the translation rules presented in Section 4. The IOPT-Tools web-based
framework [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] is used to read the PNML file and to support the remaining steps to classify the viability
level of the generated map/graph as described through the Algorithm 1. The IOPT-Tools framework,
available at http://gres.uninova.pt/IOPT-Tools/, uses one specific class of Petri nets, the Input-Output
Place-Transition nets (IOPT-nets) [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ], which was selected for convenience of the authors, but other
tools could also provide similar support for implementation of Algorithm 1 (Note: the Petri net models
presented were edited using the IOPT-Tools framework, so instead of using a black dot to represent a
token, the number "1" is used instead).
      </p>
      <p>The proposed strategy heavily relies on the construction of the reachability graph, which is a directed
graph that represents all reachable states, considering a specific initial marking of the Petri net model.
The nodes of this graph are all the reachable markings (global marking states), and the arcs connecting
those nodes have an annotation referring to the set of transitions that produced that change in state.</p>
      <p>
        After importing the PNML file to the IOPT-Tools framework, the associated reachability graph
containing all reachable markings is obtained (using the "Generate State Space" tool option [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ]) (line 2
of Algorithm 1). After that, the IOPT-Tools query system [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ] is used to obtain the remaining answers.
More specifically, a set of queries is formulated (using the "Query Editor" tool option), and associated
answers are obtained (using the "Query Results" tool option).
      </p>
      <p>In particular, the following queries are presented, and the following answers are obtained:
• the first query is RoomXX = 1, where RoomXX is the final room for the map/graph under analysis;
the result will provide a list with the numbers of the states of the reachability graph that contains
RoomXX marked (line 3 of Algorithm 1, providing the SuccessMarkings set). If the result is the
empty set, then the map/graph is inviable (if statement in line 4 of Algorithm 1).
• a second set of queries has the form REACH(GlobalMarking), where GlobalMarking is the number
of each of the reachability graph states obtained as a result of the previous query; this corresponds
to the loop in line 11 of Algorithm 1; the result will provide a list with the numbers of the states
of the reachability graph that are in a path leading to GlobalMarking (line 12 of Algorithm 1).</p>
      <p>After knowing the list of reachability graph states that have a path to a global marking of success
(where the final room is marked), comparing with the total number of reachability graph states (line
14 of Algorithm 1) it is possible to conclude if the map/graph is nonviable (line 16 of Algorithm 1) or
viable (else in line 17 of Algorithm 1).</p>
      <p>Finally, when the map/graph is viable and the reachability graph is obtained (using the "Generate
State Space" tool option), the information of the maximum number of tokens in all places can be known,
Algorithm 1 Checking the viability of the map and the reachability of the game’s final objective
Require:     = (, , ,  =  → N)
Require:  ⊆  ×  ∪  × 
Require:  ⊆ 
Require:    ∈ 
1: function CheckMap(   , ,   )
2: ℎℎ ← BuildAssociatedReachabilityGraph(   )
3:   ← {  ∈   (ℎℎ) :</p>
      <p>(  ) &gt; 0}
if   = ∅ then
◁ The game is inviable (impossible to reach FinalRoom)
return  __  
else
▷
▷
▷
▷
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
◁ game final room (objective) is reachable ▷
◁ success markings are net markings where place modeling the final room is marked ▷
   ℎ ← ∅
for all  ∈   do
   ℎ ←    ℎ ∪</p>
      <p>ℎ( (ℎℎ), )
end for
if |   ℎ| &lt; | (ℎℎ)| then
◁ The game is nonviable (concluding the game depends on player options
return  __   
else
  ← ∅
for all  ∈  do
if ∃  ∈    ℎ : () &gt; 0 then</p>
      <p>←   ∪ 
end if
end for
if | | = || then
◁ FinalRoom can always be reached
return  __ _ __ _  
else
◁ The game is viable (FinalRoom can always be reached), but at least one room is not</p>
      <p>reachable, so the map/graph should be pruned
29: return  __ _  __ _  
30: end if
31: end if
32: end if
33: end function
allowing a decision based on all rooms having been visited (if statement in line 24) in the map/graph.
Either all were visited (viable map with all rooms visited, line 26 of Algorithm 1) or only some (viable
map with some rooms not reachable, line 29 of Algorithm 1).</p>
      <p>Coming back to the simple map/graph of Figure 2, the associated reachability graph is presented in
Figure 5 (using a tree representation, where some leaves denoted by squares are in fact representing
loops returning to some already existing state), where two deadlock states are presented colored red: the
state 9, associated with goal achievement (having final marking at places RoomE and unlocked_by_K1),
and state 6, associated with a situation where final goal is not reachable (due to the player did not take
the K1 key when visiting RoomB and moved afterward to Room D, where it is not possible to return to
Room B).</p>
      <p>Using the IOPT-Tools framework and the query "RoomE = 1", we got the answer "State 9". Afterward,
for the query "REACH(9)", the answers were "States 0, 1, 2, 3, 4, 8, 9", which means that it is possible to
reach State 9 from 7 reachable states. For the query "NOT REACH(9)", the answer was "State 6", which
means that from State 6, the final goal is not reachable (states 5 and 7 are dummy states, as they only
redirect to states 1 and 2). The cardinality of the set MarkingsToTheGoal is 7, while the cardinality of the
set Markings(ReachabilityGraph) is 8 (important to note that even with eight states in the reachability
graph, IOPT-Tools can associate higher numbering to reachable states due to dummy states (enclosed
in squares), which represent pointers to reachable states). In this sense, the simple map of Figure 2 is
nonviable (lines 14-16 of Algorithm 1).</p>
    </sec>
    <sec id="sec-4">
      <title>6. Validation</title>
      <p>In this section, small examples of maps/graphs randomly generated by the application described before
are used to validate the correctness of the proposed approach, considering four typical situations:
• a viable map
• a viable map where some rooms are not reachable
• a nonviable map
• an inviable map</p>
      <p>
        For the four analyzed situations, a figure will be used to present the map randomly generated by the
application described before and the Petri net graph obtained using the IOPT-Tools framework, which
in turn benefits from the usage of the open-source graph visualization software Graphviz [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ].
      </p>
      <sec id="sec-4-1">
        <title>6.1. Viable map</title>
        <p>In this example, the map presented in Fig. 6(a) was generated containing 14 rooms and 3 keys, from
which the Petri net model of Fig. 6(b) was generated, leading to a reachability graph composed by 288
states.
(a) The map.</p>
        <p>(b) And associated Petri net.</p>
        <p>The query (Room13 = 1) received an answer identifying 9 states of the reachability graph where the
place Room13 is marked: states 71, 82, 91, 109, 332, 375, 525, 531, and 571. Note: as previously referred,
the numbering of the states in the reachability graph obtained from the IOPT-Tools accommodates the
numbering of the reachable states as well as the numbering of dummy states, which only point to actual
reachable states (that is the reason why, in this example, the reachability graph contains 288 reachable
states, and it is possible to find states with a number greater than that).</p>
        <p>From the 9 queries (), where  are the 9 states referred above, the answers
were 29, 58, 58, 116, 90, 180, 93, 186, 288, accordingly (for example, for the query (71), 29
reachable states were identified). From this it is possible to conclude that all 288 states of the reachability
graph have a path leading to (at least) one of the success states.</p>
        <p>Finally, from the state space generation report, it is possible to conclude that all rooms are reachable.</p>
        <p>So, the conclusion is that the map is viable.</p>
      </sec>
      <sec id="sec-4-2">
        <title>6.2. Viable map with rooms not reachable</title>
        <p>In this example, the map presented in Fig. 7(a) was generated containing 15 rooms and 2 keys, from
which the Petri net model of Fig. 7(b) was generated, leading to a reachability graph composed by 30
states.</p>
        <p>The query (14 = 1) received an answer identifying 4 states of the reachability graph where
the place Room14 is marked: states 21, 25, 46, and 47.</p>
        <p>From the queries, (21), (25), (46), and (47), the answers
identifying the number of states that can reach the referred state were 12, 13, 21, and 22, accordingly.
Considering the answers provided, it is possible to conclude that all 30 states of the reachability graph
have a path leading to (at least) one of the success states.</p>
        <p>Finally, from the state space generation report, it is possible to conclude that some rooms are not
reachable, namely Room2, Room6, and Room10 at the top of the figure. More specifically, to move from
Room0 to these rooms, possession of Key1 is needed, but Key1 is available at the bottom of the map
after moving to Room9, from where it is impossible to return.
(a) The map.</p>
        <p>(b) And associated Petri net.</p>
        <p>So, the conclusion is that the map is viable, but contains non reachable rooms. As an additional step
before providing the map for the game to proceed, it is recommended to prune the map from Room2,
Room6, and Room10.</p>
      </sec>
      <sec id="sec-4-3">
        <title>6.3. Nonviable map</title>
        <p>In this example, the map presented in Fig. 8(a) was generated containing 17 rooms and 2 keys, from
which the Petri net model of Fig. 8(b) was generated, leading to a reachability graph composed by 129
states.</p>
        <p>The query (Room16 = 1) received an answer identifying 3 states of the reachability graph where the
place Room16 is marked: states 131, 139, and 181.</p>
        <p>From the queries, (131), (139), and (181), the answers identifying the
number of states that can reach the referred state were 37, 74, and 120, respectively, from where it is
possible to conclude that only 120 states of the reachability graph have a path leading to one of the
success states.</p>
        <p>So, the conclusion is that the map is nonviable: if the player moves to Room15 on the top, they will
not be able to return as the transition between Room13 and Room15 is unidirectional.</p>
      </sec>
      <sec id="sec-4-4">
        <title>6.4. Inviable map</title>
        <p>In this example, the map presented in Fig. 9(a) was generated containing 21 rooms and 3 keys, from
which the Petri net model of Fig. 9(b) was generated leading to a reachability graph composed by 18
states.</p>
        <p>The query (Room20 = 1) received an answer confirming that Room20 is unreachable.
So, the conclusion is that the map is inviable.
(a) The map.</p>
        <p>(b) And associated Petri net.</p>
        <p>(b) And associated Petri net.</p>
        <p>From the state space generation report, it is also possible to conclude that some rooms are unreachable,
namely Room9, Room13, Room14, Room17, Room18, Room19, and Room20.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>7. Conclusions and future work</title>
      <p>The proposed approach proved to correctly identify the viability level of randomly generated
maps/graphs, which can be used as the base for roguelike games. Maps, where the final room cannot be
reached, are classified as inviable, while maps, where the reachability of the final room depends on the
movement options of the player along the game, are classified as nonviable. Viable games (those where
it is always possible to find a path leading to the final room) are successfully classified, and rooms that
cannot be visited are identified and can be removed from the map, saving resources when the execution
of the game is concerned.</p>
      <p>The proposed approach can be used to validate more sophisticated games, namely other types of
role-playing games (RPG), e.g., games with 2D or 3D grids, with any number of transitions per room, or
multi-player support. To support multi-player extensions, the Petri net class to be used must consider
distinguishable tokens, meaning an adequate class of high-level Petri nets needs to be selected.</p>
      <p>In future works, it is foreseen to set up a complete environment to generate fully playable roguelike
games, integrating the proposed approach to validate the viability of the randomly generated map
(where all the manual steps referred to in this paper will be integrated, allowing automatic execution of
the whole flow).</p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>This work was financed by Portuguese Agency FCT – Fundação para a Ciência e Tecnologia, in
the framework of project UIDB/00066/2020, and under the PhD scholarship with the reference
PRT/BD/154920/2022. The authors would like to thank Miguel Vitória for making available the
application that allowed the generation of the maps used to validate the presented work.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Daniel</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Nash</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Koenig</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          , &amp;
          <string-name>
            <surname>Felner</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          (
          <year>2010</year>
          ).
          <article-title>Theta*: Any-angle path planning on grids</article-title>
          .
          <source>Journal of Artificial Intelligence Research</source>
          ,
          <volume>39</volume>
          (January),
          <fpage>533</fpage>
          -
          <lpage>579</lpage>
          . https://doi.org/10.1613/jair.2994
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Dijkstra</surname>
            ,
            <given-names>E.W.</given-names>
          </string-name>
          (
          <year>1959</year>
          ).
          <article-title>A note on two problems in connexion with graphs</article-title>
          .
          <source>Numer. Math. 1</source>
          ,
          <fpage>269</fpage>
          -271 https://doi.org/10.1007/BF01386390.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Russell</surname>
            ,
            <given-names>S. J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Norvig</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Artificial Inteligence</surname>
            :
            <given-names>A Modern</given-names>
          </string-name>
          <string-name>
            <surname>Approach</surname>
          </string-name>
          .
          <source>Pearson Education, 3rd edition</source>
          ,
          <year>2003</year>
          . ISBN:
          <volume>9780136042594</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Hart</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Nilsson</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          &amp;
          <string-name>
            <surname>Raphael</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          <article-title>A Formal Basis for the Heuristic Determination of Minimum Cost Paths</article-title>
          .
          <source>IEEE Transactions On Systems Science And Cybernetics</source>
          .
          <volume>4</volume>
          ,
          <fpage>100</fpage>
          -
          <lpage>107</lpage>
          (
          <year>1968</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Alves</surname>
            ,
            <given-names>J. M. M.</given-names>
          </string-name>
          (
          <year>2017</year>
          ).
          <article-title>Path Planning and Collision Avoidance Algorithms for Small RPAS</article-title>
          , MSc Thesis; Instituto Superior Técnico, Portugal. https://fenix.tecnico.ulisboa.pt/downloadFile/ 1126518382183333/JulianaAlves_Thesis.pdf
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Reshamwala</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          (
          <year>2013</year>
          ).
          <article-title>Robot Path Planning using An Ant Colony Optimization Approach : A Survey</article-title>
          . pp.
          <fpage>65</fpage>
          -
          <lpage>71</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Khatib</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          (
          <year>1985</year>
          ).
          <article-title>Real-time obstacle avoidance for manipulators and mobile robots</article-title>
          .
          <source>Proceedings - IEEE International Conference on Robotics and Automation</source>
          ,
          <volume>500</volume>
          -
          <fpage>505</fpage>
          . https://doi.org/10.1109/ROBOT.
          <year>1985</year>
          .
          <volume>1087247</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Barreto</surname>
            ,
            <given-names>F. M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Julia</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          (
          <year>2021</year>
          ).
          <article-title>Formal Approach Based on Petri Nets for Modeling and Verification of Video Games</article-title>
          .
          <source>Computing and Informatics</source>
          vol.
          <volume>40</volume>
          ,
          <string-name>
            <surname>number</surname>
            <given-names>1</given-names>
          </string-name>
          , (
          <volume>216</volume>
          -248)
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Gomes</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ribeiro-Gomes</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          (
          <year>2023</year>
          ).
          <article-title>Analysing navigation paths in constrained graphs using Petri nets</article-title>
          , in: ISIE'
          <fpage>2023</fpage>
          - 32nd IEEE International Symposium on Industrial Electronics;
          <fpage>19</fpage>
          -
          <lpage>21</lpage>
          June 2023, Aalto University, Helsinki-Espoo,
          <source>Finland; DOI: 10.1109/ISIE51358</source>
          .
          <year>2023</year>
          .10228055
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Fan</surname>
            ,
            <given-names>X.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Li</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sisson</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          (
          <year>2018</year>
          ).
          <article-title>The Binary Space Partitioning-Tree Process</article-title>
          .
          <source>Proceedings of the Twenty-First International Conference on Artificial Intelligence and Statistics</source>
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Wolverson</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          (
          <year>2001</year>
          ).
          <article-title>Hands-on Rust - Efective Learning through 2D Game Development and Play</article-title>
          . ISBN:
          <volume>9781680508161</volume>
          . https://pragprog.com/
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Vitoria</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          (
          <year>2023</year>
          ).
          <article-title>Geração de Mapas para Jogos Tipo "Roguelike" e sua Validação Utilizando Redes de Petri</article-title>
          .
          <source>MSc Thesis</source>
          . NOVA University Lisbon, Portugal
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>J. P.</given-names>
            <surname>Barros</surname>
          </string-name>
          , L.
          <string-name>
            <surname>Gomes</surname>
          </string-name>
          (
          <year>2004</year>
          ).
          <article-title>Net Model Composition and Modification by Net Operations: a Pragmatic Approach</article-title>
          . INDIN'
          <fpage>2004</fpage>
          - 2nd IEEE International Conference on Industrial Informatics;
          <fpage>24</fpage>
          -
          <lpage>26</lpage>
          June 2004; Berlin, Germany. DOI:
          <volume>10</volume>
          .1109/INDIN.
          <year>2004</year>
          .1417350
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>Pereira</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Moutinho</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Costa</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Barros</surname>
            ,
            <given-names>J.P.</given-names>
          </string-name>
          <string-name>
            <surname>Campos-Rebelo</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gomes</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          (
          <year>2022</year>
          )
          <article-title>IOPT-Tools - From executable models to automatic code generation for embedded controllers development</article-title>
          .
          <source>PETRI NETS 2022 - 43rd International Conference on Application and Theory of Petri Nets and Concurrency; June 19 - 24</source>
          ,
          <year>2022</year>
          , Bergen, Norway; in L. Bernardinello and L.
          <string-name>
            <surname>Petrucci</surname>
          </string-name>
          (Eds.):
          <source>PETRI NETS</source>
          <year>2022</year>
          , LNCS 13288, pp.
          <fpage>127</fpage>
          -
          <lpage>138</lpage>
          ,
          <year>2022</year>
          . https://doi.org/10.1007/978-3-
          <fpage>031</fpage>
          -06653-
          <issue>5</issue>
          _
          <fpage>7</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>J.</given-names>
            <surname>Ellson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Gansner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Koutsofios</surname>
          </string-name>
          , S. North and
          <string-name>
            <given-names>G.</given-names>
            <surname>Woodhull</surname>
          </string-name>
          ,
          <article-title>"Graphviz - Open Source Graph Drawing Tools"</article-title>
          , in editors P. Mutzel,
          <string-name>
            <given-names>M.</given-names>
            <surname>Jünger</surname>
          </string-name>
          and
          <string-name>
            <given-names>S.</given-names>
            <surname>Leipert</surname>
          </string-name>
          ,
          <article-title>"</article-title>
          <source>Graph Drawing"</source>
          ,
          <year>2002</year>
          , Springer Berlin Heidelberg, pages
          <fpage>483</fpage>
          -
          <lpage>484</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>F.</given-names>
            <surname>Pereira</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Moutinho</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Gomes</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Ribeiro</surname>
          </string-name>
          , R. Campos-Rebelo,
          <article-title>“An IOPT-net State-Space Generator Tool”</article-title>
          ,
          <source>INDIN'2011 - 9th IEEE International Conference on Industrial Informatics, July 26-29</source>
          ,
          <year>2011</year>
          , Caparica, Lisbon, Portugal; pp.
          <fpage>383</fpage>
          -
          <lpage>389</lpage>
          ; ISBN 978-1-
          <fpage>4577</fpage>
          -0434-5; DOI 10.1109/INDIN.
          <year>2011</year>
          .6034907
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <given-names>F.</given-names>
            <surname>Pereira</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Moutinho</surname>
          </string-name>
          , L. Gomes, “
          <article-title>Model-checking Framework for Embedded Systems Controllers Development using IOPT Petri Nets”</article-title>
          , ISIE'
          <fpage>2012</fpage>
          - 2012 IEEE International Symposium on Industrial Electronics;
          <fpage>28</fpage>
          -
          <lpage>31</lpage>
          May
          <year>2012</year>
          , Hangzhou, China
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <given-names>L.</given-names>
            <surname>Gomes</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.-P.</given-names>
            <surname>Barros</surname>
          </string-name>
          ,
          <article-title>"Refining IOPT Petri Nets Class for Embedded System Controller Modeling"</article-title>
          ,
          <source>IECON 2018 - 44th Annual Conference of the IEEE Industrial Electronics Society</source>
          ,
          <year>2018</year>
          , doi=10.1109/IECON.
          <year>2018</year>
          .8592921
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>