A Faster Alternative to Traditional A* Search: Dynamically Weighted BDBOP
Total Page:16
File Type:pdf, Size:1020Kb
Int'l Conf. Artificial Intelligence | ICAI'16 | 3 A Faster Alternative to Traditional A* Search: Dynamically Weighted BDBOP John P. Baggs, Matthew Renner and Eman El-Sheikh Department of Computer Science, University of West Florida, Pensacola, FL, USA A path-finding algorithm requires the following: a start Abstract – Video games are becoming more computationally point, an end point, and a representation of the environment complex. This requires video game designers to carefully in which the search is to take place. Today, the two main allocate resources in order to achieve desired performance. methods environments are represented in video games are This paper describes the development of a new alternative to with square grids and navigation meshes. Square grids take a traditional A* that decreases the time to find a path in three- specific section of space in the environment and map the dimensional environments. We developed a system using Unity space to a matrix location. The matrix has to be large enough 5.1 that allowed us to run multiple search algorithms on to contain the number of squares needed to represent the different environments. These tests allowed us to find the environment. Navigation meshes were developed in the 1980s strengths and weaknesses of the variations of traditional A*. for robotic path-finding and most games after the 2000s have After analyzing these strengths, we defined a new alternative adopted these navigation meshes. In [3], a navigation mesh is algorithm named Dynamically Weighted BDBOP that defined as “…a set of convex polygons that describe the performed faster than A* search in our experiments. Using walkable surface of a 3-dimensional environment”. this search, video game developers can focus the limited resources on more complex tasks. There are several efficiency related issues with square grid environments. The smaller the squares in the grid, the more detailed the description of the environment becomes. Keywords: A*, Navigation Mesh, Path-finding, Dynamically However, at the same time, the number of squares increases Weighted BDBOP, Video Games the search space for the path-finding algorithm. As the search space increases, the time complexity increases. Another issue 1 Introduction with square grids is that the squares are laid on top of non- movable or static obstacles. Because the obstacles are Path-finding algorithms are used in many Computer Science represented in the grid, collision detection is required during application areas, including robotics and video games. One of path-finding. Navigation meshes directly address these two the most popular path-finding algorithms used is the A* challenges. A navigation mesh represents the environment search. A* is an improvement on Dijkstra’s shortest path with polygons that are completely free of obstacles. This algorithm. The improvement significantly cuts down the condition, and the condition that all polygons are convex, number of nodes that need to be visited during the search. A removes the need for collision detection anywhere inside a decrease in the number of nodes correlates directly with a polygon [4]. There is no restriction on the size that a polygon decrease in the space and time complexities of the search. can be as long as the rules of being convex and obstacle free A*’s improvement upon Dijkstra’s algorithm comes from the are maintained. A navigation mesh search space consists of use of a heuristic method to reduce the search space [1]. significantly fewer nodes than the square grid search space for the same environment. For these reasons, our research Today, video games require an enormous amount of focuses on developing and implementing a navigation mesh computational resources. A majority of these resources are for experimentation with path-finding algorithms. dedicated to graphics rendering and calculations in the physics engine [2]. Given these limited resources, all This paper summarizes two main contributions: computational components of video games must be optimized 1. Results and conclusions from an experiment comparing for speed and memory management. Path-finding, a different path-finding algorithms on a set of three- component of non-player character (NPC) intelligence, is a dimensional environments developed using Unity 5.1. We computationally intensive task; therefore it is essential to implemented A* and popular variations of A*. These variants improve the path-finding computational efficiency. Because include Bi-Directional A*, Fringe search, optimized versions of it’s search speed, A* is one of the most widely used path- of traditional A*, Beam search, Dynamically Weighted A*, finding algorithms in the video game industry. This research and Bi-Directional A*. During the experiment, each search addresses improving the efficiency of path-finding was run on each environment 1000 times, collecting data for a algorithms. comparison of each search algorithm’s performance on a given environment. ISBN: 1-60132-438-3, CSREA Press © 4 Int'l Conf. Artificial Intelligence | ICAI'16 | 2. A proposal for a new variant on A*. The proposed than A*. Our results using an implementation of Fringe algorithm outperforms A* in both time and space complexity. search differ from this and are discussed in the Results The new algorithm sacrifices A*’s guaranteed optimal section. solution in order to attain these performance gains. The solutions found by the new algorithm were optimal in some A valuable resource during our research into different path- cases, but not all. Later in the paper we argue that the finding algorithms was a blog written by Amit Patel [7]. Patel differences between solutions found by our algorithm and the describes multiple variations on the A* search in his blog. We optimal solution are not concerns to a video game developer. implemented several search algorithms based on these brief descriptions, including Dynamically Weighted A*, Beam 2 Related Work Search and Bi-Directional A*. The concise and clear descriptions of the algorithms made the implementations Common practice in the video game industry for representing relatively straightforward. 3 dimensional environments, up until the early 2000s, was to use waypoints. Waypoints are a set of manually generated points in the environment that form a path that the agent can 3 Algorithm Design walk upon. The time it takes for developers to manually place Dynamically Weighted Bi-Directional Beam OPtimized these waypoints is not feasible for larger maps. Another (BDBOP) search is a variation on A* that we created which drawback is that waypoints do a poor job of representing the uses features of Dynamically Weighted, Bi-Directional, Beam environment because they only represent single points and the and Optimized A* searches. During our research into line connecting those points. The restrictive nature of variations and methods of optimizing A* we noticed that Waypointer led to the use of the more flexible navigation there are different benefits gained from using each algorithm. meshes and square grids for representing environments. Xiao After narrowing down our focus to algorithms that Qui discusses the limitation of square grids representing specialized in reducing the number of nodes visited in the environments [1]. search we formulated our algorithm design. Additionally, we optimized these searches with respect to the speed at which Square grids often require a large number of cells to they navigate their data structures, strictly in terms of their adequately describe an environment. A well designed Big O complexities. Dynamically Weighted BDBOP visits far navigation mesh that is used to describe the same less nodes than traditional A*. This allows Dynamically environment as a square grid will result in far fewer total Weighted BDBOP to outperform A* even without the nodes needed than the square grid will. One reason for this is efficiency optimizations to the data structures. that the nodes in a square grid cover the entire environment including the non-walkable areas, while a navigation mesh The defining characteristic of Bi-Directional search is that it represents the walkable areas in the environment. Another conducts two A* searches in parallel or two A* searches in reason for this is that the way a navigation mesh is designed alternating successions. One search starts from the start node is to create convex polygons as nodes that represent as much and searches for the goal node, while the opposite search of the environment as they can in a given space and that do begins at the goal node and searches for the start node. The not include static obstacles. This allows the navigation mesh search is complete when the frontiers of the searches meet or to use fewer nodes than a square grid to represent the same one of the two searches finds their destination node. Bi- environment, effectively reducing the search space for a path- Directional search visited fewer nodes when used to navigate finding algorithm, which serves to reduce the search time for our environments than A* did. the algorithm to find a path. The next search we evaluated was Dynamically Weighted Various path-finding algorithms can be used across both A*. Dynamically Weighted A* places a high priority on square grids and navigation meshes to find a valid path getting the search moving quickly in the general direction of between two points. Fringe search is one such algorithm the the goal in the beginning and then as the search gets closer to use of which on square grids was researched in an attempt to the goal precision becomes more important. This was determine if it could outperform A*. The Fringe search accomplished by adding a weight to the heuristic. The weight algorithm is a take on Iterative Deepening A* (IDA*) which decreases as the search gets closer to the goal. This results in uses recursive depth-first search of the environment until fewer nodes visited than traditional A* but does not guarantee either the goal is found or a node that exceeds the threshold is an optimal path.