EA C461 – Artificial Intelligence Adversarial Search S.P.Vimal http://discovery.bits-pilani.ac.in/~vimalsp/1910AI/ To discuss… • Game Playing • Optimal Decisions in Games – Minimax Algorithm – Multiplayer Games • Alpha-Beta Pruning Vimal EA C461- Artificial Intelligence Game playing • One of the very first tasks AI undertook • Chess, with average branching factor 35, with each player taking 50 steps, the number of nodes generated is 35100. • Make decisions, apparently no optimal choice • Inefficiencies penalized severely • "Unpredictable" opponent specifying a move for every possible opponent reply • Time limits unlikely to find goal, must approximate Vimal EA C461- Artificial Intelligence Problems • Two players – MAX, MIN • Components of the problem – Initial State – Successor function – Terminal Test • Test of states where the game ends – Utility function • +1, 0, -1 Vimal EA C461- Artificial Intelligence Game tree (2-player, deterministic, turns) Vimal EA C461- Artificial Intelligence Game strategy • An optimal strategy leads to an outcome which is at least as good as playing against an infallible opponent One move Vimal EA C461- Artificial Intelligence Minimax Value Minimax-Value (n) = Utility(n) , if n is a terminal node MaxsεSuccessors(n) Minimax-Value(s) , if n is a Max Node MinsεSuccessors(n) Minimax-Value(s) , if n is a Min Node Optimal play for MAX assumes, MIN also plays optimally. Vimal EA C461- Artificial Intelligence Minimax algorithm Vimal EA C461- Artificial Intelligence Properties of minimax • • • • Complete? Yes (if tree is finite) Optimal? Yes (against an optimal opponent) Time complexity? O(bm) Space complexity? O(bm) (depth-first exploration) • For chess, b ≈ 35, m ≈100 for "reasonable" games exact solution completely infeasible Vimal EA C461- Artificial Intelligence Vimal EA C461- Artificial Intelligence α-β Pruning • Prune away those nodes which cannot possibly influence the final outcome Vimal EA C461- Artificial Intelligence α-β pruning example Vimal EA C461- Artificial Intelligence α-β pruning example Vimal EA C461- Artificial Intelligence α-β pruning example Vimal EA C461- Artificial Intelligence α-β pruning example Vimal EA C461- Artificial Intelligence α-β pruning example What if successors are examined in a different order… Vimal EA C461- Artificial Intelligence α-β Pruning Minimax (root) = max( min(3,12,8), min(2,x,y), min(14,5,2) ) = max( 3, min(2,x,y), 2 ) = max( 3, z, 2 ) , z≤2 =3 Vimal EA C461- Artificial Intelligence Properties of α-β • Pruning does not affect final result • Good move ordering improves effectiveness of pruning • With "perfect ordering," time complexity = O(bm/2) doubles depth of search • A simple example of the value of reasoning about which computations are relevant (a form of metareasoning) Vimal EA C461- Artificial Intelligence Why is it called α-β? • α is the value of the best (i.e., highest-value) choice found so far at any choice point along the path for max • If v is worse than α, max will avoid it prune that branch • Define β similarly for min Vimal EA C461- Artificial Intelligence Implementation • The game tree is traversed in depth-first order. • Each non-leaf node will have a beta value and an alpha value stored. • For each max node, the minimum beta value for all its min node ancestors is stored as beta. • For each min node, the maximum alpha value for all its max node ancestors is stored as alpha. • Initially, the root node is assigned an alpha value of negative infinity and a beta value of infinity. Vimal EA C461- Artificial Intelligence Implementation • The variable children is used to represent all of the children of the current node • The following call means Vimal EA C461- Artificial Intelligence A better beta is already found… Vimal EA C461- Artificial Intelligence A better alpha is already found… Vimal EA C461- Artificial Intelligence Trace alpha-beta Vimal EA C461- Artificial Intelligence Resource limits • Replace utility function with heuristic function – Gives an estimate of utility • Replace terminal test by cur-off test Vimal EA C461- Artificial Intelligence Evaluation functions • Evaluation function should – Order the terminal state by it’s true utility – Not take long time – Correlate strongly with the actual chances of winning, for every non terminal states • Works by calculating features of the state – No of pawns possessed by each players, etc – Groups features to make classes/categories of the state. • Mostly evaluation function identifies the category in which the current state falls, and give an ordering of its successor with it’s expected utility. Vimal EA C461- Artificial Intelligence Evaluation functions • Categorizing may be difficult – Material value of each piece can be taken into account • • • • Pawn Knight/bishop Rook Queen 1 3 5 9 – Specific features like • Good pawn structure • King safty • For chess, typically linear weighted sum of features Eval(s) = w1 f1(s) + w2 f2(s) + … + wn fn(s) Vimal EA C461- Artificial Intelligence Evaluation functions • Weighted linear combination of features may be poor considering the fact – Bishops are more powerful in the endgame – Pair of bishops slightly more worthies than a single bishop – Importantly, the features are not the part of the rules of the game • They come out of experience • Experience suggests that, secured material advantage has more chance of winning, when all other things being equal… – A 3 point advantage near the end of the game is sufficient to ensure victory • Bishop is indeed worth 3 pawns Vimal EA C461- Artificial Intelligence Cutting off search • Replace terminal test with the cutoff function – If CUTOFF-TEST (state, depth) then return EVAL (state) • Apply evaluation functions only to quiescent positions, positions unlikely to exhibit a wild swing • Generate around million nodes/second in latest PC Vimal – Given 3 mins to make a move approximately 200 million nodes can be generated – With b=35, this implies 5 levels of look ahead (minimax) – With alpha-beta we get around 10 ply look EA C461- Artificial Intelligence ahead Cutting off search • Minimax MAX – Selects optimal move, given the leave evaluations are exactly correct. – Evaluations at leave are mostly estimations MIN 100 99 MAX • Evaluation functions can be probability distribution over a set of possible values Vimal 99 1000 1000 1000 EA C461- Artificial Intelligence 100 101 102 100 Chess in Gaming Literature • 1957 – Herbert Simon – 10 years computer will beat human world champion • 1997 – Deep Blue – defeated – Gary Kasparov – Six-Game Exhibition Match • Deep Blue – Running as parallel computer, 30 IBM RS/6000 running software search, 480 custom VLSI chess processors generates moves and orders them – Hardware search for last few levels of the tree … – 126 million nodes/second average with the peak speed of 300 million nodes/sec Vimal EA C461- Artificial Intelligence Chess in Gaming Literature – Used standard iterative deepening alpha-beta search with transposition tables – Max depth approx 40 plies – Evaluation function with 8000 features – About 4000 opening positions, consensus recommendations from the database of 700,000 grandmaster games – Large solved end game database (all positions with 5 pieces, as many as 6 pieces) • 2002 – FRITZ (on ordinary PC) – Vladimir Kramnik – drawn Vimal EA C461- Artificial Intelligence Summary • • • • Vimal Games are fun to work on! They illustrate several important points about AI perfection is unattainable must approximate good idea to think about what to think about EA C461- Artificial Intelligence
© Copyright 2026 Paperzz