540 likes | 553 Views
This article explores the use of Artificial Intelligence (AI) algorithms in game development to control non-player characters (NPCs) and simulate intelligent behavior. It covers various AI algorithms such as LOS, Graph Theory and Routing, FSM, Genetic Algorithms, Decision Trees, Fuzzy Logic, and Cellular Automata. Examples of games that utilize AI for NPC behavior are discussed, including Halo, Sims, TechnoSphere, and Black & White. The article also introduces the concept of flocking behavior and its implementation using the Flocking Algorithm developed by Craig Reynolds.
E N D
Yingcai Xiao • Yingcai Xiao Artificial Intelligence in Game Development
Non-player character (NPC) / non-person character / non-playable character: any game character that is not controlled by a player.AI in games controls NPCs to simulate intelligence behavior. Artificial Intelligence in Game Development
First AI games created in 1951.NIM and CheckerPac-Man (1980) added personalities to enemies. https://www.youtube.com/watch?v=x4tqMv0CvTQGarry Kasparov defeated by IBM's Deep Blue computer in 1997https://www.youtube.com/watch?v=_Y9hriLylIo Examples
InteractionInteraction with Natural LanguageJeopardyhttps://www.youtube.com/watch?v=WFR3lOm_xhEAPIhttp://www.ibm.com/smarterplanet/us/en/ibmwatson/?lnk=buwaCloudhttp://www.ibm.com/smarterplanet/us/en/ibmwatson/watson-cloud.html IBM Watson
Examples • Halo: Intelligent aliens will retreat after their leader killed. (Jobs) • Sims: smart objects that can go hungry, bored, tired, ... • TechnoSphere: an online digital environment where users from around the globe could create creatures and release them into. • Black & White: belief-desire-intention, god overseeing little people.
AI Algorithms • LOS (line of sight): avoid of being shot. • Graph Theory and Routing: maze games. • BF/DF Searching Algorithms: board games. • FSM (Finite State Machine): state of mined games.
AI Algorithms • Genetic Algorithms: evolutionary computing based on adaptation and survival. • http://www.biomanbio.com/GamesandLabs/Genegames/genetics.html • http://www.biomanbio.com/GamesandLabs/Cellgames/sCellExplorerAnimalCell.html • (Arrow keys to move, “s” to shoot an object for explanation.)
AI Algorithms • Decision Trees: hierarchical graph to make decisions based on conditions. • Fuzzy Logic: make decisions based on vague information.
John von Neumann (The Martians) Computer Architecture https://en.wikipedia.org/wiki/Von_Neumann_architecture Game Theory https://en.wikipedia.org/wiki/Von_Neumann_architecture
AI Algorithms • Cellular Automata: a grid of cells with each cell value being updated constantly by its neighbor’s values. • Game of Life • Stephen Wolfram • Wolfram Alpha
AlphaGo • AlphaGo: a game engine that plays the Go game. • Go: aChinese board game of strategies. 19x19, 361!, 10761 (total number of fundamental particles in the observable universe:1085). • The first computer program to beat a professional Go player (4:1, March 8-15, 2016).
AlphaGo Zero • AlphaGo: learns from past human games. • AlphaGo Zero: learns by itself. • AlphaGo Zero won AlphaGo 100:0
Flocking • Flocking: crowd behaviors. • Starling murmuration: https://www.youtube.com/watch?v=eakKfY5aHmY • Reynolds, Craig W. (1987). "Flocks, herds and schools: A distributed behavioral model.". ACM SIGGRAPH Computer Graphics 21 (4). pp. 25–34. • Batman Returns (1992): flocking bats and The Lion King (1994): wildebeest stampede.
Flocking • Craig Reynolds: http://www.red3d.com/cwr/ • Reynolds, Craig W. (1987). "Flocks, herds and schools: A distributed behavioral model.". ACM SIGGRAPH Computer Graphics 21 (4). pp. 25–34. • Authored the Open Steer library • Won 1998 Academy Scientific and Technical Award for pioneering contributions to 3D computer animation for movies. • Uses procedural models to simulate complex natural phenomenon.
The Flocking Algorithm • The algorithm • Implementation in Unity3D • Building a Unity package for reuse • Building a flocking library in a game engine
The Flocking Algorithm • Craig Reynolds’ Boids: • artificial objects follow natural flocking behavior • Unity Implementation: • http://black-square.github.io/BirdFlock/ • JavaScript implementation: http://gpolo.github.io/birdflocking/ • OpenGL implementation: http://www.navgen.com/3d_boids/
The Flocking Algorithm • Tutorial: • http://www.vergenet.net/~conrad/boids/pseudocode.html • Unity Code Explanation: • http://wiki.unity3d.com/index.php?title=Flocking
The Flocking Algorithm • Craig Reynolds’ Boids: artificial objects flow natural flocking behavior. • 3 Basic Rules: • cohesion - to move toward the center of the mass of the flockmates • separation - to avoid flockmates • alignment – to steer towards the flock direction
The Flocking Algorithm • Craig Reynolds’ Boids: artificial objects flow natural flocking behavior. • 3 Basic Rules: • cohesion - to move toward the center of the mass of the flockmates • separation - to avoid flockmates • alignment – to steer towards the flock direction • http://www.vergenet.net/~conrad/boids/pseudocode.html
init_game(); while(!done) { e = get_event() switch(e) { case “p”: change_game_parameters( ); break; … default: display_game_objects(); compute_next_frame(); } } Event Loop Event Event Mapping & Event Dispatching EDP Game Development Event Handler
init_game(); while(!done) { e = get_event() switch(e) { case “p”: change_game_parameters( ); break; … default: compute_next_frame(); display_game_objects(); } } Event Loop Event Event Mapping & Event Dispatching EDP Game Development Event Handler
init_game(); create_boids(); while(!done) { e = get_event() switch(e) { case “p”: change_game_parameters( ); break; … default: compute_CoM_AV(); compute_boid_velocity(); display_boids(); } } Event Loop Event Event Mapping & Event Dispatching EDP Game Development Event Handler
Flocking Code • C# code at http://wiki.unity3d.com/index.php?title=Flocking • Create the flock at the BiodController::Start() • //all boids • Update animation parameters in BiodController::Update () //all boids • Control the animation in BoidFlocking::BoidSteering () //each boid
Flocking Code • Create the flock at the Start() • Flock Size • Boids Array • Position • Direction
Flocking Code • Create the flock at the Start() • Bounding box • Global and local transformation • The Controller
Flocking Code • (2) Update animation parameters in Update () • Center of Mass • Average Direction • The Controller
Flocking Code • (3) Control the animation in BoidFlocking::BoidSteering () • This is the script for each boid. • Separation is taking care of by rigidbody. • Cohesion is to follow the CoM. • Alignment is to follow the Average Direction
PA3 Coding / Flocking http://www.cs.uakron.edu/~xiao/game/igd3.htm The Theory / Rules: cohesion - to move toward the center of the mass of the flockmates separation - to avoid flockmates alignment – to steer towards the flock direction
PA3 Coding / Flocking The Example: Holistic Game Development with UnityBy: Penny de Byl http://proquest.safaribooksonline.com/book/programming/game-programming/9780240819334 Section 5.6: a flock of seagulls flying against wind in small groups. http://proquest.safaribooksonline.com/book/programming/game-programming/9780240819334/chapter-5-character-mechanics/ch5_6_006_9780240819341_web_ch05_html
Yingcai Xiao Sorting and Searching in Game Development
Sorting & Searching • S&S needed to develop AI games to find optimal strategies, paths, in the game logic. • The main challenge is the huge size of the search tree. The number of branches in the search tree of a 19x19 Go board game is larger than the number of atoms in the known universe. • The key of success is to reduce the search space but not the optimal solutions.
Sorting • Sorting the search space can make searches faster. • Sorting can be used to prioritize the search space. • Weights can be added to reflect heuristic information.
Basic Sorting Algorithms • Sorting Algorithm Animations • http://www.sorting-algorithms.com/ • https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html • https://www.youtube.com/watch?v=aXXWXz5rF64 • Wiki listing • https://en.wikipedia.org/wiki/Sorting_algorithm • eights can be added to reflect heuristic information.
Searching • Basic searching • Statistical searching • Searching for globally optimal solutions
Basic Searching Algorithms Code Listing https://users.dcc.uchile.cl/~rbaeza/handbook/search_a.html Comparisons http://bigocheatsheet.com/ http://research.cs.queensu.ca/home/cisc121/2006s/webnotes/search.html Example: How many steps are needed to find the one over-weighted golf ball among the eight of them using just a scale.
Statistical Searching Algorithms https://en.wikipedia.org/wiki/Monte_Carlo_tree_search “The focus of Monte Carlo tree search (MCTS) is on the analysis of the most promising moves, expanding the search tree based on random sampling of the search space. The application of Monte Carlo tree search in games is based on many playouts. In each playout, the game is played-out to the very end by selecting moves at random. The final game result of each playout is then used to weight the nodes in the game tree so that better nodes are more likely to be chosen in future playouts” https://en.wikipedia.org/wiki/Search_tree https://en.wikipedia.org/wiki/Monte_Carlo_method https://en.wikipedia.org/wiki/Monte_Carlo_method#History https://en.wikipedia.org/wiki/Monte_Carlo_Casino
MCTS • Four Steps: • Selection • Expansion • Simulation • Backpropagation
MCTS • Selection • Start from root R and select successive child nodes down to a leaf node L. The section below says more about a way of choosing child nodes that lets the game tree expand towards most promising moves, which is the essence of Monte Carlo tree search.
MCTS https://commons.wikimedia.org/wiki/File:MCTS_(English).svg#/media/File:MCTS_(English).svg
MCTS Expansion Unless L ends the game with a win/loss for either player, either create one or more child nodes or choose from them node C.
MCTS https://commons.wikimedia.org/wiki/File:MCTS_(English).svg#/media/File:MCTS_(English).svg
MCTS Simulation Play a random playout from node C.
MCTS https://commons.wikimedia.org/wiki/File:MCTS_(English).svg#/media/File:MCTS_(English).svg
MCTS Backpropagation Use the result of the playout to update information in the nodes on the path from C to R.”
MCTS https://commons.wikimedia.org/wiki/File:MCTS_(English).svg#/media/File:MCTS_(English).svg
AlphaGo Algorithms • Based on tree searches and neural networks that can learn. • Policy Network: only consider a few promising positions (limit the breadth of the search tree.) • Value Network: only consider a few steps deep (limit the depth of the search tree).
Globally Optimal Solutions “Simulated annealing (SA) is a probabilistic technique for approximating the global optimum of a given function. ” “Specifically, it is a metaheuristic to approximate global optimization in a large search space” “for problems where finding the precise global optimum is less important than finding an acceptable local optimum in a fixed amount of time, simulated annealing may be preferable to alternatives such as brute-force search or gradient descent.” https://en.wikipedia.org/wiki/Simulated_annealing