Pick a direction that lands in a cell minimizing the distance to goal
Can get stuck in local minima or maxima
Solution?
Track candidate path choices and explore until acceptable solution found
Graphs
A graph is formed by
Nodes (N) connected by
Edges (E)
cost of traversing the path related to the length or difficulty
Types of graphs
DAG
directed cyclic graphs
Risk
Game dependency tree
Graph from uniform structure (Grid)
Early games built from tiles
can think of each grid as a node and the adjacency to other traversable cells as edges
Other game types with unique geometry?
Connecting rooms
Planning
Manipulate current state of the world to reach a goal
Operaters- movements taken to change state
grid movement- NSWE
NavMesh- represent navigable areas with convex polygons connected to each other
Path planning
States
Discretized space- want just the right detail in a discretized representation
Tile-based: tiles are inhernetly discrete
Can have different waypoints
Voxels- cubelike- 3D grid representation
Operators
Basic strategy for path planning in games
Create a data structure (graph) that facilities path planning
Quantize-
path creation with search algorithm
localize the path back to the game world
initiate agent movement and continue until goal reached
Path planning algorithms
Must search the state space to move agent to goal state
Computational isues
Completeness- will the algorithm find an answer if one exists
Time complexity
space complexity - How much memory required- performing calculations or caching data
Optimiality- will it find the best solution
Search strategies
Blind search- Only consider nodes and edges/weights
Heuristic search- domain knowledge can drive heuristic rules
Depth first search
Whichever node you consider first, you expand upon that further and further until you run out of choices, then work your way back and consider other possiblities
Can easily keep track of where you are based on nature of tree structure, don’t need to worry about getting caught in loops, can leverage recursion
DFS in path planning
Breadth-First Search
Consider all the children of the starting point before move to next level, which would be like the grandchildren from the starting point
Can work well for returning a result, because never return a path longer than the shortest chain
Pathfinding
Sample games where path planning fails
discretized space not complete or
physical capabilities of the agent doesn’t align with the discretized space
Pathfinding in Sim City
Sims not considering travel time on shorter dirt road
Issues
Failures when graph rep or intended path not coordinated with the AI agent and simulated space (environment)
Tile-based games
Inherent graph structure can be leveraged for path planning
AI exist in discrete locations
Easy to keep track of where you can and cannot go
Grid navigation
2D tile representation
squares- 4 or 8 way
Hexagonal board- 6-way
Discretization of continuous space
Generation
Boundaries and terrain type regions
Gradients may depend on perspective
e.g. can go downhill but not uphill
Discretized space- grid lattice
Instead of tiles, might have geometry of arbitrary shape or structure relative to grid lattice cells
Size our grid lattice relative to the world boundaries
world perimeter- largest grid we can fit in the game world
Grids cells with intersection with obstacles are marked as untraversable with blue x’s
Use integer representation to avoid floating point issues
Generation
Confirm that world boundaries don’t go through grid lines
Verify no obstacle point within a grid cell, or vice versa
Quit as soon as intersection found
Tests for points before more expensive tests like edge intersections
Grid cells point containment
Could treat grid cells as polygons
Assuming axis-aligned dimensions of the grid, can just perform range checks for x and y
Problematic edge cases
Issues with geometry perfectly algined with grid cells
Proper line intersection- 2 lines not parallel that intersect somewhere other than an endpoint
Problematic case
If a polygon was same size as grid cell, might fail to mark as untraversable
Fix: shrink by 1 unit, now the point test against the polygon would reveal all 4 vertices inside the grid cell
Validity
May wish to id individual edges
Validity: Agent can safely navigate from one node to the next adjacent node