AI in games Roger Crawfis/Eric Fosler-Lussier CSE 786 Game Design
AI vs. AI for games AI for games poses a number of unique design challenges AI for games poses a number of unique design challenges Traditional AI: Traditional AI: Made to handle unseen inputs, large state space Made to handle unseen inputs, large state space Too many options possible to compute an exact optimal solution Too many options possible to compute an exact optimal solution Engineering criteria: best possible performance Engineering criteria: best possible performance Game AI: Game AI: The game world is known, though it can still be large The game world is known, though it can still be large In a known world, optimal solutions can be precomputed In a known world, optimal solutions can be precomputed Entertainment criteria: smart enough to pose a challenge, but not smart enough to be undefeatible Entertainment criteria: smart enough to pose a challenge, but not smart enough to be undefeatible
Injecting AI into a Game Friend: Friend: autonomous, intelligent NPC helpmates autonomous, intelligent NPC helpmates Configurable (scripted) behaviors: different characters solve a problem in different ways Configurable (scripted) behaviors: different characters solve a problem in different ways Player may trade places with NPC: automation Player may trade places with NPC: automation Foe: Foe: Opponents get better with time Opponents get better with time Opponents are less predictable because the individuals’ behavior is not uniform Opponents are less predictable because the individuals’ behavior is not uniform Scene Clutter Scene Clutter Provides a richness to your environment. Provides a richness to your environment. Animals grazing, birds flying, people milling about, automobiles driving, etc. Animals grazing, birds flying, people milling about, automobiles driving, etc.
Goals for your games Prepare you for entertainment and ‘serious’ games Prepare you for entertainment and ‘serious’ games You must implement at least one of these features You must implement at least one of these features Improve over time Improve over time Goal-driven action decomposition Goal-driven action decomposition A* search A* search for path planning, with varying cost functions for different agents (different agents have different heuristics) for path planning, with varying cost functions for different agents (different agents have different heuristics) Game tree search Game tree search Emergent group behavior (flocking or formations) Emergent group behavior (flocking or formations) “Intelligent” interaction (e.g. speech/language) “Intelligent” interaction (e.g. speech/language) Your game AI must be data-driven, i.e. it must tune itself or otherwise interoperate with an arbitrary map/level loaded at runtime Your game AI must be data-driven, i.e. it must tune itself or otherwise interoperate with an arbitrary map/level loaded at runtime
Warning: AI is not an afterthought AI elements need to be designed in from the start AI elements need to be designed in from the start Configurable/scripted behavior Configurable/scripted behavior Data-driven map/level layouts Data-driven map/level layouts AI isn’t time-consuming to create, if coded from the start AI isn’t time-consuming to create, if coded from the start
Improving over time Agent behavior needs to be composed from small, modular, context-sensitive actions Agent behavior needs to be composed from small, modular, context-sensitive actions Evade-right if angle >90 and 90 and < 180 Reward good performance/punish bad Reward good performance/punish bad Each re-spawn can modify control strategy Each re-spawn can modify control strategy See good discussion in Buckland online book See good discussion in Buckland online book You can either perform training and freeze optimal play, or let the agent adapt to each user You can either perform training and freeze optimal play, or let the agent adapt to each user
Improving over time Example from Buckland (online) Ch 10: brainy aliens Example from Buckland (online) Ch 10: brainy aliens Map sensory input to behavior with a hidden layer Map sensory input to behavior with a hidden layer The time it stayed alive is fitness function The time it stayed alive is fitness function When alien dies, replace it with an evolved one When alien dies, replace it with an evolved one
Goal-driven behavior Multiple steps required to achieve a desired effect Multiple steps required to achieve a desired effect Useful in Useful in Action-adventure type games -puzzles to solve Action-adventure type games -puzzles to solve RPG - task underlings with a multi-step job RPG - task underlings with a multi-step job Good discussion in Buckland PGAIE ch. 9 Good discussion in Buckland PGAIE ch. 9 Each ‘goal’ is an instance of a composite class Each ‘goal’ is an instance of a composite class Many different goals can be created with minimal coding Many different goals can be created with minimal coding
Goal-driven agents Different classes of agents solve problem in different ways, based on their abilities Different classes of agents solve problem in different ways, based on their abilities “Block door”: “Block door”: Strong trolls move boulders in the way Strong trolls move boulders in the way Small hobbits shovel sand into the opening Small hobbits shovel sand into the opening Each agent’s response to the goal depends on his abilities, available tools, etc. Each agent’s response to the goal depends on his abilities, available tools, etc. Goal object contains alternative recipes Goal object contains alternative recipes One goal at a time is active for each agent One goal at a time is active for each agent In more complex games, might have goal queue In more complex games, might have goal queue
A* path planning Smart path planning/locomotion using waypoints/grabpoints built into the world Smart path planning/locomotion using waypoints/grabpoints built into the world Board/card games like chess/poker are impossible to completely search, heuristics are required and search cutoffs Board/card games like chess/poker are impossible to completely search, heuristics are required and search cutoffs
flocking/formation Agents have small goals to balance that result in emergent behavior Agents have small goals to balance that result in emergent behavior Flocking: stay close, navigate toward centroid of flock, avoid collision Flocking: stay close, navigate toward centroid of flock, avoid collision Results in a ‘crowd’ behavior look Results in a ‘crowd’ behavior look Formations: flanking/center/right wing, etc. Formations: flanking/center/right wing, etc. Individuals stay evenly spaced within their group Individuals stay evenly spaced within their group Each agent chooses a position within the formation Each agent chooses a position within the formation One agent or central planner selects formation One agent or central planner selects formation Results in a more disciplined/organized look (Orcs) Results in a more disciplined/organized look (Orcs) Depends on how organized you want the agents to appear Depends on how organized you want the agents to appear
Flocking demos See Craig Reynold’s Steering behaviors: See Craig Reynold’s Steering behaviors:
“Intelligent” interaction NPCs might communicate state via language NPCs might communicate state via language E.g. Wii Fit, “All your bases belong to us” E.g. Wii Fit, “All your bases belong to us” Complete job is WAAAAY too hard Complete job is WAAAAY too hard Input: probably beyond scope of project Input: probably beyond scope of project Output: May be able to do simple state-conditional things (mocking, encouragement) Output: May be able to do simple state-conditional things (mocking, encouragement) Scripting languages can be used for rapid deployment Scripting languages can be used for rapid deployment
Other AI principles: observability Don’t let the agents have perfect knowledge: they have to operate in the environment like the players do Don’t let the agents have perfect knowledge: they have to operate in the environment like the players do Sense and remember events in their sensory horizon, memories can have a TTL Sense and remember events in their sensory horizon, memories can have a TTL Perhaps in more advanced levels, they can communicate with each other about what they know Perhaps in more advanced levels, they can communicate with each other about what they know See article on “adding stupidity to AI” See article on “adding stupidity to AI”