Escolar Documentos
Profissional Documentos
Cultura Documentos
Minimax algorithm
function MINIMAX-DECISION(state) returns an action
inputs: state, current state in game
v←MAX-VALUE(state)
return the action in SUCCESSORS(state) with value v
function MAX-VALUE(state) returns a utility value
if TERMINAL-TEST(state) then return UTILITY(state)
v ← -∞
for a,s in SUCCESSORS(state) do
v ← MAX(v,MIN-VALUE(s))
return v
function MIN-VALUE(state) returns a utility value
if TERMINAL-TEST(state) then return UTILITY(state)
v←∞
for a,s in SUCCESSORS(state) do
v ← MIN(v,MAX-VALUE(s))
return v
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 2
1
Propriedades do Minimax
Completo
Discriminador
Complexidade temporal: O(bm)
Complexidade espacial: O(bm)
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 3
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 4
2
Interrupção da procura
Os recursos limitados fazem com que a terminação seja
impossível!
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 5
Requisitos:
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 6
3
Minimax – Jogo do Galo
• Função de avaliação heurística para a posição p, Eval(p)
+∞ Se MAX ganha
Caso geral:
(Nº linhas, colunas e diagonais abertas para MAX) –
(Nº linhas, colunas e diagonais abertas para MIN)
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 7
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 8
4
Minimax – Jogo do Galo
1
OX 6 6-4=2
–4=2
X
X 5 5-4=1
–4=1
O 4 – 6 = –2
O
X 4-6=-2
MAX’s move
O
6 – 66-6=0
=0
1 –2 X
O
5 – 65-6=-1
= –1
X X
Start node
O 5 – 55-5=0
=0
X
5 – 65-6=-1
= –1
OX
O 4 4-5=-1
– 5 = –1
X
O
5 5-5=0
–5=0
–1 X
O
6–5=1
X X 6-5=1
5 5-5=0
–5=0
X O
6 6-5=1
–5=1
26-Feb-16 http://w3.ualg.pt/~jvo/ia
X O 11 – 9
© 1998 Morgan Kaufman Publishers
X 5 5-4=1
–4=1
O 4 – 6 = –2
O
X 4-6=-2
MAX’s move
O
6 –6-6=0
6=0
1 –2 X
-2 O
5 –5-6=-1
6 = –1
X X
Start node
O 5 –5-5=0
5=0
X
5 –5-6=-1
6 = –1
OX
O 4 4-5=-1
– 5 = –1
X
O
5 5-5=0
–5=0
-1
–1 X
O
6–5=1
X X 6-5=1
5 5-5=0
–5=0
X O
6 6-5=1
–5=1
26-Feb-16 http://w3.ualg.pt/~jvo/ia
X O 11 – 10
© 1998 Morgan Kaufman Publishers
5
Minimax – Jogo do Galo
1 0
Start node
OX OX X OX X 3–3=0
O
MAX’s move
OX X 4–3=1
1 O
O
OX OX 4–2=2 OX X 4–3=1
X X O
O
OX 4–2=2
0 X
O O
OX OX 4–3=1 OX 3–2=1
X X X
O
OX 4–3=1 OX O 5–2=3
1 X X
O O
OX OX 3–2=1 OX 3–3=0 OX 4–2=2
X X X OX
O
OX 4–2=2 OX O 5–3=2 OX 4–2=2
X X O X
O
OX 3–2=1 OX 3–3=0
X X O
OX O 5–2=3 OX 4–3=1
X OX
OX 3–2=1
X O
OX 4–2=2
X O
OO
OX X 3–2=1
X
1 –∞ O O
O O
OX X 2–2=0
X
OX OX X
X X O
Start
OX X 2–2=0
X
node O
MAX’s OX X –∞
move O X
1 OO –∞ OO
O
OX 3–1=2 O
D OX 3–2=1
X X X X
OX OX
X X O O X X O O
OX 2–1=1 C OX 2–2=0
X X X X
O O
OX O 3–1=2 B OX O 3–2=1
X X X X
O O
OX 2–1=1 A OX –∞
26-Feb-16 X OX http://w3.ualg.pt/~jvo/ia OX X 11 – 12
© 1998 Morgan Kaufman Publishers
6
Xadrez - Funções de avaliação
Ex: w1 = 9 e f1(s) = (número
de rainhas brancas) -
(número de rainhas pretos)
Outras características
possíveis para além da
vantagem relativa das peças:
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 13
26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 14
7
α-β
α é um valor auxiliar provisório de um nó maximizante
β é um valor auxiliar provisório de um nó minimizante
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 15
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 16
8
α-cut, example of
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 17
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 18
9
MAX
0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2 3 -3 0 -1 -2 0 1 4 5 1 -1 -1 3 -3 2 -2
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 19
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 20
10
How much do we gain?
Assume a game tree of constant branching factor b
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 21
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 22
11
The α-β strategy
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 23
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 24
12
Deterministic games
in practice
Chinook is invincible!
http://www.nytimes.com/2007/07/19/science/19cnd-checkers.html
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 26
13
Deep Blue II plays at human grandmaster level
n http://www.research.ibm.com/deepblue/
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 27
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 28
14
Othello: Murakami vs. Logistello
26-Feb-16 10 – 29
GO
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 30
15
GO
In 2005: Computer GO is
useless
26-Feb-16 http://w3.ualg.pt/~jvo/ml 10 – 32
16
Summary
Minimax with alpha-beta cut-off
26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 33
17