CS 380: ARTIFICIAL INTELLIGENCE

GAME AI

Santiago Ontañón [email protected] Artificial Intelligence

We propose that a 2 month, 10 man study of artificial intelligence be carried out during the summer of 1956 at Dartmouth College in Hanover, New Hampshire.

The study is to proceed on the basis of the conjecture that every aspect of learning or any other feature of intelligence can in principle be so precisely described that a machine can be made to simulate it. An attempt will be made to find how to make machines use language, form abstractions and concepts, solve kinds of problems now reserved for humans, and improve themselves.

- Dartmouth AI Project Proposal; J. McCarthy et al.; Aug. 31, 1955. Artificial Intelligence

We propose that a 2 month, 10 man study of artificial intelligence be carried out during the summer of 1956 at Dartmouth College in Hanover, New Hampshire.

The study is to proceed on the basis of the conjecture that every aspect of learning or any other feature of intelligence can in principle be so precisely described that a machine can be made to simulate it. An attempt will be made to find how to make machines use language, form abstractions and concepts, solve kinds of problems now reserved for humans, and improve themselves.

- Dartmouth AI Project Proposal; J. McCarthy et al.; Aug. 31, 1955. Artificial Intelligence What is Game AI?

• Artificial Intelligence for Computer Games • Different from traditional AI

Traditional AI: Optimality, efficiency Game AI: Fun, artificial “stupidity” What is Game AI?

• Intersection of games and AI:

Games AI

• Two (three) main communities working on it: • Academics: • Artificial Intelligence community: how can games help us have better AI (AI centric) • Computer Game scholars: how can AI help us have better/more interesting/new forms of games? (Games centric) • Game industry: • Their goal is to make games that sell more units (games centric) Outline

• Structure of the course • Intro to Game AI • Examples of Game AI • Course Scope • Projects Examples of Game AI

“Pac-Man” (1980) First ever to feature AI AI: finite state machine Examples of Game AI

“Pac-Man” (1980) First ever video game to feature AI AI: finite state machine First Ever Game to Feature AI? First Ever Game to Feature AI?

• Dr. NIM from the 1960s? https://www.youtube.com/watch?v=9KABcmczPdg First Ever Game to Feature AI?

• Dr. NIM from the 1960s? https://www.youtube.com/watch?v=9KABcmczPdg • “El Ajedrecista”, 1921 (Leonardo Torres y Quevedo) Examples of Game AI

Board Games

AI needs to provide a collection of difficulty levels.

Only the hardest mode falls into the realm of traditional AI. Examples of Game AI

“Left 4 Dead 2”

AI Director adjusts game pace to ensure desired dramatic effects Examples of Game AI

“Black & White”

Uses machine learning to simulate a learning creature Examples of Game AI

“Starcraft II”

Strategy, planning, path- finding, economics, etc. Types of Game AI

• Inside the game: • Character control • Director (drama management)

• During game development: • Help in behavior/content design

• After game deployment: • Analysis of game data First-Person Shooters

• We all know what a FPS is. But do you know which one was the first?

• http://www.youtube.com/watch?v=7chDIySXK2Q (1979) • http://www.youtube.com/watch?v=PoEpgfTtUYg (1984) • http://www.youtube.com/watch?v=C00n4rDUMNo (1992) • http://www.youtube.com/watch?v=yr-lQZzevwA (1993) • http://www.youtube.com/watch?v=d_kfZSsArCM (2004) • https://www.youtube.com/watch?v=SCenq-HHDMc (2016) AI Requirements in FPS

• The two basic needs in all FPS are: • Movement • Firing

• With those two you can already have a basic FPS running like: • 3D (for which you most likely only need movement, since there are no projectiles, and thus firing is just line-of-sight testing) •

• But you need way more than that for a modern FPS!

Character AI Game Rendering State

World Interface Collision Physics (perception)

Movement Firing Input User Game Engine

Character AI Game Rendering State

World Interface Collision Physics (perception)

At this point we Movement Firing already have the AI for “Wolfenstein 3D” Input User

(It had no pathfinding) AI Requirements in FPS

• In Modern FPS you don’t expect: • Enemies to get stuck behind a wall (enemies in old games like Wolfenstein do) • To stand still while you kill their comrades (they do in Wolfenstein and Doom!) • To be trapped just because you closed a door! • To move independently of each other • etc. Path-finding

• Not all enemies are given path-finding capabilities: • Path-finding makes characters look smart, the ones that should not look smart should not have path-finding

• Representation of the navigation graph: • Navigation meshes is the most popular

• Embedded navigation: • Annotate links in the navigation graph with the action required to traverse it (walk, crawl, climb, open door, etc.) • Characters look smart knowing they have to perform those actions, but it’s all hand annotated or precomputed Game Engine

Character AI Game Rendering State

World Interface Collision Physics (perception) Path-finding

Movement Firing Input User Game Engine

Character AI Game Rendering State

World Interface Collision Physics (perception) Path-finding

Movement Firing At this point we Input User already have the AI for “Doom”! Decision Making

• Decision Making in FPS controls what characters do at a high : do they attack? Do they retreat? Do they execute other actions?

• Classic games: Finite-state machines • Modern games: Behavior Trees

• Some exceptions: • F.E.A.R.: Goal-oriented behavior • Characters have a set of goals, and each goal associated with an FSM, the most relevant goal takes control and its FSM is executed. Game Engine

Character AI Game Rendering State

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing Input User Group Control

• Coupled with better decision-making, this is the largest difference between classic and modern FPS AI.

• In old games (Doom, etc.) enemies always rush!

• Modern games use group tactics: • Simplest is “kung-fu style” (one enemy at a time) • Complex attack tactics where some characters attack, while others cover Group Control

• Can be defined also using behavior trees

• Most common approach: • Each tactic defines a set of “roles” • A role is filled by one character • Each tactic has a behavior tree that executes it

• For example: • A “flank” tactic can have 3 roles for “left attack”, “front attack”, and “right attack” • Only 3 enemies will execute it at once (if there are more, they will wait, kung-fu style) • Enemies look smart, but do not crazily over-power the player Game Engine

Character AI Game Rendering State Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing Input User Game Engine

Character AI Game Rendering State Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing At this point we already have the AI Input User for “Half-”! Game Engine

Character AI Game Rendering State Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing At this point we already have the AI Input User for “Half-Life”!

But there is more… Drama Management / Directing

• Premise: • Different players have different preferences • Each player enjoys a different subset of the elements of a game

• Problem: • How can a game automatically adapt to match the current player? • Maintain the dramatic arc expected by the game designer • Prevent the players from dealing with parts of the game not appealing to them • Adjust difficulty level, etc.

• Solution: • Drama Management / Experience Management / AI Director Drama Management

Game Evaluation Adaptation Function

Drama Manager

Player

Game Engine Drama Management Examples

• Façade: • http://www.youtube.com/watch?v=GmuLV9eMTkg

• Left 4 Dead: • http://www.youtube.com/watch?v=VVIdHPG0wYI • AI Director controls: spawning enemies and items, music, map (can block or open paths) • Not random spawns: AI Director has a set of predefined patterns with parameter ranges, and selects the appropriate pattern with the appropriate parameters. Game Engine

Character AI Game Rendering State Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing Input User

Drama Management Game Engine

Character AI Game Rendering State Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding At this point, we have the AI of “Left 4 Dead 2”

Movement Firing Input User

Drama Management Intelligent Camera Control

• Recent games have an emphasis on story telling

• Camera control is an essential component in story telling, since it provides focus

• A lot of recent work on automatic camera control: • Example: http://www.youtube.com/watch?v=8G0xfyDGLsk&feature=related NPCs and Camera Control

• What if you put a lot of work in NPC AI, but player never “looks” to NPCs? NPCs and Camera Control

• What if you put a lot of work in NPC AI, but player never “looks” to NPCs? • Example: Elizabeth in Bioshock Infinite NPCs and Camera Control

• The Game predicts the path • What if you put a lot of work in NPC AI,the but player player needs never to take to “looks” to NPCs? get to the next “goal”. • Then, makes Elizabeth be in • Example: Elizabeth in Bioshock Infinitethat path in order to make sure she is on the camera. • Otherwise, if she was just following, she would always be behind, and the player would need to “turn around” to see the NPC. Game Engine

Rendering

Character AI Game State Camera Control Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing Input User

Drama Management This is a complete state Game Engine of the art AI architecture for a modern FPS (or RPG) game Rendering

Character AI Game State Camera Control Tactics (Group Behavior)

Decision Making World Interface Collision Physics (perception) Path-finding

Movement Firing Input User

Drama Management Game Engine

Rendering

Character AI Game State Camera Control Tactics (Group Behavior)

Some specific platforms Decision Making World (e.g. Wii, Kinect) have Interface specificCollision AI needs,Physics like (perception) gesture recognition. Path-finding

Movement Firing Input User

Drama Management