juegos minimax alfabeta
DESCRIPTION
Descripcion minimax alfabeta .TRANSCRIPT
![Page 1: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/1.jpg)
Juegos
Nelson Becerra Correa
Fundación FABBECOR-ONG
![Page 2: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/2.jpg)
![Page 3: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/3.jpg)
Bibliografía• Conferencia : Miguel Illescas, Gran Maestro Internacional.
Kasparov, Deep Blue y la mente del ajedrecista.
• http://www.ocf.berkeley.edu/~yosenl/extras/alphabeta/alphabeta
• Jorge Egger M. Desarrollo de la maestría ajedrecística computacional. Utilizando recursos restringidos. Universidad de chile. Facultad de ciencias físicas y matemáticas. Departamento de ciencias de la computación, Santiago de chile, Julio 2003.
• Técnicas de inteligencia artificial en Juego. Nelson Becerra Correa, Fondo de publicaciones Universidad Distrital (FJC), Año 2003.
• w.acm.uiuc.edu/sigart/docs/MinimaxPresentation.ppt
![Page 4: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/4.jpg)
![Page 5: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/5.jpg)
TEORIA DE JUEGOS Fué creada para solucionar problemas
económicos. Los pioneros de esta teoría son John Von Newman y Oskar Morgestern.
En la actualidad se aplica a la Psicología, la administarción , las ciencias políticas etc.
![Page 6: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/6.jpg)
Clasificación de los juegos
NUMERO PARTICIPANTES
•Unipersonales•Bipersonales•N-personas N>2
NUMEROESTRATEGIAS
•Finito (estrategias finitas)•Infinitas
DE ACUERDO A LA
INFORMACION
•Información perfecta (Secuenciales)
•Información Imperfecta (Yan ken Po) (Dilema pri)
DE ACUERDO A LA SUMA
•Juegos de suma cero (ajedrez, oso, go,mankala)
•Juegos de suma distinta de cero (F)
![Page 7: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/7.jpg)
![Page 8: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/8.jpg)
![Page 9: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/9.jpg)
Como juegan las maquinas
![Page 10: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/10.jpg)
Como juegan las maquinas
![Page 11: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/11.jpg)
Como juegan las maquinas
![Page 12: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/12.jpg)
Como juegan las maquinas
![Page 13: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/13.jpg)
Como juegan las maquinas
![Page 14: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/14.jpg)
DEEP-BLUE potencia de calculo
![Page 15: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/15.jpg)
Función de evaluación
![Page 16: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/16.jpg)
Función de evaluación
![Page 17: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/17.jpg)
Posición que un programa sin Tablas de Transposición no puede solucionar.Las Blancas ganan mediante 1.Rb1!! Rb7 2.Rc1!!
1. 30 movimientos sería necesaria, y eso tomaría miles de horas de tiempo de CPU.
2. Con tablas Hash 6 movimientos, puesto que existen 130 diferentes tipos de posiciones obtenibles desde la inicial.
![Page 18: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/18.jpg)
![Page 19: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/19.jpg)
![Page 20: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/20.jpg)
Basic Idea
• Search problem– Searching a tree of the possible moves in order
to find the move that produces the best result– Depth First Search algorithm
• Assume the opponent is also playing optimally– Try to guarantee a win anyway!
![Page 21: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/21.jpg)
Árbol de variantes
1. En los inicios de 1970 la búsqueda en árboles de variantes alcanzaba la cantidad aproximada de 200 posiciones por segundo.
2. En año 2003, DEEP BLUE busca en 2.000.000 de posiciones por segundo.
3. Los mejores programas logran examinar todas las secuencias de movimientos con una profundidad de 8 a 10 movidas en el árbol (4 a 5 jugadas por bando).
![Page 22: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/22.jpg)
![Page 23: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/23.jpg)
Required Pieces for Minimax
• An initial state– The positions of all the pieces– Whose turn it is
• Operators– Legal moves the player can make
• Terminal Test– Determines if a state is a final state
• Utility Function
![Page 24: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/24.jpg)
Utility Function• Gives the utility of a game state
– utility(State)
• Examples– -1, 0, and +1, for Player 1 loses, draw, Player 1 wins,
respectively– Difference between the point totals for the two players– Weighted sum of factors (e.g. Chess)
• utility(S) = w1f
1(S) + w
2f
2(S) + ... + w
nf
n(S)
– f1(S) = (Number of white queens) – (Number of black queens), w
1 = 9
– f2(S) = (Number of white rooks) – (Number of black rooks), w
2 =
5– ...
![Page 25: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/25.jpg)
Two Agents• MAX
– Wants to maximize the result of the utility function
• MIN– Wants to minimize the result of the evaluation
function
![Page 26: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/26.jpg)
![Page 27: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/27.jpg)
… MINIMAXEjemplo de definición de función evaluadora:• Si p no es posición ganadora para ningún ganado, entonces:
– e(p)= (el nº de filas, columnas y diagonales completas que todavía estan libres para MAX) – (nº de filas, columnas, diagonales completas que todavía estan libres para MIN)
• Si p es una posición ganadora para MAX, entonces– e(p)= ∞ (donde ∞ indica un número positivo muy grande)
• Si p es una posición ganadora para MIN, entonces– e(p)= -∞
![Page 28: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/28.jpg)
… MINIMAXOX
Se tiene que e(p)=6 – 4 = 2
http://www.ocf.berkeley.edu/~yosenl/extras/alphabeta/alphabeta.html
![Page 29: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/29.jpg)
Basic Algorithm
![Page 30: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/30.jpg)
ALGORITMOS DE JUEGOS
• Algoritmos de primera generación
– se caracterizan por confiar en la capacidad bruta de las maquinas
• Algoritmos de segunda generación:
– Surge la inquietud de que mientras la maquina examina miles de posiciones su oponente humano solo examina algunas de ellas
![Page 31: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/31.jpg)
ALGORITMOS DE PRIMERA GENERACION
• MINIMAX
• NEGAMAX
• ALFA/BETA
• FALFA/BETA
• LALFA/BETA
• PALFA/BETA
• SCOUT
![Page 32: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/32.jpg)
MINIMAX NEGAMAX
ALFA/BETA FALFA/BETA
![Page 33: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/33.jpg)
LALFA/BETA PALFA/BETA
SCOUT
![Page 34: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/34.jpg)
Max
Min
Max
Min
Starting node and labelsMiniMax Search
![Page 35: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/35.jpg)
Max
Min
Max
Min
Continue expand the search space
![Page 36: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/36.jpg)
Max
Min
Max
Min
Continue expand the search space
![Page 37: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/37.jpg)
Max
Min
Max
Min2 3 5 09 7 4
Expand the search space down3-ply
![Page 38: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/38.jpg)
Max
Min
Max
Min2 3 5 09 7 4
Propagate the leaf values backwardPick Max values at Max Level
9 03 77
![Page 39: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/39.jpg)
Max
Min
Max
Min2 3 5 09 7 4
Continue propagate the values backwardPick Min values at Min Level
9 03 77
3 0
![Page 40: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/40.jpg)
Max
Min
Max
Min2 3 5 09 7 4
Continue propagate the values backwardPick Max values at Max Level
9 03 77
3 0
3
![Page 41: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/41.jpg)
Max
Min
Max
Min2 3 5 09 7 4
The move picked by Max
9 03 77
3 0
3
![Page 42: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/42.jpg)
Example MINIMAX
• Coins game– There is a stack of N coins– In turn, players take 1, 2, or 3 coins from the
stack– The player who takes the last coin loses
![Page 43: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/43.jpg)
Coins Game: Formal Definition
• Initial State:
The number of coins in the stack• Operators:
1. Remove one coin
2. Remove two coins
3. Remove three coins
• Terminal Test:
There are no coins left on the stack• Utility Function: F(S)
– F(S) = 1 if MAX wins, 0 if MIN wins
![Page 44: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/44.jpg)
N = 4K =
N = 3K =
N = 2K =
N = 1K =
N = 0K =
N = 1K =
N = 2K =
N = 0K =
N = 0K =
N = 1K =
N = 0K =
N = 1K =
N = 0K =
N = 0K =
12
3
3 21 2 1 1
1211
N = 0K =
1 F(S)=0
F(S)=0
F(S)=0
F(S)=1
F(S)=1
F(S)=1
F(S)=1
MAXMIN
![Page 45: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/45.jpg)
N = 4K = 1
N = 3K = 0
N = 2K = 0
N = 1K = 1
N = 0K = 1
N = 1K = 0
N = 2K = 1
N = 0K = 1
N = 0K = 1
N = 1K = 0
N = 0K = 0
N = 1K = 1
N = 0K = 0
N = 0K = 0
12
3
3 21
2 1 1
1211
N = 0K = 1
1 F(S)=0F(S)=0 F(S)=0
F(S)=1
F(S)=1
FFS(51791527S)=1
F(S)=1
MAXMIN
Solution
F(S)=1
![Page 46: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/46.jpg)
Analysis• Max Depth: 5• Branch factor: 3• Number of nodes: 15• Even with this trivial example, you can see that
these trees can get very big– Generally, there are O(bd) nodes to search for
• Branch factor b: maximum number of moves from each node• Depth d: maximum depth of the tree
– Exponential time to run the algorithm!– How can we make it faster?
![Page 47: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/47.jpg)
![Page 48: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/48.jpg)
Alpha-Beta Pruning
• Main idea: Avoid processing subtrees that have no effect on the result
• Two new parameters– α: The best value for MAX seen so far– β: The best value for MIN seen so far
• α is used in MIN nodes, and is assigned in MAX nodes
• β is used in MAX nodes, and is assigned in MIN nodes
![Page 49: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/49.jpg)
Alpha-Beta Pruning
• MAX (Not at level 0)– If a subtree is found with a value k greater than
the value of β, then we do not need to continue searching subtrees• MAX can do at least as good as k in this node, so MIN
would never choose to go here!
• MIN– If a subtree is found with a value k less than the
value of α, then we do not need to continue searching subtrees• MIN can do at least as good as k in this node, so MAX
would never choose to go here!
![Page 50: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/50.jpg)
Max
Min
Max
Min
Starting node and labelsAlpha-Beta Prune
![Page 51: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/51.jpg)
Max
Min
Max
Min
Perform a DFS
![Page 52: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/52.jpg)
Max
Min
Max
Min
Continue the DFS
![Page 53: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/53.jpg)
Max
Min
Max
Min2 3
Until reach the depth we want, i.e., 3-ply in this case
![Page 54: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/54.jpg)
Max
Min
Max
Min2 3
3
Propagate leaf values backward
![Page 55: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/55.jpg)
Max
Min
Max
Min2 3
3
3
![Page 56: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/56.jpg)
Max
Min
Max
Min2 3
3
3
3
![Page 57: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/57.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha Node
Beta Node
![Page 58: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/58.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
New DFS path Ended with 5
![Page 59: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/59.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
Propagate backward
![Page 60: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/60.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
Because 3 < 5
The branch is pruned.
Beta-Prune
![Page 61: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/61.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
New 3-ply DFSEnded with 0
0
![Page 62: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/62.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
0
0
Propagate backward
![Page 63: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/63.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
0
0
Propagate backward
0
![Page 64: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/64.jpg)
Max
Min
Max
Min2 3
3
3
3 Alpha
Beta
5
5
0
0
The branch is cut offBecause 3 > 0
Alpha Prune
0
![Page 65: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/65.jpg)
Algorithm
![Page 66: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/66.jpg)
N = 4K =
N = 3K =
N = 2K =
N = 1K =
N = 0K =
N = 1K =
N = 2K =
N = 0K =
N = 0K =
N = 1K =
N = 3K =
N = 1K =
N = 0K =
N = 0K =
12
3
3 21
2 1 1
1211
N = 0K =
1 F(S)=0F(S)=0 F(S)=0
F(S)=1
F(S)=1
F(S)=1 F(S)=1
MAXMIN
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
α =β =
![Page 67: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/67.jpg)
N = 4K = 0 1
N = 3K = 1 0
N = 2K = 1 0
N = 1K = 1
N = 0K = 1
N = 1K = 0
N = 2K = 1
N = 0K = 1
N = 0K = 1
N = 1K =
N = 3K = 0
N = 1K = 1
N = 0K =
N = 0K = 0
12
3
3 21
2 1 1
1211
N = 0K = 1
1 F(S)=0F(S)=0 F(S)=0
F(S)=1
F(S)=1
F(S)=1 F(S)=1
MAXMIN
α =β = 1 0
α = 0β =
α = 0β = 1 0
α =β = 0
α = 1β =
α = 0β = 0
α = 0β = 0
α = 0β = 1
α = 0β =
α = 0β = 0
α = 0β =
α = 1β = 0
α =β =
α = 1β = 0
α = 0β = 1
![Page 68: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/68.jpg)
![Page 69: Juegos minimax AlfaBeta](https://reader033.vdocuments.net/reader033/viewer/2022061205/5480bfa9b4af9f161e8b4586/html5/thumbnails/69.jpg)
Conclusion
• Minimax finds optimal play for deterministic, fully observable, two-player games
• Alpha-Beta reduction makes it faster