International Journal of Computer Games Technology

Volume 2018, Article ID 5184605, 19 pages

https://doi.org/10.1155/2018/5184605

## xTrek: An Influence-Aware Technique for Dijkstra’s and A Pathfinders

Instituto de Telecomunicações and Universidade da Beira Interior, Covilhã, Portugal

Correspondence should be addressed to Abel J. P. Gomes; tp.ibu.id@semoga

Received 22 October 2017; Revised 23 January 2018; Accepted 7 February 2018; Published 12 April 2018

Academic Editor: Hock S. Seah

Copyright © 2018 Gonçalo P. Amador and Abel J. P. Gomes. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

#### Abstract

We propose a new pathfinding technique called xTrek that combines conventional pathfinding and influence fields; that is, we are introducing a new* influence-sensitive pathfinder* or* influence-aware pathfinder*. The leading idea of influence-aware pathfinding is to avoid unwanted regions and/or converge to desired regions of the search space during the path search. As shown throughout the paper, this region avoidance/convergence is more striking using our technique than in other field-aware pathfinders as, for example, risk-adverse pathfinders and constraint-aware navigation pathfinders. Furthermore, our technique constrains the search space even more than such state-of-the-art influence-aware pathfinders, aiming to reduce the memory space consumption, to speed up pathfinding computations, and at the same time to have better control on the paths to be discovered.

#### 1. Introduction

Artificial intelligence (AI) has many definitions, but Poole et al. [1] describe it as “the study and design of intelligent agents.” An intelligent agent (e.g., NPC, shorthand of on-player character) is an autonomous entity that analyzes the surrounding environment, from where it avoids eventual obstacles, makes decisions, and acts accordingly to achieve its goal or objective [2]. Influence fields, also known as force fields in robotics, are often seen as an obstacle avoidance technique by associating repulsive fields to obstacles. However, influence fields may also work as a trail-orienteering technique by assigning attractive fields to landmarks leading to the desired destination. By combining such repulsive and attractive influence fields, an NPC can follow a collision-free path from a point to another on the game map.

Usually, an NPC is programmed in a loose way to ensure a player has a chance to win a game. NPCs are not intelligent agents in literal terms, but they behave in a seamlessly plausible intelligent manner, particularly when they are chasing a player in the game world. For this plausible intelligent behavior, much contributes motion planning algorithms for NPCs and agents [3]. In games, motion planning is known as pathfinding and has to do with the motion of a given NPC from one place to another in the game world.

##### 1.1. Pathfinders

Before proceeding any further, let us show that pathfinding algorithms are used in many areas other than video games [4, 5], namely, communication network routing [6, 7], robotics path planning [8, 9], and global positioning system navigation systems [10], just to mention a few.

Pathfinding operates over a search graph that describes the path network of the game world. The idea is to find a path (if it exists) between two given locations (two graph nodes), preferably with the lowest cost; in other words, the pathfinder should be complete and optimal. Dijkstra’s and [11, 12] pathfinders are two examples of complete pathfinders, but only the first is optimal; is optimal if the heuristic is appropriate, that is, if the heuristic function cost estimate is always lower than or equal to the real cost from either node to the goal of the search. Dijkstra’s is a particular pathfinder with the heuristic taking on the value 0.

In games, it suffices to use complete pathfinders [13]. Finding the shortest path is not a strict requirement in games, just because such will turn into an advantage for NPCs over the player. That is, it is harder, not to say impossible, for a player to beat an NPC that acts optimally. Therefore, it is acceptable to propose pathfinding algorithms that sacrifice optimality for performance, as it is the case of the influence-aware Dijkstra’s and pathfinders introduced in this paper. These influence-aware pathfinders have the advantage of consuming less memory space, of being faster than their counterparts without influence, and additionally of being context-aware; that is, they avoid unwanted regions and go through preferable regions.

##### 1.2. Influence Fields

In addition to spatial reasoning-based strategy [14–20], influence fields (also known as* influence maps*) have been also used as an obstacle avoidance technique in motion planning. For example, Ms. PacMan game [21, 22] uses influence fields generated by repulsors and attractors. Repulsors (e.g., ghosts and inedible objects) exert a negative influence, while attractors exert a positive influence (e.g., food, health, or point-scoring objects). That is, repulsors are divergence locations, whereas attractors are convergence locations, regardless of whether they are moving in the game or not. Another example is for activity-centric crowd authoring [23], where influences were used to simulate crowd movement; that is, avatars avoid others yet they converge to areas of interest (e.g., a mall restaurant area).

However, and unlike pathfinders,* influence fields* were not thought of to find a path between two locations, but at most to induce a steering motion on game entities that move around the environment, yet avoiding obstacles. Recall that an influence field is defined as a function that ascribes a single value (e.g., weight or cost) to each point in game space and time, that is, a concept known in mathematics as a scalar field [24]. It happens that like any other function, an influence field may possess one or more local extrema (i.e., minima and maxima). These local extrema constitute the principal problem of influence fields, because any object moving in the scene may be attracted to and trapped at an extremum. Consequently, influence fields do not ensure that the goal position is reached if one finds a local extremum in the meanwhile.

It is worth noting that a few path planners based on* potential fields* have been also proposed in the literature [25–27]. A potential field is also a scalar field, but usually, one takes advantage of a vector field (e.g., the gradient field) associated with it. For example, the path planner introduced by Dapper et al. [26] uses the gradient descent to find routes from any point of the game map to a goal position. The resulting routes are not only smooth but also free of local minima. This path planner was inspired by BVP-based motion planners used in robotics [28], where BVP is the shorthand of boundary value problems. It is not a pathfinder because it uses a motion equation rather than a cost function. However, and similar to grid-based pathfinders, it requires the decomposition of the game map into a grid of square cells. Then, cells spanning obstacles are set to the potential value 1 (repulsors) to avoid collisions, while cells containing target or goal locations for NPCs are set to 0 (attractors). In this BVP framework, each NPC has a local map with a single attractor located at target location so that whenever the NPC moves around in the environment, its map requires an update to its position and velocity. However, solving the BVP-based motion equation for a given NPC requires the interpolation of the potential values on the grid between obstacle locations and the target location of such NPC [26].

##### 1.3. Related Influence-Aware Pathfinders

At our best knowledge, there are five works incorporating awareness of the avatar’s surroundings into pathfinding, yet they differ in their purposes. The first is due to Laue and Röfer [29], who used a vector field for navigation of agents in a virtual world. This vector field-based navigation algorithm only takes advantage of a pathfinder when the agent gets trapped at a local extremum. That is, the pathfinder is only used near a local extremum when there is a need to escape from it.

The second work attempts to integrate pathfinders and influence maps and is due to Paanakker [30]. This work modified the cost functions of Dijkstra’s and pathfinders to include influence values tied to repulsors and attractors, yet such values are constant within the area of influence of each repulsor/attractor, that is, −1 for attractors and +1 for repulsors. This technique is known as risk-adverse pathfinding (RAP), so it uses repulsors as risk-adverse entities. It is a repulsor-oriented technique so that a path goes away from repulsors. However, the moving agent often ignores the presence of attractors, walking straight ahead through their influence areas. Furthermore, the behavior of the agent depends on the game map and tuning parameters; that is, the human-like movement behavior that gets out from repulsors and approaches attractors rarely happens and is not automated.

The third work is by Adaixo et al. [31], which replaces such constant influence values by decreasing values obtained from a Gaussian kernel function, but this has not improved the straight moving behavior of agents though attractors (neither repulsors) in a noticeable manner. This problem comes out because there is no guarantee that the cost function value of the next node to be evaluated is less than the cost function value of the current node. In contrast, our field-sensitive pathfinders guarantee that their cost functions monotonically decrease from the start node to the goal node.

The fourth work is due to Sturtevant [32] and incorporates avoidable agents (i.e., agents to avoid) in the process of pathfinding. More specifically, one uses the circular AoI of each agent to be avoided, as well as the distance and the line of sight to it, in the reformulation of the cost-so-far function. Therefore, the AoI plays the role of a repulsor somehow. The idea is to pass by each avoidable agent (e.g., an enemy player) without being seen. However, this technique does not use any concept similar to attractors.

Finally, Kapadia et al. [23, 33, 34] developed influence-aware pathfinders called constraint-aware navigation (CAN) pathfinders. These pathfinders consider both attractors and repulsors, which they called constraints. However, seemingly this technique is not sensitive (or is slightly sensitive at most) to repulsors.

Summing up, among these five techniques, only two integrate influence with pathfinders, namely, risk-adverse pathfinders (RAP) [30] and constraint-aware navigation (CAN) [23, 33, 34]. However, only the CAN technique is automated; that is, it does not need any manual tuning of parameters. However, CAN only accounts for attractors and repulsors in the proximity of the path found by the traditional and Dijkstra’s pathfinders; that is, the convergence to attractors and divergence from repulsors only occurs if the path found by CAN gets close to the corresponding path by and Dijkstra’s pathfinders without constraints. In contrast, the xTrek technique—with “” standing for either “Dijkstra” or “”—finds a path that goes toward attractors and deviates from repulsors. Besides, the placement of attractors and repulsors is also automated and builds upon on the minimum spanning tree of the graph of passable nodes of the game map. In a way, our technique mimics both obstacle avoidance and trail orienteering, whose control points are here repulsors and attractors, respectively.

##### 1.4. Organization of the Paper

The remainder of this paper is organized as follows. Section 2 details the mathematical theory of fields and shows how it can be applied in pathfinding. Section 3 details our influence-aware Dijkstra’s and pathfinders, named DjTrek (or DjT) and Trek (T), including their cost functions that combine the traditional cost functions with influence functions. Section 4 presents the experimental results obtained from a battery of tests performed for 20 game maps taken from the HOG2 map repository (http://movingai.com/benchmarks/). Section 5 further discusses the applicability of our influence-aware technique in solving the problems of path adaptivity and smoothness. Finally, Section 6 draws relevant conclusions and points out new directions for future work.

#### 2. Theory of Fields for Games

As explained further ahead, we use attractors and repulsors to guide the agent (avatar) on its way to the goal, avoiding obstacles at the same time. An attractor is a local minimum of a scalar field, while a repulsor is a local maximum of a scalar field. In mathematics, a* scalar field* ties a scalar value to every point in space (e.g., 3D Euclidean space or ). Recall that a scalar field is known as* influence field* or* influence map* in games. Even considering that the game world is bounded in size, the number of points of is uncountable, so we need to discretize into a finite number of cubes so that we then calculate the value of the scalar field at each corner of every single cube. For the sake of convenience, we consider that represents the terrain of the game world; that is, it is tiled into squares, not into cubes.

A scalar field in is generated by a real bivariate function ; that is, is defined at every single point of . We use a Gaussian function to model the scalar field generated by each repulsor , which is given by where stands for the amplitude of the Gaussian, is the distance of an arbitrary point to the location of the repulsor , and is the decay factor of the Gaussian with the distance in relation to the location of the repulsor . More specifically, we have where denotes the standard deviation. Figure 1 shows us the effect of the decay on the influence area of a repulsor, so that the bigger the decay, the lesser the influence area of a repulsor. Note that each function represents the decaying behavior of the scalar field of the repulsor with the distance. That is, the repulsor is stronger at its location than at any other point in the game world.