1 00:00:04,940 --> 00:00:09,550 Now while, bounded minimax helps avoid some wasted work, we can do even better. 2 00:00:10,810 --> 00:00:12,160 Consider the game tree shown here. 3 00:00:13,280 --> 00:00:16,670 In this case, unlike the earlier examples, there are 4 00:00:16,670 --> 00:00:19,524 many terminal nodes that are neither zero or 100. 5 00:00:20,790 --> 00:00:22,940 Determining the maximum score for the top node of this tree a 6 00:00:22,940 --> 00:00:27,460 minimax player, even a bounded minimax player wouldn't examine the entire tree. 7 00:00:29,250 --> 00:00:30,040 However not all of this 8 00:00:30,040 --> 00:00:31,710 work is necessary. 9 00:00:31,710 --> 00:00:35,900 So as an example, consider the fourth terminal node on the lower-left. 10 00:00:35,900 --> 00:00:39,410 Even before that node is examined the player knows that his opponent can keep it 11 00:00:39,410 --> 00:00:45,380 to at most 10 points. And on that branch, based on the third 12 00:00:45,380 --> 00:00:51,900 node, it, all, and it already has a move of it's own that gets it 11 points. 13 00:00:53,970 --> 00:00:56,810 Sporing the fourth node can only decrease the mid nodes score. 14 00:00:56,810 --> 00:00:58,300 And, the player's not going to choose it 15 00:00:58,300 --> 00:01:00,800 anyway since it can get 11 points somewhere else. 16 00:01:00,800 --> 00:01:03,400 So there's not point in examining it. 17 00:01:03,400 --> 00:01:06,440 In this case, the saving is only one node. 18 00:01:06,440 --> 00:01:08,170 But in other cases it can allow a player to 19 00:01:08,170 --> 00:01:10,160 prune whole subtrees, as we'll see in just a bit. 20 00:01:12,578 --> 00:01:15,580 Alpha-Beta Search is a variation of Bounded Minimax that eliminate such 21 00:01:15,580 --> 00:01:19,400 wasted work, by computing balance dynamically 22 00:01:19,400 --> 00:01:21,169 and passing them along as parameters. 23 00:01:22,360 --> 00:01:25,940 One bound called Alpha is the best score the players seen thus far. 24 00:01:27,030 --> 00:01:29,720 Another bound called Beta is the worst score the player has seen. 25 00:01:29,720 --> 00:01:32,950 In examining new nodes, Alpha-Beta Search, uses these 26 00:01:32,950 --> 00:01:35,230 bounds to decide whether to look at further nodes. 27 00:01:36,610 --> 00:01:37,710 So partial resulted in 28 00:01:37,710 --> 00:01:39,780 min node, is less than alpha, then 29 00:01:39,780 --> 00:01:41,880 there's no point in examining any other descendants 30 00:01:41,880 --> 00:01:45,290 of that node since it can only decrease its fame player will not take that choice. 31 00:01:45,290 --> 00:01:46,900 Given that it has a higher value elsewhere. 32 00:01:48,320 --> 00:01:52,300 And, analogously, if the partial result of the max node is greater than Beta, 33 00:01:52,300 --> 00:01:53,720 then there's no point in considering other 34 00:01:53,720 --> 00:01:55,920 options since that can only increase the score. 35 00:01:55,920 --> 00:01:58,470 And, the player's opponent would not allow that since they know 36 00:01:58,470 --> 00:02:00,180 that they can keep the value to no more than Beta. 37 00:02:02,310 --> 00:02:06,309 So, here's the implementation of maxscore and minscore for a Alpha Beta player. 38 00:02:07,570 --> 00:02:09,520 In computing the maxscore of a max node, 39 00:02:09,520 --> 00:02:13,030 the player takes the max, maximum, of alpha 40 00:02:13,030 --> 00:02:14,830 and the minscore of the node obtained by 41 00:02:14,830 --> 00:02:17,170 performing an illegal action in the corresponding state. 42 00:02:18,710 --> 00:02:21,010 And symmetrically, to compute the minscore of a 43 00:02:21,010 --> 00:02:23,870 node, the player takes the minimum of beta and 44 00:02:23,870 --> 00:02:25,740 the maxscore of the node for the state obtained 45 00:02:25,740 --> 00:02:28,159 by executing the joint move for any illegal action. 46 00:02:31,500 --> 00:02:35,780 Now let's apply this procedure, to the tree shown earlier. 47 00:02:36,890 --> 00:02:39,620 with initial values 0 and 100 for alpha and beta. 48 00:02:41,250 --> 00:02:43,680 In the tree shown here, we have written in the values produced 49 00:02:43,680 --> 00:02:46,559 by the alpha-beta procedure in this case, and left the other nodes blank. 50 00:02:47,830 --> 00:02:49,780 So as you can see, we suse, we pruned 51 00:02:49,780 --> 00:02:53,500 away that fourth node at the bottom of the tree. 52 00:02:53,500 --> 00:02:56,480 But we also pruned away quite a few others. 53 00:02:56,480 --> 00:02:58,460 It's just not a insubstantial savings. 54 00:03:00,660 --> 00:03:04,728 In this particular case it was modest, however, in general 55 00:03:04,728 --> 00:03:08,145 alpha-beta search can,can save significant amount of work over full 56 00:03:08,145 --> 00:03:08,430 [UNKNOWN]. 57 00:03:08,430 --> 00:03:14,055 In fact, in the best case, given a tree with branching factor B, and depth D, 58 00:03:14,055 --> 00:03:19,570 alpha-beta search needs to examine at most, order of B to the D over 59 00:03:19,570 --> 00:03:25,230 2 nodes, to find the maximum score instead of order of B to the D. 60 00:03:25,230 --> 00:03:29,860 This means that an alpha-beta player can look ahead twice as 61 00:03:29,860 --> 00:03:32,850 far as a mini-max player in the same amount of time. 62 00:03:34,830 --> 00:03:36,920 Or looked at another way, the effective branching factor in 63 00:03:36,920 --> 00:03:40,290 this game is the square root of B instead of B. 64 00:03:40,290 --> 00:03:42,080 It would be the equivalent of searching a 65 00:03:42,080 --> 00:03:45,340 tree with just five moves instead of 25 moves.