Download presentation
Presentation is loading. Please wait.
1
Pengantar Kecerdasan Buatan
GAME PLAYING
2
Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem, you (the searcher) get to choose every move In a two-player competitive game, you alternate moves with the other player The other player doesn’t want to reach your goal Your search technique must be very different
3
Permainan yang melibatkan 2 orang berarti melibatkan juga unpredictable opponent
Search space game besar & biasanya ada batas waktu
4
Types of Games battleship Kriegspiel Not Considered: Physical games like tennis, croquet, ice hockey, etc. (but see “robot soccer”
5
Game Trees This is an example of a partial game tree for the game tic-tac-toe. Even for this simple game, the game tree is very large.
6
Minimax Minimax is a method used to evaluate game trees.
A static evaluator is applied to leaf nodes, and values are passed back up the tree to determine the best score the computer can obtain against a rational opponent.
7
Game Trees
8
Minimax – Animated Example
3 6 The computer can obtain 6 by choosing the right hand edge from the first node. Max 5 1 3 6 2 7 6 Min 5 3 1 3 7 Max 6 5
9
Properties of minimax Complete? Yes (if tree is finite). Optimal?
Can it be beaten by an opponent playing sub-optimally? No. (Why not?) Time complexity? O(bm) Space complexity? O(bm) (depth-first search, generate all actions at once) O(m) (backtracking search, generate actions one at a time)
10
Searching Game Trees Exhaustively searching a game tree is not usually a good idea. Even for a game as simple as tic-tac-toe there are over 350,000 (9!) nodes in the complete game tree. [9! If computer goes first, 8! If computer goes second] For chess : b ≈ 35 (approximate average branching factor) d ≈ 100 (depth of game tree for “typical” game) bd ≈ ≈ nodes!! exact solution completely infeasible It is usually impossible to develop the whole search tree.
11
Applying MiniMax to tic-tac-toe
The static heuristic evaluation function
12
Backup Values
14
−∞ means MIN wins. +∞ means MAX wins.
15
Alpha-beta Pruning A method that can often cut off a half the game tree. Based on the idea that if a move is clearly bad, there is no need to follow the consequences of it. alpha – highest value we have found so far beta – lowest value we have found so far
16
Another Alpha-Beta Example
Do DF-search until first leaf Range of possible values [-∞,+∞] [-∞, +∞]
17
Alpha-Beta Example (continued)
[-∞,+∞] [-∞,3]
18
Alpha-Beta Example (continued)
[-∞,+∞] [-∞,3]
19
Alpha-Beta Example (continued)
[3,+∞] [3,3]
20
Alpha-Beta Example (continued)
[3,+∞] This node is worse for MAX [3,3] [-∞,2]
21
Alpha-Beta Example (continued)
, [3,14] [3,3] [-∞,2] [-∞,14]
22
Alpha-Beta Example (continued)
, [3,5] [3,3] [−∞,2] [-∞,5]
23
Alpha-Beta Example (continued)
[3,3] [3,3] [−∞,2] [2,2]
24
Alpha-Beta Example (continued)
[3,3] [3,3] [-∞,2] [2,2]
25
Alpha-beta Algorithm Depth first search
only considers nodes along a single path from root at any time a = highest-value choice found at any choice point of path for MAX (initially, a = −infinity) b = lowest-value choice found at any choice point of path for MIN (initially, = +infinity) Pass current values of a and b down to child nodes during search. Update values of a and b during search: MAX updates at MAX nodes MIN updates at MIN nodes Prune remaining branches at a node when a ≥ b
26
When to Prune Prune whenever ≥ .
Prune below a Max node whose alpha value becomes greater than or equal to the beta value of its ancestors. Max nodes update alpha based on children’s returned values. Prune below a Min node whose beta value becomes less than or equal to the alpha value of its ancestors. Min nodes update beta based on children’s returned values.
27
Alpha-Beta Example Revisited
Do DF-search until first leaf , , initial values =− =+ , , passed to kids =− =+
28
Alpha-Beta Example (continued)
=− =+ =− =3 MIN updates , based on kids
29
Alpha-Beta Example (continued)
=− =+ =− =3 MIN updates , based on kids. No change.
30
Alpha-Beta Example (continued)
MAX updates , based on kids. =3 =+ 3 is returned as node value.
31
Alpha-Beta Example (continued)
=3 =+ , , passed to kids =3 =+
32
Alpha-Beta Example (continued)
=3 =+ MIN updates , based on kids. =3 =2
33
Alpha-Beta Example (continued)
=3 =+ =3 =2 ≥ , so prune.
34
Alpha-Beta Example (continued)
MAX updates , based on kids. No change. =3 =+ 2 is returned as node value.
35
Alpha-Beta Example (continued)
=3 =+ , , , passed to kids =3 =+
36
Alpha-Beta Example (continued)
=3 =+ , MIN updates , based on kids. =3 =14
37
Alpha-Beta Example (continued)
=3 =+ , MIN updates , based on kids. =3 =5
38
Alpha-Beta Example (continued)
=3 =+ 2 is returned as node value. 2
39
Alpha beta pruning example
40
Example -which nodes can be pruned? 6 5 3 4 1 2 7 8
41
Answer to Example -which nodes can be pruned? Max Min Max 6 5 3 4 1 2
7 8 Answer: NONE! Because the most favorable nodes for both are explored last (i.e., in the diagram, are on the right-hand side).
42
Second Example (the exact mirror image of the first example)
-which nodes can be pruned? 4 3 6 5 8 7 2 1
43
Answer to Second Example (the exact mirror image of the first example)
-which nodes can be pruned? Max Min Max 4 3 6 5 8 7 2 1 Answer: LOTS! Because the most favorable nodes for both are explored first (i.e., in the diagram, are on the left-hand side).
44
Checker Example Black to move, White = “Min”, Black = “Max”
45
Chess Evaluation Functions
Alan Turing’s f(n)=(sum of your piece values)- (sum of opponent’s piece values) More complex: weighted sum of positional features: Deep Blue has > 8000 features (IBM Computer vs. Gary Kasparov) Pawn 1.0 Knight 3.0 Bishop 3.25 Rook 5.0 Queen 9.0 Pieces values for a simple Turing-style evaluation function
46
Min Max another example
48
Alpha Beta Another Example
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.