19.01.2015 Views

pdf(for print) - Computer Graphics Laboratory

pdf(for print) - Computer Graphics Laboratory

pdf(for print) - Computer Graphics Laboratory

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Minimax (5/6)<br />

• Some issues<br />

• Draw<br />

• Estimated value e(n)<br />

• e(n) ) = 1 : the node is a win <strong>for</strong> maximizer<br />

• e(n) ) = -11 : the node is a win <strong>for</strong> minimizer<br />

• e(n) ) = 0 : that is a draw<br />

• e(n) ) = -11 ~ 1 : the others<br />

• When to decide stop the tree expanding further <br />

Minimax (6/6)<br />

• The algorithm (final)<br />

1. Set L = { n }, the unexpanded nodes in the tree<br />

2. Let x be the 1st node on L. . If x = n and there is a value assigned to<br />

it, return this value.<br />

3. If x has been assigned a value v x , let p be the parent of x and v p<br />

the value currently assigned to p. . If p is a minimizing node, set v p<br />

= min(v p , v x ). If p is a maximizing node, set v p = max(v p , v x ).<br />

Remove x from L and return to step 2.<br />

4. If x has not been assigned a value and either x is a terminal node<br />

or we have decided not to expand the tree further, compute its<br />

value using the evaluation function. Leave x on L and return to<br />

step 2.<br />

5. Otherwise, set v x to be –∞ if x is a maximizing node and + ∞ if x is<br />

a minimizing node. Add the children of x to the front of L and<br />

return to step 2.<br />

19<br />

20<br />

Introduction to Path Finding<br />

• A common situation of game AI<br />

• Path planning<br />

• From start position to the goal<br />

• Most popular technique<br />

• A* (A Star)<br />

• 1968<br />

• A search algorithm<br />

• Favorite teaching example : 15-pizzule<br />

• Algorithm that searches in a state space <strong>for</strong> the least costly path<br />

from start state to a goal state by examining the neighboring<br />

states<br />

A* Algorithm (1/4)<br />

The A* Algorithm<br />

Open : priorityqueue of searchnode<br />

Closed : list of searchnode<br />

AStarSearch( location StartLoc, location GoalLoc, agenttype Agent) {<br />

clear Open & Closed<br />

// initialize a start node<br />

StartNode.Loc = StartLoc;<br />

StartNode.CostFromStart = 0;<br />

StartNode.CostToGoal = PathCostEstimate(StartLoc, GoalLoc, Agent);<br />

StartNode.TotalCost = StartNode.CostToGoal ;<br />

StartNode.Parent = NULL;<br />

push StartNode on Open;<br />

// process the list until success or failure<br />

while Open is not empty {<br />

pop Node from Open // node has the lowest TotalCost<br />

21<br />

22<br />

A* Algorithm (2/4)<br />

// if at a goal, we’re done<br />

if (Node is a goal node) {<br />

construct a path backward from Node to StartLoc<br />

return SUCCESS;<br />

}<br />

else {<br />

<strong>for</strong> each successor NewNode of Node {<br />

NewCost = Node.CostFromStart + TraverseCost(Node, NewNode, Agent);<br />

// ignore this node if exists and no improvement<br />

if (NewNode is in Open or Closed) and<br />

(NewNode.CostFromStart

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!