ai part 1

47
INTRO TO INTELLIGENT AND AUTONOMOUS AGENTS Steering behaviors and pathfinding

Upload: spartasoft

Post on 31-Oct-2014

928 views

Category:

Education


3 download

DESCRIPTION

Steering behaviors and pathfinding, by Dan Sosnowski

TRANSCRIPT

Page 1: Ai part 1

INTRO TO INTELLIGENT AND AUTONOMOUS AGENTS

Steering behaviors and pathfinding

Page 2: Ai part 1

Game AI

What we’re covering today And what we’re not

How AI can improve your games Autonomous agents

Page 3: Ai part 1

Steering Behaviors

What they are When they’re used

Quite often http://www.youtube.com/watch?v=e2YYt

SJhmJg Movies

Let’s try some out!

Page 4: Ai part 1

Seek

Move entity from current position to target position as quickly as possible

Page 5: Ai part 1

Our entity is the triangle. How do we get to the target?

Page 6: Ai part 1

Desired velocity = target.position - myPosition

Page 7: Ai part 1

You can get a vector pointing from A to B by B - A

Page 8: Ai part 1
Page 9: Ai part 1
Page 10: Ai part 1

Don’t worry about overshooting, it’ll be corrected

Page 11: Ai part 1

Other steering behaviors

Arrive Obstacle Avoidance

Make sure we don’t have a force that’s too big!

Page 12: Ai part 1

Using SBs in your Entities ChasePlayer State

Obstacle avoidance, Pursue or Seek Idle State

Wander, maybe flocking?

Sheep Flocking, Wander, Obstacle Avoidance,

Evade

Page 13: Ai part 1

Steering behaviors ftw :?

Page 14: Ai part 1

Wouldn’t this be lovely? Well then, let’s find a path

Page 15: Ai part 1

A graph of points! (navigation graph)

Page 16: Ai part 1

Building a Nav Graph

Goal: A list of nodes and edges What is needed:

Start point, cast distance, interval (optional)Max number of nodes

Page 17: Ai part 1

GraphNode

Vector3 positionGraphEdge[4] edges

Data Structures

GraphEdge

GraphNode fromNodeGraphFrom toNode(Float weight)

Page 18: Ai part 1

List<GraphNodes> Nodes

For ( i = 1; i <= xCastDistance; ++i)For (j = 1; j <= zCastDistance; ++j){

cast a ray downward from above for each potential neighbor node(i.e. (curX + invertal, curZ), (curX, curZ + interval), etc.)if raycast hit the ground{ new GraphNode(GraphNode(Raycast hit point)) if we haven’t already found this node { Add new graph node to Nodes }

(calculate edge cost) new GraphEdge(current node, new graph node, cost)) Add new graph edge to the current node’s Edge list}

Page 19: Ai part 1

Start from initial position, start casting out!

Page 20: Ai part 1
Page 21: Ai part 1

What happens when node cast hits out of bounds?

Page 22: Ai part 1
Page 23: Ai part 1

New position

Page 24: Ai part 1

Nothing new, just adding another node/edge

Page 25: Ai part 1

:o A box!Hit an object not tagged ground, skip it, keep moving

Page 26: Ai part 1

:OOOOO But we already processed that node!Result depends on algorithm implementation. Easy route (the way the pseudo code was setup) is to have each node responsible for itself. So in our case add the edge and ignore the node.

Page 27: Ai part 1

Improvements Worth Mentioning

Reducing node density Indexing GraphNodes and

GraphEdges

Page 28: Ai part 1

GraphNode

int indexVector3 positionGraphEdge[4] mEdges

Data Structures for Indexing

GraphEdge

int fromNodeIndexint toNodeIndexfloat weight

Instead of storing the GraphNodes that a GraphEdge is connected to, westore the index of each GraphNode, so we’re not storing a GraphNode twice

Page 29: Ai part 1

Take a look at that graph

Page 30: Ai part 1

Search Algorithms

Depth-first search Breadth-first search Dijkstra’s algorithm A* (aka Dijkstra++)

^ yahtzee

Page 31: Ai part 1

Dijkstra’s Algorithm

Usable with weighted graphs. Graphs without weight can be processed by assuming edges of equal weight

Guaranteed to find shortest path, if it exists.

Implementation Examine nodes on our search frontier,

find the one with the smallest total weight, and add it to our path and keep going

Page 32: Ai part 1
Page 33: Ai part 1
Page 34: Ai part 1
Page 35: Ai part 1
Page 36: Ai part 1
Page 37: Ai part 1
Page 38: Ai part 1
Page 39: Ai part 1

Picture from “Programming Game AI by Example” by Mat Buckland

Page 40: Ai part 1

Picture from “Programming Game AI by Example” by Mat Buckland

Page 41: Ai part 1

A*

Dijkstra with an additional weight factor (heuristic) Heuristic: Making a decision based on some

knowledge

There’s something troublesome in the Dijsktra implementation that seems like it would be an easy fix

Page 42: Ai part 1

We know where our target is, so let’s approximate the cost from the nodes we are looking at to the target and factor that into what we choose

In this case, Euclidean distance

Page 43: Ai part 1

Manhattan Distance

Page 44: Ai part 1

ResultsPicture from “Programming Game AI by Example” by Mat Buckland

Page 45: Ai part 1

Picture from “Programming Game AI by Example” by Mat Buckland

Page 46: Ai part 1

Review

Steering behaviors Navigation graphs Search algorithms

So how do they work together? You have a point on the graph you want to

reach. You find a sequence of nodes to follow. Use steering behaviors to get from point to

point, and create interesting behavior on the way

Page 47: Ai part 1

Next time…

Organizing these lower level decisions into functional, autonomous agents (in a smart, extendable, debug-friendly way )

Questions?

(can someone let Jordan know he can wake up now? kthx)