# artificial intelligence

Post on 30-Dec-2015

23 views

Embed Size (px)

DESCRIPTION

Artificial Intelligence. Games 2: Alpha Beta. Ian Gent ipg@cs.st-and.ac.uk. Artificial Intelligence. Alpha Beta Search. Part I :The idea of Alpha Beta Search Part II: The details of Alpha Beta Search Part III: Results of using Alpha Beta. Reminder. - PowerPoint PPT PresentationTRANSCRIPT

Artificial IntelligenceIan Gentipg@cs.st-and.ac.uk

Games 2: Alpha Beta

Artificial IntelligencePart I :The idea of Alpha Beta SearchPart II: The details of Alpha Beta SearchPart III: Results of using Alpha Beta

Alpha Beta Search

ReminderWe consider 2 player perfect information gamesTwo players, Min and MxLeaf nodes given definite scorebacking up by MiniMax defines score for all nodesUsually cant search whole treeUse static evaluation function insteadMiniMax hopelessly inefficient

Whats wrong with MiniMaxMinimax is horrendously inefficientIf we go to depth d, branching rate b,we must explore bd nodesbut many nodes are wastedWe needlessly calculate the exact score at every nodebut at many nodes we dont need to know exact scoree.g. outlined nodes are irrelevant

The SolutionStart propagating costs as soon as leaf nodes are generatedDont explore nodes which cannot affect the choice of moveI.e. dont explore those that we can prove are no better than the best found so farThis is the idea behind alpha-beta search

Alpha-Beta searchAlpha-Beta = Uses same insight as branch and boundWhen we cannot do better than the best so farwe can cut off search in this part of the treeMore complicated because of opposite score functionsTo implement this we will manipulate alpha and beta values, and store them on internal nodes in the search tree

Alpha and Beta valuesAt a Mx node we will store an alpha valuethe alpha value is lower bound on the exact minimax scorethe true value might be if we know Min can choose moves with score < then Min will never choose to let Max go to a node where the score will be or moreAt a Min node, value is similar but oppositeAlpha-Beta search uses these values to cut search

Alpha Beta in ActionWhy can we cut off search?Beta = 1 < alpha = 2 where the alpha value is at an ancestor nodeAt the ancestor node, Max had a choice to get a score of at least 2 (maybe more)Max is not going to move right to let Min guarantee a score of 1 (maybe less)

Alpha and Beta valuesMx node has valuethe alpha value is lower bound on the exact minimax scorewith best play M x can guarantee scoring at least Min node has valuethe beta value is upper bound on the exact minimax scorewith best play Min can guarantee scoring no more than At Max node, if an ancestor Min node has < Mins best play must never let Max move to this nodetherefore this node is irrelevantif = , Min can do as well without letting Max get hereso again we need not continue

Alpha-Beta Pruning RuleTwo key points:alpha values can never decreasebeta values can never increaseSearch can be discontinued at a node if:It is a Max node and the alpha value is the beta of any Min ancestorthis is beta cutoffOr it is a Min node and the beta value is the alpha of any Max ancestorthis is alpha cutoff

Calculating Alpha-Beta valuesAlpha-Beta calculations are similar to Minimaxbut the pruning rule cuts down searchUse concept of final backed up value of nodethis might be the minimax value or it might be an approximation where search cut offless than the true minimax value at a Max nodemore than the true minimax value at a Min nodein either case, we dont need to know the true value

Final backed up valueLike MiniMaxAt a Max node:the final backed up value is equal to the:largest final backed up value of its successorsthis can be all successors (if no beta cutoff)or all successors used until beta cutoff occursAt a Min nodethe smallest final backed up value is equal to the smallest final backed up value of its successorsmin of all successors until alpha cutoff occurs

Calculating alpha valuesAt a Mx nodeafter we obtain the final backed up value of the first childwe can set of the node to this valuewhen we get the final backed up value of the second childwe can increase if the new value is larger when we have the final child, or if beta cutoff occursthe stored becomes the final backed up valueonly then can we set the of the parent Min nodeonly then can we guarantee that will not increaseNote the differencesetting alpha value of current node as we go alongvs. propagating value up only when it is finalised

Calculating beta valuesAt a Min nodeafter we obtain the final backed up value of the first childwe can set of the node to this valuewhen we get the final backed up value of the second childwe can decrease if the new value is smaller when we have the final child, or if alpha cutoff occursthe stored becomes the final backed up valueonly then can we set the of the parent Max nodeonly then can we guarantee that will not decreaseNote the differencesetting beta value of current node as we go alongvs. propagating value up only when it is finalised

Move ordering HeuristicsVariable ordering heuristics irrelevantvalue ordering heuristics = move ordering heuristicThe optimal move ordering heuristic for alpha-beta .. is to consider the best move firstI.e. test the move which will turn out to have best final backed up valueof course this is impossible in practiceThe pessimal move ordering heuristic is to consider the worst move firstI.e. test move which will have worst final backed up value

Move ordering HeuristicsIn practice we need quick and dirty heuristicswill neither be optimal nor pessimalE.g. order moves by static evaluation functionif its reasonable, most promising likely to give good scoreshould be nearer optimal than randomIf static evaluation function is expensiveneed even quicker heuristicsIn practice move ordering heuristics vital

Theoretical ResultsWith pessimal move ordering,alpha beta makes no reduction in search costWith optimal move orderingalpha beta cuts the amount of search to the square rootI.e. From bd to bd = bd/2Equivalently, we can search to twice the depth at the same costWith heuristics, performance is in betweenalpha beta search vital to successful computer play in 2 player perfect information games

Summary and Next LectureGame trees are similar to search trees but have opposing playersMinimax characterises the value of nodes in the treebut is horribly inefficientUse static evaluation when tree too bigAlpha-beta can cut off nodes that need not be searchedcan allow search up to twice as deep as minimaxNext Time: Chinook, world champion Checkers player

Recommended