Thesis: Video Game Pathfinding and Improvements to Discrete Search on Grid-Based Maps
Total Page:16
File Type:pdf, Size:1020Kb
Video Game Pathfinding and Improvements to Discrete Search on Grid-based Maps by Bobby Anguelov Submitted in partial fulfillment of the requirements for the degree Master of Science in the Faculty of Engineering, Built Environment and Information Technology University of Pretoria Pretoria JUNE 2011 Publication Data: Bobby Anguelov. Video Game Pathfinding and Improvements to Discrete Search on Grid-based Maps. Master‘s dissertation, University of Pretoria, Department of Computer Science, Pretoria, South Africa, June 2011. Electronic, hyperlinked PDF versions of this dissertation are available online at: http://cirg.cs.up.ac.za/ http://upetd.up.ac.za/UPeTD.htm Video Game Pathfinding and Improvements to Discrete Search on Grid-based Maps by Bobby Anguelov Email: [email protected] Abstract The most basic requirement for any computer controlled game agent in a video game is to be able to successfully navigate the game environment. Pathfinding is an essential component of any agent navigation system. Pathfinding is, at the simplest level, a search technique for finding a route between two points in an environment. The real-time multi-agent nature of video games places extremely tight constraints on the pathfinding problem. This study aims to provide the first complete review of the current state of video game pathfinding both in regards to the graph search algorithms employed as well as the implications of pathfinding within dynamic game environments. Furthermore this thesis presents novel work in the form of a domain specific search algorithm for use on grid-based game maps: the spatial grid A* algorithm which is shown to offer significant improvements over A* within the intended domain. Keywords: Games, Video Games, Artificial Intelligence, Pathfinding, Navigation, Graph Search, Hierarchical Search Algorithms, Hierarchical Pathfinding, A*. Supervisor: Prof. Andries P. Engelbrecht Department: Department of Computer Science Degree: Master of Science ―In theory, theory and practice are the same. In practice, they are not.‖ - Albert Einstein Acknowledgements This work would not have been completed without the following people: My supervisor, Prof. Andries Engelbrecht, for his crucial academic and financial support. My dad, Prof. Roumen Anguelov, who first introduced me to the wonderful world of computers and who has always been there to support me and motivate me through thick and thin. Alex Champandard for letting me bounce ideas off of him. These ideas would eventually become the SGA* algorithm. Neil Kirby, Tom Buscaglia and the IGDA Foundation for awarding me the 2011 ―Eric Dybsand Memorial Scholarship for AI development‖. Dave Mark for taking me under his wing at the 2011 Game Developers Conference and introducing me to a whole bunch of game AI VIPs. Jack Bogdan, Gordon Bellamy and Sheri Rubin for all their amazing work on the IGDA Scholarships. This thesis would not have been completed as quickly without the IGDA scholarship. Chris Jurney, for taking the time to discuss my thesis topic all those years ago. His work on the pathfinding for ―Company of Heroes‖ is the inspiration behind this thesis. My friends and colleagues, for their support over the last few years and for putting up with all my anxiety and neuroses. This work has been partly supported by bursaries from: The National Research Foundation (http://www.nrf.ac.za) through the Computational Intelligence Research Group (http://cirg.cs.up.ac.za). The University of Pretoria. i ii Contents Acknowledgements ............................................................................................................................................. i Contents ............................................................................................................................................................. iii List of Figures ................................................................................................................................................... vii List of Pseudocode Algorithms ....................................................................................................................... x Chapter 1 Introduction ............................................................................................................................... 1 1.1 Problem Statement and Overview .................................................................................................. 1 1.2 Thesis Objectives .............................................................................................................................. 2 1.3 Thesis Contributions......................................................................................................................... 2 1.4 Thesis Outline .................................................................................................................................... 3 Chapter 2 Video Games and Artificial Intelligence ................................................................................ 5 2.1 Introduction to Video Games ......................................................................................................... 5 2.2 Video Game Artificial Intelligence ................................................................................................. 8 2.2.1 Human Level AI ..................................................................................................................... 10 2.2.2 Comparison to Academic and Industrial AI ....................................................................... 11 2.3 Game Engine Architecture ............................................................................................................ 13 2.3.1 The Game Engine ................................................................................................................... 13 2.3.2 Basic Engine Architecture and Components ...................................................................... 15 2.3.3 Game Engine Operation and the Game Loop ................................................................... 16 2.3.4 Performance Constraints ....................................................................................................... 18 2.3.5 Memory Constraints ............................................................................................................... 20 2.3.6 The Need for Concurrency ................................................................................................... 21 2.4 The Video Game Artificial Intelligence System.......................................................................... 21 2.4.1 Game Agent Architecture ...................................................................................................... 22 iii 2.4.2 The Game Agent Update....................................................................................................... 24 2.4.3 The AI System Architecture and Multi-Frame Distribution ............................................ 26 2.4.4 The Role of Pathfinding in a Game AI System .................................................................. 27 2.5 Summary ........................................................................................................................................... 29 Chapter 3 Graph Representations of Video Game Environments ................................................... 31 3.1 The Navigational Graph Abstraction ........................................................................................... 31 3.2 Waypoint Based Navigation Graphs ............................................................................................ 33 3.3 Mesh Based Navigational Graphs ................................................................................................. 34 3.4 Grid Based Navigational Graphs .................................................................................................. 37 3.5 Summary ........................................................................................................................................... 39 Chapter 4 The Requirements and Constraints of Video Game Pathfinding .................................... 41 4.1 The Pathfinding Search Problem .................................................................................................. 41 4.2 Pathfinding Search Problem Requirements................................................................................. 43 4.2.1 Path Optimality ....................................................................................................................... 43 4.2.2 Path Smoothing ....................................................................................................................... 44 4.3 Pathfinding Search Problem Constraints ..................................................................................... 45 4.3.1 Performance Constraints ....................................................................................................... 46 4.3.2 Memory Constraints ............................................................................................................... 48 4.4 Pathfinding in Dynamic Environments ....................................................................................... 49 4.5 Selecting a Suitable Search Algorithm .......................................................................................... 52 4.6 Summary ..........................................................................................................................................