Artificial Intelligence for Games Uninformed search Patrick Olivier
Simple problem solving agent
Roadmap of Romania…
Example: Romanian holiday On holiday in Romania (currently in Arad) Flight leaves tomorrow from Bucharest Formulate goal: –be in Bucharest Formulate problem: –states: various cities –actions: drive between cities Find solution: –sequence of cities, e.g., Arad, Sibiu, Fagaras…
Example: 8 puzzle states? –locations of tiles actions? –move blank left, right, up, down goal test? –goal state (given) path cost? –1 per move
Example: robot assembly states? –joint angles + parts actions? –joint motions goal test? –complete assembly path cost? –time to execute
Example: NPC path planning states? –discretised world actions? –character motions goal test? –destination reached path cost? –cumulative motion cost
Tree search algorithms simulated (offline) exploration of state space generating successors of already-explored states
Tree search: implementation
Search strategies strategy defined by order of node expansion strategies evaluated according to: –completeness: always find a solution if one exists? –time complexity: number of nodes generated –space complexity: maximum nodes in memory –optimality: always finds a least-cost solution? time & space complexity measured in terms of: –b: maximum branching factor of the search tree –d: depth of the least-cost solution –m: maximum depth of the state space (may be ∞)
Uninformed search strategies only use information in the problem definition (uninformed): –breadth-first search –uniform-cost search –depth-first search –depth-limited search –iterative deepening search improve using informed search (next week)
Breadth-first search Expand shallowest unexpanded node Implementation: fringe is a FIFO queue –add newly expanded nodes to back of queue –expand nodes at the front of the queue
Old queue:[ ] New queue:[A]
Old queue:[A] New queue:[B C]
Old queue:[B C] New queue:[C D E]
Old queue:[C D E] New queue:[D E F G]
Properties of breadth-first search Complete? –Yes (if b is finite) Time: –b+b 2 +b 3 +… +b d + (b d+1 -b) = O(b d+1 ) Space: –O(b d+1 ) …keeps every node in memory Optimal? –If the cost is the same per step Space is the problem (more than time)
Depth-first search Expand deepest unexpanded node Implementation: fringe is a LIFO queue –add newly expanded nodes to front of queue –expand node at the front of queue
Old queue:[ ] New queue:[A]
Old queue:[A] New queue:[B C]
Old queue:[B C] New queue:[D E C]
Old queue:[D E C] New queue:[H I E C]
Old queue:[H I E C] New queue:[I E C]
Old queue:[I E C] New queue:[E C]
Old queue:[E C] New queue:[J K C]
Old queue:[J K C] New queue:[K C]
Old queue:[K C] New queue:[C]
Properties of depth-first search Complete? –No – fails in infinite-depth spaces (or with loops) –modify to avoid repeated states along path –complete in finite spaces Time: –O(b m ): bad if m much larger than d of shallowest goal –if solutions are dense, much faster than breadth-first Space: –O(bm), i.e. linear space Optimal? –No