Você está na página 1de 17

Adversarial Search: game playing – part II

Stuart Russel and Peter Norvig, Artificial Intelligence: A modern


approach, 3rd edition, Pearson Education, 2010
http://aima.cs.berkeley.edu/ – chapter 6

Ernesto Costa e Anabela Simões, Inteligência Artificial:


Fundamentos e Aplicações (2ª edição) FCA, Set. 2008 – chapter 9

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

Contas para o jogo das damas


„ Se a dimensão do espaço de procura for de 10^40
nós e conseguirmos gerar um nó em cada terço de
nanosegundo (1/3 *10^-9) quanto tempo será
necessário para gerar todos os nós do espaço?

„ Ora cada século tem 31 536*10^6 segundos

„ Cerca de 10^20 séculos

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!

„ MinimaxCutoff igual a MinimaxValue excepto em


1. Terminal-Test é substituído por Cutoff-Test
2. Utility é substituído por Eval (Função de avaliação heurísitica)

„ Factores a considerar na interrupção da procura


‰ Algum agente ganhou?
‰ Quantas jogadas já foram exploradas?
‰ Quanto tempo está ainda disponível?
‰ Quão promissor é o caminho?
‰ Quão estável é a configuração actual?

26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 5

Função de avaliação heurísitica, Eval

„ Eval: estimativa da função utilidade, Utility

„ O desempenho depende da qualidade de Eval

„ Requisitos:

‰ Eval deve ordenar os nós terminais da mesma maneira


do que Utility.

‰ Para os estados não terminais a função de avaliação


deve estar fortemente correlacionada com as
possibilidades reais de ganhar.

‰ Eval deve ser (muito) rápida.

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

Eval(p)= -∞ Se MIN 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

Minimax – Jogo do Galo

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

Minimax – Jogo do Galo


1
6 6-4=2
–4=2
1 OX

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

© 1998 Morgan Kaufman Publishers


26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 11

Minimax – Jogo do Galo


OX O OOX
OX 2–1=1 OX 3–1=2
X X
OX O X
OX O 2–1=1 OX O 3–1=2
X X
–∞ OX –∞ O X
OX
OX 2–1=1 O X
OX 2–1=1
OX OX
OX OX
X OX X O X
OX –∞ OX – ∞
O X O X

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:

•Estrutura dos peões,


•Segurança do rei;
•Controlo do centro;
•…
Eval(s) = w1 f1(s) + w2 f2(s) + … + wnfn(s)

26-Feb-16 http://w3.ualg.pt/~jvo/ia 11 – 13

Xadrez - Interrupção da procura


„ Como se comporta na prática?
100 secs disponíveis e 104 nós/sec
=> 106 nós/jogada
bm = 106, se b=35 então m=4

„ Jogador de xadrez com 4-ply é um nabo!


„ 4-ply ≈ nabo
„ 8-ply ≈ jogo comum em PC / nível de Mestre
„ 12-ply ≈ Deep Blue II / Kasparov

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

„ O α de um nó maximizante é igual ao máximo actual dos β dos


sucessores desse nó
„ O β de um nó minimizante é igual ao mínimo actual dos α dos
sucessores desse nó

„ Os αα nunca diminuem; só podem crescer


„ Os ββ nunca aumentam; só podem descrescer

26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 15

Cortes α-β – Regra 1

„ A procura pode ser interrompida abaixo de qualquer


nó minimizante cujo β seja menor ou igual ao α de
qualquer dos seus nós maximizantes antecessores –
independentemente do seu nível

„ À interrupção chama-se corte α e o valor de β passa


a definitivo (embora possa não ser o valor
verdadeiro é um valor apropriado para calculos
subsequentes)

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

Cortes α-β – Regra 2


„ A procura pode ser interrompida abaixo de
qualquer nó maximizante cujo α seja maior ou
igual ao β de qualquer dos seus nós
maximizantes antecessores –
independentemente do seu nível.

„ À interrupção chama-se corte β e o valor de α


passa a definitivo (embora possa não ser o valor
verdadeiro é um valor apropriado para calculos
subsequentes)

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

„ In the worst-case, Minimax examines O(bm) nodes so does α-β

„ The gain for alpha-beta is maximum when:


‰ The children of a MAX node are ordered in decreasing
backed up values
‰ The children of a MIN node are ordered in increasing backed
up values
Then α-β examines O(bm/2) nodes (Knuth and Moore, 1975)
(if we knew how to order nodes perfectly, we would not need to search
the game tree)

„ If nodes are ordered at random, then the average number of nodes


examined by alpha-beta is O(b3m/4) (Knuth and Moore, 1975)

26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 21

The α-β strategy

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

α-β search – some conclusions


„ Pruning does not affect final result

„ A good heuristic ordering of successors improves effectiveness


of pruning

„ In the best case, i.e., with perfect ordering, time complexity is


O(bm/2) i.e., doubles the solvable tractable depth of search

„ Example of meta-reasoning (A simple example of the value of


reasoning about which computations are relevant)

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

Chess: Kasparov vs. Deep Blue


1997: Deep Blue wins by 3 wins, 1 loss, and 2 draws

Kasparov Deep Blue

1,6 mts Height 2 mts


80 kg Weight 1089 kg
34 years Age 4 years
50 billion neurons Hardware 30 IBM RS/6000
+ 480 VLSI chess proc.
2 pos/sec Max Speed 330,000,000 pos/sec
Extensive Knowledge Primitive
Chemical Power Source Electrical
Enormous Ego None

26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 28

14
Othello: Murakami vs. Logistello

Takeshi Murakami Michael Buro and is program


World Othello Champion Logistello

1997: The Logistello crushed Murakami by 6 games to 0

26-Feb-16 10 – 29

GO

„ State space: 10170 nodes


„ Branching factor: about 200
„ Sequential environment: A move now might make a
difference some dozen moves later
„ No good evaluation function
„ Local and global features

26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 30

15
GO

„ In 2005: Computer GO is
useless

„ In 2008, MoGO, a Monte Carlo Tree search based


program, won one game against a 5th dan pro Go
player on a 9x9 board

„ In 2013, Zen defeated a 9th dan on a 19x19 board


26-Feb-16 10 – 31

GO – humans not ahead anymore

26-Feb-16 http://w3.ualg.pt/~jvo/ml 10 – 32

16
Summary
„ Minimax with alpha-beta cut-off

„ Deterministic games in practice

26-Feb-16 http://w3.ualg.pt/~jvo/ia 10 – 33

17

Você também pode gostar